diff options
author | ubq323 <ubq323@ubq323.website> | 2025-02-18 21:22:18 +0000 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2025-02-18 21:22:18 +0000 |
commit | acc825b90a801fc719e680f60e2fd62fe25a7ccd (patch) | |
tree | 6eaf1c65b2177ffdbf07e37d42bbeb0ddec7d5c7 | |
parent | c7d9efdb19b650733f19176e11389e865ee92272 (diff) |
-rw-r--r-- | html.lua | 85 | ||||
-rw-r--r-- | init.lua | 2 | ||||
-rw-r--r-- | prose.lua | 2 |
3 files changed, 2 insertions, 87 deletions
diff --git a/html.lua b/html.lua deleted file mode 100644 index 532d606..0000000 --- a/html.lua +++ /dev/null @@ -1,85 +0,0 @@ -local function fmt_attrs(attrs) - local function fmt_attr(k,v) - if v == true then - return k - else - if type(v) == "table" then v = table.concat(v," ") end - return ('%s="%s"'):format(k,v) - end - end - - local o = "" - for k,v in pairs(attrs) do - o = o .. " " .. fmt_attr(k,v) - end - return o -end - -local html -local function fmt_tag(tag) - local attrs = tag.attrs and fmt_attrs(tag.attrs) or "" - local selfclosing = (tag.body == "") - if selfclosing then - return ("<%s%s/>"):format(tag.tname,attrs) - else - return ("<%s%s>%s</%s>"):format(tag.tname,attrs,html(tag.body),tag.tname) - end -end - -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} -local T = setmetatable({}, {__index=function(_,tname) - return function (...) - return tag(tname, ...) - end -end}) - -local function safe(s) - -- marks s as safe, doesn't escape it - assert(type(s) == "string","can only mark string as safe") - return setmetatable({safe=true,s=s},{__tostring=function(x)return x.s end}) -end - -local function escape(s) - s=s:gsub("&","&") - s=s:gsub("<","<") - s=s:gsub(">",">") - s=s:gsub('"',""") - return safe(s) -end - - -html = function (x) - if type(x) == "string" then - return escape(x) - elseif type(x) == "table" then - if x.safe then - -- safestr. already escaped - return x - elseif x.tag then - -- it's a tag - return safe( tostring(x) ) - else - -- just a regular list - local o = "" - for _,item in ipairs(x) do - o = o .. tostring(html(item)) - end - return safe(o) - end - end -end - -return { - html = html, - tag = tag, - safe = safe, - T = T, -} @@ -1,4 +1,4 @@ -local html = require'garkup.html' +local html = require'r.html' local T = html.T local prose = require'garkup.prose' @@ -1,4 +1,4 @@ -local html = require'garkup.html' +local html = require'r.html' local T = html.T local extensions = {} |