diff options
Diffstat (limited to 'mod/tex/context/third/rst/rst_directives.lua')
-rw-r--r-- | mod/tex/context/third/rst/rst_directives.lua | 80 |
1 files changed, 62 insertions, 18 deletions
diff --git a/mod/tex/context/third/rst/rst_directives.lua b/mod/tex/context/third/rst/rst_directives.lua index b64bafc..f5572b7 100644 --- a/mod/tex/context/third/rst/rst_directives.lua +++ b/mod/tex/context/third/rst/rst_directives.lua @@ -72,10 +72,35 @@ local function img_setup (properties) return result end -rst_directives.image = function(data) +local collect_image_properties = function (data) + local image_directives = rst_directives.images + local p_keyval = helpers.patterns.colon_keyval + local properties = { } + + data = tableflattened(data) + for i=1, #data do + local str = stringstrip(data[i]) + local key, val = lpegmatch(p_keyval, str) + if key and val then + key = image_directives.keys[key] -- sanitize key expression + local valtype = type(image_directives.values[key]) + if valtype == "table" then + val = image_directives.values[key][val] + elseif valtype == "function" then + val = image_directives.values[key](val) + end + properties[key] = val + end + end + return properties +end + +--- ordinary image directives are converted to floats + +local float_image = function (data) rst_context.addsetups "image" local inline_parser = rst_context.inline_parser - local properties = {} + local properties local anon = false local rdi = rst_directives.images local hp = helpers.patterns @@ -95,22 +120,7 @@ rst_directives.image = function(data) --anon = true -- indicates a nameless picture --name = "anonymous" .. rd.anonymous - data = tableflattened(data) - - for i=1, #data do - local str = stringstrip(data[i]) - local key, val = lpegmatch(hp.colon_keyval, str) - if key and val then - key = rdi.keys[key] -- sanitize key expression - local valtype = type(rdi.values[key]) - if valtype == "table" then - val = rdi.values[key][val] - elseif valtype == "function" then - val = rdi.values[key](val) - end - properties[key] = val - end - end + properties = collect_image_properties(data) if properties.caption then caption = lpegmatch(inline_parser, properties.caption) @@ -143,6 +153,40 @@ rst_directives.image = function(data) return img end +--- inline substitutions are converted to bare external figures +local inline_image = function (name, data) + rst_context.addsetups "image" + local filename = data.first + local p_keyval = helpers.patterns.colon_keyval + local properties + + if not filename then --- garbage, ignore + return "" + end + data.first = nil + filename = stringstrip(filename) + properties = collect_image_properties(data) + + local scheme = "\n\\def\\RSTsubstitution%s{\n \\externalfigure[%s]%s%%\n}\n" + local options = "" + if next(properties) then + local tmp = { } + tmp[#tmp+1] = "[" + for key, value in next, properties do + tmp[#tmp+1] = key + tmp[#tmp+1] = "={" + tmp[#tmp+1] = rst_context.escape(value) + tmp[#tmp+1] = "}," + end + tmp[#tmp+1] = "]" + options = tableconcat(tmp) + end + return stringformat(scheme, name, filename, options) +end + +rst_directives.image = float_image +rst_directives.inline_image = inline_image + rst_directives.caution = function(data) local inline_parser = rst_context.inline_parser rst_context.addsetups("dbend") |