From 23062e3fddcbc73ac51faaaaf46627477e413f6e Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 30 May 2025 16:40:58 +0100 Subject: minor html changes --- html.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/html.lua b/html.lua index 532d606..456285a 100644 --- a/html.lua +++ b/html.lua @@ -1,5 +1,6 @@ local function fmt_attrs(attrs) local function fmt_attr(k,v) + k = k:gsub("_","-") if v == true then return k else @@ -26,15 +27,15 @@ local function fmt_tag(tag) end end + +-- tag(tname,body) or tag(tname,attrs,body) local function tag(tname, a1, a2) - -- tag(tname,body) or tag(tname,attrs,body) local body, attrs if a2 then attrs=a1 body=a2 else attrs=nil body=a1 end return setmetatable({tag=true,tname=tname,attrs=attrs,body=body},{__tostring=fmt_tag}) end --- instead of tag('ul', {x, y, z}) --- you can do T.ul{ x, y, z} +-- T.tname(body) or T.tname(attrs, body) local T = setmetatable({}, {__index=function(_,tname) return function (...) return tag(tname, ...) @@ -59,6 +60,8 @@ end html = function (x) if type(x) == "string" then return escape(x) + elseif type(x) == 'number' then + return html(tostring(x)) elseif type(x) == "table" then if x.safe then -- safestr. already escaped -- cgit v1.2.3