From df73dca1a539387a12da632f2dd48e34f08d70d0 Mon Sep 17 00:00:00 2001 From: sanine Date: Sun, 22 May 2022 13:26:45 -0500 Subject: add child rendering --- marigold.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'marigold.lua') diff --git a/marigold.lua b/marigold.lua index 37cbdfb..ac0e061 100644 --- a/marigold.lua +++ b/marigold.lua @@ -87,6 +87,7 @@ end marigold.html = function(tbl, indent_level) indent_level = indent_level or 0 + local indent = string.rep('\t', indent_level) -- generate attribute strings local attributes = {} @@ -105,7 +106,19 @@ marigold.html = function(tbl, indent_level) local open = string.format('<%s%s>', tbl.tag, a) local close = string.format('', tbl.tag) - return string.format('%s%s%s', open, tbl.content, close) + if #tbl.children == 0 then + return string.format('%s%s%s%s', indent, open, tbl.content, close) + end + + local children = '' + for _, child in ipairs(tbl.children) do + children = children .. marigold.html(child, indent_level+1) .. '\n' + end + + return string.format('%s%s%s\n%s%s%s', + indent, open, tbl.content, + children, + indent, close) end -- cgit v1.2.1