summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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")