diff options
author | ubq323 <ubq323@ubq323.website> | 2024-10-31 18:41:04 +0000 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-10-31 18:41:04 +0000 |
commit | d5e53ee2a2b83adf91a0c3bbbc02c450b6747d59 (patch) | |
tree | 6d08a0aa3e8eaa341e402b5881735ba79094ddc4 /html.lua | |
parent | 664f471c774d6182efb0f9c4d4c9af9857b1bf52 (diff) |
highlighting, better whitespace, make into a module
Diffstat (limited to 'html.lua')
-rw-r--r-- | html.lua | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -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 |