From 9d00a058df52d261861fcc7a9d4dd6474a5f7f53 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Tue, 4 Jan 2011 23:20:58 +0100 Subject: macros for inline reST parsing --- mod/tex/context/third/rst/rst_parser.lua | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'mod/tex/context/third/rst/rst_parser.lua') diff --git a/mod/tex/context/third/rst/rst_parser.lua b/mod/tex/context/third/rst/rst_parser.lua index 580204c..ba9b4c8 100644 --- a/mod/tex/context/third/rst/rst_parser.lua +++ b/mod/tex/context/third/rst/rst_parser.lua @@ -1361,7 +1361,7 @@ local function save_file (name, data) return 0 end -local function get_setups () +local function get_setups (inline) local optional_setups = optional_setups -- might expect lots of calls local setups = [[ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -1391,7 +1391,7 @@ local function get_setups () local f = optional_setups[item] setups = f and setups .. f() or setups end - return setups .. [[ + setups = setups .. [[ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -1400,8 +1400,11 @@ local function get_setups () %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\starttext ]] + if not inline then + setups = setups .. "\n\\starttext" + end + return setups end local function main() @@ -1440,11 +1443,11 @@ do strip_comments = Cs((comment + 1)^0) end -function do_rst_file(fname) +function rst.do_rst_file(fname) local rst_parser = parser local raw_data = load_file(fname) local processed = rst_parser:match(raw_data) - local setups = get_setups() + local setups = get_setups(false) local tmp_file = tex.jobname .. "–rst_temporary.tex.tmp" if processed then @@ -1454,6 +1457,25 @@ function do_rst_file(fname) end end +function rst.do_rst_snippet(txt) + local processed = parser:match(txt) + local setups = get_setups(true) + local tmp_file = tex.jobname .. "–rst_temporary.tex.tmp" + + if processed then + warn("·cs·",txt) + processed = strip_comments:match(setups..processed) + save_file (tmp_file,processed) + context.input("./"..tmp_file) + else + warn("·cs·",txt) + context.par() + context("{\\bf context-rst could not process snippet.\\par}") + context.type(txt) + context.par() + end +end + if not context then return main() -- cgit v1.2.3