diff options
Diffstat (limited to 'html.lua')
-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 |