summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rst_context.lua40
-rw-r--r--rst_parser.lua6
2 files changed, 38 insertions, 8 deletions
diff --git a/rst_context.lua b/rst_context.lua
index 36dbdfc..d92a33d 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -210,7 +210,7 @@ end
function rst_context.substitution_reference (str)
rst_context.addsetups("substitutions")
- return [[{\\RSTsubstitution]] .. string.strip(str) .. "}"
+ return [[{\\RSTsubstitution]] .. str:gsub("%s", "") .. "}"
end
function rst_context.escape (str)
@@ -1047,7 +1047,8 @@ end
function optional_setups.substitutions ()
local images_done = {}
- local image = function(name, data)
+ local directives = {}
+ directives.image = function(name, data)
local img = ""
if not images_done[name] then
img = img .. string.format([[
@@ -1063,20 +1064,45 @@ function optional_setups.substitutions ()
return img
end
+ directives.ctx = function(name, data)
+ local ctx = string.format([[
+
+\startbuffer[%s]
+%s
+\stopbuffer
+\def\RSTsubstitution%s{
+ \getbuffer[%s]
+}
+]], name, data, name, name)
+ return ctx
+ end
+
+ directives.lua = function(name, data)
+ local luacode = string.format([[
+
+\startbuffer[%s]
+\startluacode
+%s
+\stopluacode
+\stopbuffer
+\def\RSTsubstitution%s{%%
+ \getbuffer[%s]%%
+}
+]], name, data, name, name)
+ return luacode
+ end
+
local substitutions = [[
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Substitutions %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
]]
local rs = rst_context.substitutions
for name, content in next, rs do
local directive, data = content.directive, content.data
- name, data = string.strip(name), string.strip(data)
- if string.strip(directive) == "image" then
- substitutions = substitutions .. image(name, data)
- end
+ name, data = name:gsub("%s", ""), string.strip(data)
+ substitutions = substitutions .. directives[directive](name, data)
end
return substitutions
end
diff --git a/rst_parser.lua b/rst_parser.lua
index dd20354..1ef0aa0 100644
--- a/rst_parser.lua
+++ b/rst_parser.lua
@@ -128,6 +128,10 @@ local parser = P{
--+ V"comment block"
,
+ explicit_markup_block = V"explicit_markup"^1
+ * V"end_block"
+ ,
+
--------------------------------------------------------------------------------
-- Substitution definition block
--------------------------------------------------------------------------------
@@ -140,7 +144,7 @@ local parser = P{
* C((1 - V"colon" - V"space" - V"eol")^1) -- directive
* V"double_colon"
* C(V"data_directive_block")
- * V"end_block"
+ * V"blank_line"^-1
/ rst.substitution_definition
,