summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rst_context.lua52
1 files changed, 33 insertions, 19 deletions
diff --git a/rst_context.lua b/rst_context.lua
index 00b93f5..9112786 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -1121,28 +1121,33 @@ function optional_setups.references ()
return refsection
end
-function optional_setups.substitutions ()
- local images_done = {}
+--------------------------------------------------------------------------------
+-- Directives for use with |substitutions|
+--------------------------------------------------------------------------------
- local directives = {}
- directives.image = function(name, data)
- local img = ""
- if not images_done[name] then
- img = img .. string.format([[
+rst_context.directives = {}
+rst_context.directives.images_done = {}
+
+rst_context.directives.image = function(name, data)
+ local img = ""
+ local images_done = rst_context.directives.images_done
+ if not images_done[name] then
+ img = img .. string.format([[
\useexternalfigure[%s][%s][]
]], name, data)
- end
- img = img .. string.format([[
+ images_done[name] = true
+ end
+ img = img .. string.format([[
\def\RSTsubstitution%s{
\placefigure[here]{%s}{\externalfigure[%s]}
}
]], name, name, name)
- return img
- end
+ return img
+end
- directives.ctx = function(name, data)
- local ctx = string.format([[
+rst_context.directives.ctx = function(name, data)
+ local ctx = string.format([[
\startbuffer[%s]
%s
@@ -1151,11 +1156,11 @@ function optional_setups.substitutions ()
\getbuffer[%s]
}
]], name, data, name, name)
- return ctx
- end
+ return ctx
+end
- directives.lua = function(name, data)
- local luacode = string.format([[
+rst_context.directives.lua = function(name, data)
+ local luacode = string.format([[
\startbuffer[%s]
\startluacode
@@ -1166,9 +1171,18 @@ function optional_setups.substitutions ()
\getbuffer[%s]%%
}
]], name, data, name, name)
- return luacode
- end
+ return luacode
+end
+
+rst_context.directives.replace = function(name, data)
+ return string.format([[
+\def\RSTsubstitution%s{%s}
+]], name, data)
+end
+
+function optional_setups.substitutions ()
+ local directives = rst_context.directives
local substitutions = [[
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%