From 8c8f6783423a44dc0623b0b1f409d3a71457c6ab Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 28 Aug 2011 15:33:18 +0200 Subject: rst projects --- mod/tex/context/third/rst/rst_parser.lua | 51 +++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 7 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 ff5d648..5bdc89d 100644 --- a/mod/tex/context/third/rst/rst_parser.lua +++ b/mod/tex/context/third/rst/rst_parser.lua @@ -1423,7 +1423,9 @@ end local function get_setups (inline) local optional_setups = optional_setups -- might expect lots of calls - local setups = [[ + local setups = "" + if not inline then + setups = setups .. [[ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~% %{ Setups }% @@ -1432,6 +1434,10 @@ local function get_setups (inline) % General % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +]] + end + + setups = setups .. [[ \setupcolors[state=start] \setupinteraction[state=start,focus=standard,color=darkgreen,contrastcolor=darkgreen] \setupbodyfontenvironment [default] [em=italic] @@ -1446,12 +1452,12 @@ local function get_setups (inline) } ]] - for item, _ in next, state.addme do local f = optional_setups[item] setups = f and setups .. f() or setups end - setups = setups .. [[ + if not inline then + setups = setups .. [[ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -1460,9 +1466,8 @@ local function get_setups (inline) %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\starttext ]] - if not inline then - setups = setups .. "\n\\starttext" end return setups end @@ -1512,11 +1517,43 @@ function thirddata.rst.do_rst_file(fname) if processed then processed = strip_comments:match(setups..processed.."\n\\stoptext\n") - save_file (tmp_file,processed) + save_file(tmp_file, processed) context.input("./"..tmp_file) end end +local rst_inclusions = { } +local rst_incsetups = { } +function thirddata.rst.do_rst_inclusion (iname, fname) + local rst_parser = parser + local raw_data = load_file(fname) + local processed = rst_parser:match(raw_data) + local setups = get_setups(true) + + local incnr = #rst_incsetups + 1 + local tmp_file = tex.jobname .. fmt("–rst_inclusion-%d.tex.tmp", incnr) + + if processed then + processed = strip_comments:match(processed) + save_file(tmp_file, processed) + rst_inclusions[iname] = tmp_file + rst_incsetups[#rst_incsetups +1] = setups + end +end + +function thirddata.rst.do_rst_setups () + local out = table.concat(rst_incsetups ) + context(out) +end + +function thirddata.rst.get_rst_inclusion (iname) + if rst_inclusions[iname] then + context.input(rst_inclusions[iname]) + else + context(fmt("{\\bf File for inclusion “%s” not found.}\par ", iname)) + end +end + function thirddata.rst.do_rst_snippet(txt) local processed = parser:match(txt) local setups = get_setups(true) @@ -1525,7 +1562,7 @@ function thirddata.rst.do_rst_snippet(txt) if processed then warn("·cs·",txt) processed = strip_comments:match(setups..processed) - save_file (tmp_file,processed) + save_file(tmp_file,processed) context.input("./"..tmp_file) else warn("·cs·",txt) -- cgit v1.2.3