From 32b085252affd98e0c4ed4bb2ec0748579e6bb56 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 15 Sep 2010 16:17:48 +0200 Subject: context (ctx) and lua directives --- rst_context.lua | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'rst_context.lua') 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 -- cgit v1.2.3