diff options
author | ubq323 <ubq323@ubq323.website> | 2025-05-30 16:40:58 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2025-05-30 16:40:58 +0100 |
commit | 23062e3fddcbc73ac51faaaaf46627477e413f6e (patch) | |
tree | 555523c8cbb1b48b6ffbf5b361faaee605fcbd3a | |
parent | d6ce98744e2aab91719014b6bd1f4dd0bc6393f5 (diff) |
minor html changes
-rw-r--r-- | html.lua | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -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 |