From 86415db3b88f1f94e63e9e93c70af110ea6516fa Mon Sep 17 00:00:00 2001 From: Omikhleia Date: Tue, 11 Jul 2023 09:48:05 +0200 Subject: [PATCH] refactor: command cascades should build an AST instead of functions --- packages/markdown/commands.lua | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/packages/markdown/commands.lua b/packages/markdown/commands.lua index eee1d3d..559de4f 100644 --- a/packages/markdown/commands.lua +++ b/packages/markdown/commands.lua @@ -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, })