summaryrefslogtreecommitdiff
path: root/rst_context.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-15 15:34:30 +0200
committerPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-15 15:34:30 +0200
commit35b9bd9ecc9fc606f8652f20b1126e6019b96006 (patch)
treef8fc2e4f8fafcb89f579c28ec4f38a2ad4084b0f /rst_context.lua
parent18f1a4107f48beb33fced6c7c4a770a718c15aa1 (diff)
downloadcontext-rst-35b9bd9ecc9fc606f8652f20b1126e6019b96006.tar.gz
image substitution directive
Diffstat (limited to 'rst_context.lua')
-rw-r--r--rst_context.lua63
1 files changed, 60 insertions, 3 deletions
diff --git a/rst_context.lua b/rst_context.lua
index 1ac5f96..36dbdfc 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -48,6 +48,7 @@ rst_context.last_section_level = 0
rst_context.anonymous_targets = 0
rst_context.anonymous_links = 0
rst_context.context_references = {}
+rst_context.substitutions = {}
rst_context.current_footnote_number = 0
rst_context.current_symbolnote_number = 0
@@ -207,6 +208,11 @@ function rst_context.inline_internal_target (str)
return "\\\\reference[__target_" .. rst_context.whitespace_to_underscore(str) .."]{}"
end
+function rst_context.substitution_reference (str)
+ rst_context.addsetups("substitutions")
+ return [[{\\RSTsubstitution]] .. string.strip(str) .. "}"
+end
+
function rst_context.escape (str)
str = str:gsub("\\(.)", "%1")
return str
@@ -228,9 +234,9 @@ local inline_parser = P{
+ V"emphasis"
+ V"inline_literal"
+ V"interpreted_text"
- + V"inline_internal_target" -- TODO
+ + V"inline_internal_target"
+ V"footnote_reference"
--- + V"substitution_reference" -- TODO
+ + V"substitution_reference"
+ V"link_standalone")
* V"succede_inline"),
@@ -389,6 +395,13 @@ local inline_parser = P{
/ rst_context.inline_internal_target
,
+ substitution_reference = V"bar"
+ * C((1 - V"bar")^1)
+ * V"bar"
+ * (V"underscore" + V"double_underscore")^-1
+ / rst_context.substitution_reference
+ ,
+
--------------------------------------------------------------------------------
-- Urls
--------------------------------------------------------------------------------
@@ -920,7 +933,7 @@ function rst_context.simple_table(tab)
return head .. body .. tail
end
-function rst_context.footnote(label, content)
+function rst_context.footnote (label, content)
local tf = state.footnotes
rst_context.addsetups("footnotes")
if label:match("^%d+$") then -- all digits
@@ -945,6 +958,13 @@ function rst_context.footnote(label, content)
return ""
end
+function rst_context.substitution_definition (subtext, directive, data)
+ print(subtext,directive,data)
+ local rs = rst_context.substitutions
+ rs[subtext] = { directive = directive, data = data }
+ return "\n% substitution definition block\n"
+end
+
optional_setups = {}
function optional_setups.footnote_symbol ()
local setup = [[
@@ -1024,4 +1044,41 @@ function optional_setups.references ()
return refsection
end
+function optional_setups.substitutions ()
+ local images_done = {}
+
+ local image = function(name, data)
+ local img = ""
+ if not images_done[name] then
+ img = img .. string.format([[
+
+\useexternalfigure[%s][%s][]
+]], name, data)
+ end
+ img = img .. string.format([[
+\def\RSTsubstitution%s{
+ \placefigure[here]{%s}{\externalfigure[%s]}
+}
+]], name, name, name)
+ return img
+ end
+
+ local substitutions = [[
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Substitutions %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+]]
+ local rs = rst_context.substitutions
+ for name, content in next, rs do
+ local directive, data = content.directive, content.data
+ name, data = string.strip(name), string.strip(data)
+ if string.strip(directive) == "image" then
+ substitutions = substitutions .. image(name, data)
+ end
+ end
+ return substitutions
+end
+
return rst_context