diff options
Diffstat (limited to 'mod/tex/context/third/rst/rst_directives.lua')
-rw-r--r-- | mod/tex/context/third/rst/rst_directives.lua | 55 |
1 files changed, 43 insertions, 12 deletions
diff --git a/mod/tex/context/third/rst/rst_directives.lua b/mod/tex/context/third/rst/rst_directives.lua index 9ece1db..c5f0b68 100644 --- a/mod/tex/context/third/rst/rst_directives.lua +++ b/mod/tex/context/third/rst/rst_directives.lua @@ -20,6 +20,8 @@ local rst_context = thirddata.rst local stringstrip = string.strip local stringformat = string.format +local tableconcat = table.concat +local lpegmatch = lpeg.match rst_directives.anonymous = 0 rst_directives.images = {} @@ -84,9 +86,10 @@ rst_directives.image = function(name, data) local processed = "" -- stub; TODO do something useful with optional dimension specifications if type(data) == "table" then -- should always be true local p = helpers.patterns - for _, str in ipairs(data) do + for i=1, #data do + local str = data[i] local key, val - key, val = p.colon_keyval:match(str) + key, val = lpegmatch(p.colon_keyval, str) local rdi = rst_directives.images if key and val then key = rdi.keys[key] -- sanitize key expression @@ -118,12 +121,12 @@ rst_directives.image = function(name, data) \def\RSTsubstitution%s{%% \placefigure[here]{%s}{\externalfigure[%s]%s} } -]], name, rst_context.escape(inline_parser:match(properties.caption)), name, properties.setup) +]], name, rst_context.escape(lpegmatch(inline_parser, properties.caption)), name, properties.setup) else -- image won't be referenced but used instantly img = img .. stringformat([[ \placefigure[here]{%s}{\externalfigure[%s]%s} -]], rst_context.escape(inline_parser:match(properties.caption)), data, properties.setup) +]], rst_context.escape(lpegmatch(inline_parser, properties.caption)), data, properties.setup) end return img end @@ -134,8 +137,9 @@ rst_directives.caution = function(raw) rst_context.addsetups("caution") local text local first = true - for _, line in ipairs(raw) do - if not helpers.patterns.spacesonly:match(line) then + for i=1, #raw do + local line = raw[i] + if not lpegmatch(helpers.patterns.spacesonly, line) then if first then text = line first = false @@ -144,7 +148,7 @@ rst_directives.caution = function(raw) end end end - text = rst_context.escape(helpers.string.wrapat(inline_parser:match(text))) + text = rst_context.escape(helpers.string.wrapat(lpegmatch(inline_parser, text))) return stringformat([[ \startRSTcaution %s @@ -158,8 +162,9 @@ rst_directives.danger = function(raw) rst_context.addsetups("danger") local text local first = true - for _, line in ipairs(raw) do - if not helpers.patterns.spacesonly:match(line) then + for i=1, #raw do + local line = raw[i] + if not lpegmatch(helpers.patterns.spacesonly, line) then if first then text = line first = false @@ -168,7 +173,7 @@ rst_directives.danger = function(raw) end end end - text = rst_context.escape(helpers.string.wrapat(inline_parser:match(text))) + text = rst_context.escape(helpers.string.wrapat(lpegmatch(inline_parser, text))) return stringformat([[ \startRSTdanger %s @@ -179,7 +184,8 @@ end -- http://docutils.sourceforge.net/docs/ref/rst/directives.html rst_directives.DANGER = function(addendum) local result = "" - for _,str in ipairs(addendum) do + for i=1, #addendum do + local str = addendum[i] result = result .. (stringstrip(str)) end return stringformat([[ @@ -264,7 +270,7 @@ rst_directives.math = function (name, data) data = data or name local formula if type(data) == "table" then - local last, i = table.maxn(data), 1 + local last, i = #data, 1 while i <= last do local line = stringstrip(data[i]) if line and line ~= "" then @@ -291,3 +297,28 @@ rst_directives.replace = function(name, data) ]], name, data) end +-------------------------------------------------------------------------------- +--- Containers. +-------------------------------------------------------------------------------- + +rst_directives.container = function(data) + local inline_parser = rst_context.inline_parser + local name, content = stringstrip(data[1]), "" + local tmp = { } + for i=2, #data do + tmp[#tmp+1] = data[i] + end + content = tableconcat(tmp, " ") + content = lpegmatch(inline_parser, content) + return stringformat([[ +\ifcsname %s\endcsname%% + \csname %s\endcsname%% +\else + \relax +\fi%% +{%s}%% +]], name, name, content) +end + +-- vim:ft=lua:sw=4:ts=4:expandtab + |