Skip to content

Commit

Permalink
Merge pull request #80 from Omikhleia/refactor-styles-cascade
Browse files Browse the repository at this point in the history
refactor: command cascades should build an AST instead of functions
  • Loading branch information
Omikhleia authored Jul 11, 2023
2 parents a16a826 + 86415db commit f9ba0ab
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions packages/markdown/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,21 @@ package._name = "markdown.commands"
-- content, avoiding a callback hell with conditionals where it is
-- used and providing a sequence-oriented presentation.
local CommandCascade = pl.class({
wrapper = nil,
_init = function (self)
self.inner = {}
self.outer = nil
end,
call = function (self, command, options)
local inner = self.wrapper
if inner then
self.wrapper = function (content)
SILE.call(command, options, function ()
inner(content)
end)
end
else
self.wrapper = function (content)
SILE.call(command, options, content)
end
end
local out = self.outer and { self.outer } or self.inner
self.outer = utils.createStructuredCommand(command, options, out)
end,
process = function (self, content)
if not self.wrapper then
SILE.process(content)
else
self.wrapper(content)
-- As a subTreeContent but into the inner node
for _, v in ipairs(content) do
self.inner[#self.inner + 1] = v
end
local stacked = self.outer and { self.outer } or self.inner
SILE.process(stacked)
end,
})

Expand Down

0 comments on commit f9ba0ab

Please sign in to comment.