From d5e53ee2a2b83adf91a0c3bbbc02c450b6747d59 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Thu, 31 Oct 2024 18:41:04 +0000 Subject: highlighting, better whitespace, make into a module --- html.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'html.lua') diff --git a/html.lua b/html.lua index 87ecc53..e265578 100644 --- a/html.lua +++ b/html.lua @@ -19,7 +19,9 @@ local html local function fmt_tag(tag) local attrs = tag.attrs and fmt_attrs(tag.attrs) or "" local selfclosing = (tag.body == "") - local sameline = type(tag.body) == "string" or (type(tag.body) == "table" and tag.body.tag) + local sameline = type(tag.body) == "string" + or (type(tag.body) == "table" and tag.body.tag) + or (type(tag.body) == "table" and #tag.body <= 1) local maybenl = sameline and "" or "\n" if selfclosing then return ("<%s%s/>"):format(tag.tname,attrs) @@ -70,9 +72,13 @@ html = function (x) return safe( tostring(x) ) else -- just a regular list + local nl = "\n" + if #x <= 2 then + nl = "" + end local o = "" for _,item in ipairs(x) do - o = o .. tostring(html(item)) .. "\n" + o = o .. tostring(html(item)) .. nl end return safe(o) end -- cgit v1.2.3