summaryrefslogtreecommitdiff
path: root/rst_context.lua
diff options
context:
space:
mode:
Diffstat (limited to 'rst_context.lua')
-rw-r--r--rst_context.lua36
1 files changed, 19 insertions, 17 deletions
diff --git a/rst_context.lua b/rst_context.lua
index 12c6817..e5737e0 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -39,8 +39,13 @@ do
end
end
-local rst_context = {}
+local err = function(str)
+ if str then
+ io.write("\n*[rstctx] Error: " .. str .. "\n\n")
+ end
+end
+local rst_context = {}
rst_context.collected_references = {}
rst_context.collected_adornments = {}
@@ -118,7 +123,6 @@ function rst_context.strong_emphasis (str)
end
function rst_context.literal (str)
- print(str)
str = str:gsub([[\]], [[\\]]) -- evade escaping of backslashes
return [[\\type{]] .. str .. [[}]]
--return [[\\starttyping ]] .. str .. [[\\stoptyping]]
@@ -470,14 +474,8 @@ function rst_context.paragraph (data)
local str
if not data then
return ""
- --elseif type(data) == "table" then
- --str = #data > 1 and helpers.string.wrapat(inline_parser:match(table.concat(data, " ")), 65) or data[1]
elseif type(data) == "table" then
- str = table.concat(data, " ")
- str = inline_parser:match(str)
- str = helpers.string.wrapat(str)
- print(str)
- --str = #data > 1 and helpers.string.wrapat(inline_parser:match(table.concat(data, " ")), 65) or data[1]
+ str = #data > 1 and helpers.string.wrapat(inline_parser:match(table.concat(data, " ")), 65) or data[1]
else
str = data
end
@@ -1169,9 +1167,9 @@ function optional_setups.references ()
% #1 target name, #2 link text
\def\RSTchoosegoto#1#2{%
- \rawdoifinsetelse{#1}{\RSTexternalreferences}
- {\from[#1]}
- {\goto{#2}[#1]}
+ \rawdoifinsetelse{#1}{\RSTexternalreferences}%
+ {\from[#1]}%
+ {\goto{#2}[#1]}%
}
]]
@@ -1277,12 +1275,12 @@ rst_context.directives.image = function(name, data)
\def\RSTsubstitution%s{%%
\placefigure[here]{%s}{\externalfigure[%s]%s}
}
-]], name, properties.caption, name, properties.setup)
+]], name, inline_parser:match(properties.caption), name, properties.setup)
else -- image won't be referenced but used instantly
img = img .. string.format([[
\placefigure[here]{%s}{\externalfigure[%s]%s}
-]], properties.caption, data, properties.setup)
+]], inline_parser:match(properties.caption), data, properties.setup)
end
return img
end
@@ -1375,7 +1373,7 @@ rst_context.directives.ctx = function(name, data)
\startbuffer[%s]
%s
\stopbuffer
-\def\RSTsubstitution%s{
+\def\RSTsubstitution%s{%%
\getbuffer[%s]
}
]], name, data, name, name)
@@ -1416,7 +1414,11 @@ function optional_setups.substitutions ()
for name, content in next, rs do
local directive, data = content.directive, content.data
name, data = name:gsub("%s", ""), string.strip(data)
- substitutions = substitutions .. directives[directive](name, data)
+ if directives[directive] then
+ substitutions = substitutions .. directives[directive](name, data)
+ else
+ err(directive .. " does not exist.")
+ end
end
return substitutions
end
@@ -1573,7 +1575,7 @@ function optional_setups.caution ()
\def\startRSTcaution{%
\startparagraph
-\lettrine[Lines=2,Raise=.5,Findent=\RSTbendskip,Nindent=0pt]{\symbol[dbend]}{}%
+\dontleavehmode\lettrine[Lines=2,Raise=.5,Findent=\RSTbendskip,Nindent=0pt]{\symbol[dbend]}{}%
}
\let\stopRSTcaution\stopparagraph