summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-11-13 22:03:17 +0000
committerubq323 <ubq323@ubq323.website>2024-11-13 22:03:17 +0000
commit16e9f4ef0ab0ad51a7a05fd98ee1870c81b20a73 (patch)
tree9db82260e113c3564d5c396a88ae8d783fc0ea0f
parentdfef0c0e5fad890c6c65110e3850ece586614215 (diff)
alter extension parsingHEADtrunk
-rw-r--r--init.lua6
-rw-r--r--prose.lua39
2 files changed, 34 insertions, 11 deletions
diff --git a/init.lua b/init.lua
index 21b5313..801f9d2 100644
--- a/init.lua
+++ b/init.lua
@@ -26,7 +26,11 @@ local function mode_code(S)
text = text .. line
end
end
- S:emit(highlight(text, lang))
+ if lang then
+ S:emit(highlight(text, lang))
+ else
+ S:emit(T.pre(text))
+ end
end
local function mode_list(S)
diff --git a/prose.lua b/prose.lua
index 90172ec..83e6f5d 100644
--- a/prose.lua
+++ b/prose.lua
@@ -24,17 +24,24 @@ local function prose(S, text)
function(a,x,b) return a..emplace(T[tagname](x))..b end
}
end
-
+ local function strip(s)
+ local q = s:match("^%s*(.-)%s*$")
+ return q or s
+ end
+ local function split(s)
+ local r = {}
+ for u in s:gmatch("%w+") do table.insert(r,u) end
+ return r
+ end
local function extension(str)
- local verb, rest = str:match("^{(%w+);%s*(.*)}$")
- if verb then
- return emplace(extensions[verb](S, rest))
- end
- local verbonly = str:match("^{(%w+)}$")
- if verbonly then
- return emplace(extensions[verbonly](S))
- end
- error("invalid extension syntax: "..str)
+ local verb, rest = assert(str:match("^{%s*([^%s;]+)(.*)}$"))
+ local args, body = rest:match("(.-);(.*)")
+ if not args then args = rest; body = '' end
+ verb = strip(verb)
+ args = split(args)
+ body = strip(body)
+ -- return verb, args, body
+ return emplace(extensions[verb](S, body, table.unpack(args)))
end
local subs = {
@@ -100,6 +107,18 @@ extensions.a = function(S,text)
return T.a({href=url},body)
end
+extensions.def = function(S,text,name)
+ if extensions[name] then
+ io.stderr:write("warning: redefining extension "..name.."\n")
+ end
+ local fn = assert(load(
+ string.format("return %s", text),
+ "def "..name, "t",
+ setmetatable({S=S, T=T, html=html, prose=prose}, {__index=_G})
+ ))
+ extensions[name]=fn()
+end
+
setmetatable(extensions, {__index = function(t, k)
return function(S, text)
io.stderr:write("warning: unknown extension "..k.."\n")