summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/third/rst/rst_directives.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/third/rst/rst_directives.lua')
-rw-r--r--Master/texmf-dist/tex/context/third/rst/rst_directives.lua67
1 files changed, 48 insertions, 19 deletions
diff --git a/Master/texmf-dist/tex/context/third/rst/rst_directives.lua b/Master/texmf-dist/tex/context/third/rst/rst_directives.lua
index a8a5eb76bdd..96eaf591fa5 100644
--- a/Master/texmf-dist/tex/context/third/rst/rst_directives.lua
+++ b/Master/texmf-dist/tex/context/third/rst/rst_directives.lua
@@ -4,7 +4,7 @@
-- USAGE: called by rst_parser.lua
-- DESCRIPTION: Complement to the reStructuredText parser
-- AUTHOR: Philipp Gesang (Phg), <megas.kapaneus@gmail.com>
--- CHANGED: 2011-05-08 17:56:25+0200
+-- CHANGED: 2011-08-28 13:47:00+0200
--------------------------------------------------------------------------------
--
@@ -14,10 +14,12 @@ local helpers = helpers or thirddata and thirddata.rst_helpers
-- Directives for use with |substitutions|
--------------------------------------------------------------------------------
-local rst_directives = { }
-if context then
- thirddata.rst_directives = rst_directives
-end
+local rst_directives = { }
+thirddata.rst_directives = rst_directives
+local rst_context = thirddata.rst
+
+local stringstrip = string.strip
+local fmt = string.format
rst_directives.anonymous = 0
rst_directives.images = {}
@@ -95,7 +97,7 @@ rst_directives.image = function(name, data)
end
properties[key] = val
else
- processed = processed .. (str and str ~= "" and string.strip(str))
+ processed = processed .. (str and str ~= "" and stringstrip(str))
end
end
end
@@ -106,19 +108,19 @@ rst_directives.image = function(name, data)
local images_done = rd.images.done
if not anon then
if not images_done[name] then
- img = img .. string.format([[
+ img = img .. fmt([[
\useexternalfigure[%s][%s][]
]], name, data)
images_done[name] = true
end
- img = img .. string.format([[
+ img = img .. fmt([[
\def\RSTsubstitution%s{%%
\placefigure[here]{%s}{\externalfigure[%s]%s}
}
]], name, rst_context.escape(inline_parser:match(properties.caption)), name, properties.setup)
else -- image won't be referenced but used instantly
- img = img .. string.format([[
+ img = img .. fmt([[
\placefigure[here]{%s}{\externalfigure[%s]%s}
]], rst_context.escape(inline_parser:match(properties.caption)), data, properties.setup)
@@ -143,7 +145,7 @@ rst_directives.caution = function(raw)
end
end
text = rst_context.escape(helpers.string.wrapat(inline_parser:match(text)))
- return string.format([[
+ return fmt([[
\startRSTcaution
%s
\stopRSTcaution
@@ -167,7 +169,7 @@ rst_directives.danger = function(raw)
end
end
text = rst_context.escape(helpers.string.wrapat(inline_parser:match(text)))
- return string.format([[
+ return fmt([[
\startRSTdanger
%s
\stopRSTdanger
@@ -178,9 +180,9 @@ end
rst_directives.DANGER = function(addendum)
local result = ""
for _,str in ipairs(addendum) do
- result = result .. (string.strip(str))
+ result = result .. (stringstrip(str))
end
- return string.format([[
+ return fmt([[
%% The Rabbit of Caerbannog
\startlinecorrection
@@ -211,12 +213,12 @@ rst_directives.DANGER = function(addendum)
end
rst_directives.mp = function(name, data)
- local mpcode = string.format([[
+ local mpcode = fmt([[
\startreusableMPgraphic{%s}
%s
\stopreusableMPgraphic
]], name, data)
- mpcode = mpcode .. string.format([[
+ mpcode = mpcode .. fmt([[
\def\RSTsubstitution%s{%%
\reuseMPgraphic{%s}%%
}
@@ -225,7 +227,7 @@ rst_directives.mp = function(name, data)
end
rst_directives.ctx = function(name, data)
- local ctx = string.format([[
+ local ctx = fmt([[
\startbuffer[%s]
%s\stopbuffer
@@ -237,7 +239,7 @@ rst_directives.ctx = function(name, data)
end
rst_directives.lua = function(name, data)
- local luacode = string.format([[
+ local luacode = fmt([[
\startbuffer[%s]
\startluacode
@@ -251,11 +253,38 @@ rst_directives.lua = function(name, data)
return luacode
end
+--------------------------------------------------------------------------------
+--- Experimental math directive
+--------------------------------------------------------------------------------
+
+rst_directives.math = function (name, data)
+ data = data or name
+ local formula
+ if type(data) == "table" then
+ local last, i = table.maxn(data), 1
+ while i <= last do
+ local line = stringstrip(data[i])
+ if line and line ~= "" then
+ formula = formula and formula .. " " .. line or line
+ end
+ i = i + 1
+ end
+ end
+ return fmt([[
+\startformula
+%s
+\stopformula
+]], formula)
+end
+
+--------------------------------------------------------------------------------
+--- End math directive
+--------------------------------------------------------------------------------
+
rst_directives.replace = function(name, data)
- return string.format([[
+ return fmt([[
\def\RSTsubstitution%s{%s}
]], name, data)
end
-return rst_directives