summaryrefslogtreecommitdiff
path: root/rst_context.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-18 02:01:06 +0200
committerPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-09-18 02:01:06 +0200
commit01d0c2dcca48fde5a99ff1173e80ad3c085cdbb5 (patch)
tree09ae0970e00eb751ebbbf089290d3515722b77af /rst_context.lua
parenta47844a42cfabc9eb893eef80dd375d75bdd436f (diff)
downloadcontext-rst-01d0c2dcca48fde5a99ff1173e80ad3c085cdbb5.tar.gz
simple directives.
Diffstat (limited to 'rst_context.lua')
-rw-r--r--rst_context.lua100
1 files changed, 93 insertions, 7 deletions
diff --git a/rst_context.lua b/rst_context.lua
index 39d375b..e64aac4 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -1080,6 +1080,20 @@ function rst_context.substitution_definition (subtext, directive, data)
return ""
end
+-- not to be confused with the directive definition table rst_context.directives
+function rst_context.directive(directive, ...)
+ local rd = rst_context.directives
+ rst_context.addsetups("directive")
+ local data = {...}
+ --print(directive, data, #data)
+ --for i,j in next,data do print(i,j) end
+ local result = ""
+ if rd[directive] then
+ result = rd[directive](data)
+ end
+ return result
+end
+
optional_setups = {}
function optional_setups.footnote_symbol ()
local setup = [[
@@ -1163,26 +1177,87 @@ end
--------------------------------------------------------------------------------
rst_context.directives = {}
+rst_context.directives.anonymous = 0
rst_context.directives.images_done = {}
rst_context.directives.image = function(name, data)
+ local anon = false
+ local rd = rst_context.directives
+ if not data then -- this makes the “name” argument optional
+ data = name
+ rd.anonymous = rd.anonymous + 1
+ anon = true -- indicates a nameless picture
+ name = "anonymous" .. rd.anonymous
+ end
+
+ local processed = "" -- stub; TODO do something useful with optional dimension specifications
+ if type(data) == "table" then -- should always be true
+ for _, str in ipairs(data) do
+ processed = processed .. (str and str ~= "" and string.strip(str))
+ end
+ end
+ data = processed
+ processed = nil
local img = ""
- local images_done = rst_context.directives.images_done
- if not images_done[name] then
- img = img .. string.format([[
+ local images_done = rd.images_done
+ if not anon then
+ if not images_done[name] then
+ img = img .. string.format([[
\useexternalfigure[%s][%s][]
]], name, data)
- images_done[name] = true
- end
- img = img .. string.format([[
-\def\RSTsubstitution%s{
+ images_done[name] = true
+ end
+ img = img .. string.format([[
+\def\RSTsubstitution%s{%
\placefigure[here]{%s}{\externalfigure[%s]}
}
]], name, name, name)
+ else -- image won't be referenced but used instantly
+ img = img .. string.format([[
+
+\placefigure[here]{none}{\externalfigure[%s]}
+]], data)
+ end
return img
end
+-- http://docutils.sourceforge.net/docs/ref/rst/directives.html
+rst_context.directives.DANGER = function(addendum)
+ local result = ""
+ for _,str in ipairs(addendum) do
+ result = result .. (string.strip(str))
+ end
+ return string.format([[
+
+%% The Rabbit of Caerbannog
+\startlinecorrection
+\blank[force,big]
+\framed[frame=on,
+ corner=round,
+ rulethickness=5pt,
+ align=middle,
+ width=\hsize,
+ frameoffset=.5em,
+ backgroundoffset=1em,
+ background=color,
+ backgroundcolor=red,
+ foreground=color,
+ foregroundcolor=black]{%%
+ \language[en-gb]\tfb\bf
+ Follow only if ye be men of valour, for the entrance to this cave is guarded
+ by a creature so foul, so cruel that no man yet has fought with it and lived.
+ Bones of full fifty men lie strewn about its lair. So, brave knights, if you
+ do doubt your courage or your strength, come no further, for death awaits you
+ all with nasty, big, pointy teeth.%%
+ \blank[force,big]
+ %s%%
+}
+\blank[force,big]
+\stoplinecorrection
+]], result)
+end
+
rst_context.directives.ctx = function(name, data)
local ctx = string.format([[
@@ -1235,6 +1310,17 @@ function optional_setups.substitutions ()
return substitutions
end
+function optional_setups.directive ()
+ local directives = rst_context.directives
+ local dirstr = [[
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Directives %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+]]
+ return dirstr
+end
+
function optional_setups.blockquote ()
return [[