From a3c01af8bbd581000e276cca076023c308bd688c Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 4 Jun 2013 15:44:44 +0200 Subject: add inline images (non-float) via substitutions --- mod/tex/context/third/rst/rst_context.lua | 43 ++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'mod/tex/context/third/rst/rst_context.lua') diff --git a/mod/tex/context/third/rst/rst_context.lua b/mod/tex/context/third/rst/rst_context.lua index b9b9e58..c7e21fe 100644 --- a/mod/tex/context/third/rst/rst_context.lua +++ b/mod/tex/context/third/rst/rst_context.lua @@ -345,14 +345,14 @@ end function rst_context.substitution_reference (str, underscores) local sub = "" - rst_context.addsetups("substitutions") + rst_context.addsetups "substitutions" if underscores == "_" then -- normal reference sub = sub .. [[\\reference[__target_]] .. rst_context.whitespace_to_underscore(stringstrip(str)) .. "]{}" elseif underscores == "__" then -- normal reference rst_context.anonymous_targets = rst_context.anonymous_targets + 1 sub = sub .. [[\\reference[__target_anon_]] .. rst_context.anonymous_targets .. "]{}" end - return sub .. [[{\\RSTsubstitution]] .. str:gsub("%s", "") .. "}" + return sub .. [[{\\RSTsubstitution]] .. stringgsub(str, "%s", "") .. "}" end do @@ -1268,21 +1268,34 @@ function rst_context.footnote (label, content) return "" end +--- hack to differentiate inline images +local special_substitutions = { + image = "inline_image", +} + function rst_context.substitution_definition (subtext, directive, data) - local tmp - if data.first ~= "" then - tmp = { data.first } + local special = special_substitutions[directive] + if special then + --- override; pass data directly + directive = special else - tmp = { } - end - data.first = nil - for i=1, #data do -- paragraphs - local current = tableconcat(data[i], "\n") - --current = lpegmatch(inline_parser, current) - --current = rst_context.escape(current) - tmp[#tmp+1] = current + local tmp + if data.first ~= "" then + tmp = { data.first } + else + tmp = { } + end + data.first = nil + for i=1, #data do -- paragraphs + local current = tableconcat(data[i], "\n") + --current = lpegmatch(inline_parser, current) + --current = rst_context.escape(current) + tmp[#tmp+1] = current + end + data = tableconcat(tmp, "\n\n") + data = stringstrip(data) end - data = tableconcat(tmp, "\n\n") + subtext = stringgsub(subtext, "%s", "") rst_context.substitutions[subtext] = { directive = directive, data = data } return "" @@ -1290,7 +1303,7 @@ end -- not to be confused with the directive definition table rst_directives function rst_context.directive(directive, data) - local fun = rst_directives[directive] + local fun = rst_directives[directive] if fun then rst_context.addsetups("directive") local result = "" -- cgit v1.2.3