summaryrefslogtreecommitdiff
path: root/rst_context.lua
diff options
context:
space:
mode:
Diffstat (limited to 'rst_context.lua')
-rw-r--r--rst_context.lua160
1 files changed, 146 insertions, 14 deletions
diff --git a/rst_context.lua b/rst_context.lua
index f17f5a6..34f4594 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -809,10 +809,9 @@ function rst_context.literal_block (str, included)
\stoptyping
]]
if included then -- escaping can ruin your day
- return str:gsub("\\", "\\\\")
- else
- return str
+ str = str:gsub("\\", "\\\\")
end
+ return str
end
function rst_context.included_literal_block (str)
@@ -1184,8 +1183,15 @@ rst_context.directives.images.keys = {
["width"] = "width",
["size"] = "width",
["caption"] = "caption",
+ ["scale"] = "scale",
}
+rst_context.directives.images.values.scale = function (orig)
+ -- http://wiki.contextgarden.net/Reference/en/useexternalfigure
+ -- scale=1000 is original size; to get 72%, use scale=720.
+ return tonumber(orig) * 1000
+end
+
rst_context.directives.images.values.width = {
["fit"] = "\\hsize",
["hsize"] = "\\hsize",
@@ -1196,7 +1202,7 @@ rst_context.directives.images.values.width = {
-- we won't allow passing arbitrary setups to context
rst_context.directives.images.permitted_setups = {
- "width"
+ "width", "scale"
}
local function img_setup (properties)
@@ -1211,6 +1217,7 @@ local function img_setup (properties)
end
return result
end
+
rst_context.directives.image = function(name, data)
local properties = {}
local anon = false
@@ -1222,7 +1229,7 @@ rst_context.directives.image = function(name, data)
name = "anonymous" .. rd.anonymous
end
properties.caption = name
- properties.width = "\\local"
+ --properties.width = "\\local"
local processed = "" -- stub; TODO do something useful with optional dimension specifications
if type(data) == "table" then -- should always be true
@@ -1233,7 +1240,11 @@ rst_context.directives.image = function(name, data)
local rdi = rst_context.directives.images
if key and val then
key = rdi.keys[key] -- sanitize key expression
- val = rdi.values[key] and rdi.values[key][val] or val -- e.g. captions have no substitutions
+ if type(rdi.values[key]) == "table" then
+ val = rdi.values[key][val]
+ elseif type(rdi.values[key]) == "function" then
+ val = rdi.values[key](val)
+ end
properties[key] = val
else
processed = processed .. (str and str ~= "" and string.strip(str))
@@ -1254,7 +1265,7 @@ rst_context.directives.image = function(name, data)
images_done[name] = true
end
img = img .. string.format([[
-\def\RSTsubstitution%s{%
+\def\RSTsubstitution%s{%%
\placefigure[here]{%s}{\externalfigure[%s]%s}
}
]], name, properties.caption, name, properties.setup)
@@ -1267,6 +1278,52 @@ rst_context.directives.image = function(name, data)
return img
end
+rst_context.directives.caution = function(raw)
+ rst_context.addsetups("dbend")
+ rst_context.addsetups("caution")
+ local text
+ local first = true
+ for _, line in ipairs(raw) do
+ if not helpers.patterns.spacesonly:match(line) then
+ if first then
+ text = line
+ first = false
+ else
+ text = text .. " " .. line
+ end
+ end
+ end
+ text = rst_context.escape(helpers.string.wrapat(inline_parser:match(text)))
+ return string.format([[
+\startRSTcaution
+%s
+\stopRSTcaution
+]], text)
+end
+
+rst_context.directives.danger = function(raw)
+ rst_context.addsetups("dbend")
+ rst_context.addsetups("danger")
+ local text
+ local first = true
+ for _, line in ipairs(raw) do
+ if not helpers.patterns.spacesonly:match(line) then
+ if first then
+ text = line
+ first = false
+ else
+ text = text .. " " .. line
+ end
+ end
+ end
+ text = rst_context.escape(helpers.string.wrapat(inline_parser:match(text)))
+ return string.format([[
+\startRSTdanger
+%s
+\stopRSTdanger
+]], text)
+end
+
-- http://docutils.sourceforge.net/docs/ref/rst/directives.html
rst_context.directives.DANGER = function(addendum)
local result = ""
@@ -1356,14 +1413,15 @@ function optional_setups.substitutions ()
end
function optional_setups.directive ()
- local directives = rst_context.directives
- local dirstr = [[
+ --local directives = rst_context.directives
+ --local dirstr = [[
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Directives %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-]]
- return dirstr
+--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+--% Directives %
+--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+--]]
+ --return dirstr
+ return ""
end
function optional_setups.blockquote ()
@@ -1464,4 +1522,78 @@ function optional_setups.fieldlist ()
]]
end
+function optional_setups.dbend ()
+ -- There's just no reason for not providing this.
+ optional_setups.dbend_done = true
+ return [[
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Dangerous bend %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\loadmapfile [manfnt.map]
+\definefontsynonym [bends] [manfnt]
+
+\def\GetSym#1{\getglyph{bends}{\char#1}}
+
+\startsymbolset [Dangerous Bends]
+ \definesymbol [dbend] [\GetSym{127}]
+ \definesymbol [lhdbend] [\GetSym{126}]
+ \definesymbol [lhdbend] [\GetSym{0}]
+\stopsymbolset
+
+\setupsymbolset [Dangerous Bends]
+
+]]
+end
+
+function optional_setups.caution ()
+ local result = ""
+ --if not optional_setups.dbend_done then
+ --result = result .. optional_setups.dbend()
+ --end
+ return result .. [[
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Caution directive %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\usemodule[lettrine]
+
+\setbox0=\hbox{\symbol[dbend]\hbox to 1em{}}
+\newskip\RSTbendskip
+\RSTbendskip=\wd0
+
+\def\startRSTcaution{%
+\startparagraph
+\lettrine[Lines=2,Raise=.5,Findent=\RSTbendskip,Nindent=0pt]{\symbol[dbend]}{}%
+}
+
+\let\stopRSTcaution\stopparagraph
+
+]]
+
+end
+
+function optional_setups.danger ()
+ local result = ""
+ --if not optional_setups.dbend_done then
+ --result = result .. optional_setups.dbend()
+ --end
+ return result .. [[
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Danger directive %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\usemodule[lettrine]
+
+\def\startRSTdanger{%
+\startparagraph
+\lettrine[Lines=2,Raise=.5,Findent=1em,Nindent=0pt]{\symbol[dbend]\symbol[dbend]}{}%
+}
+
+\let\stopRSTdanger\stopparagraph
+
+]]
+
+end
+
return rst_context