diff options
author | Philipp Gesang <megas.kapaneus@gmail.com> | 2011-08-28 15:33:18 +0200 |
---|---|---|
committer | Philipp Gesang <megas.kapaneus@gmail.com> | 2011-08-28 15:33:18 +0200 |
commit | 8c8f6783423a44dc0623b0b1f409d3a71457c6ab (patch) | |
tree | 787c74db1de2e28bf112c04bc79bd11057b662b8 | |
parent | 001738e26e1b841a4042b3597ba28d9c3d04aef6 (diff) | |
download | context-rst-8c8f6783423a44dc0623b0b1f409d3a71457c6ab.tar.gz |
rst projects
-rw-r--r-- | .hgignore | 1 | ||||
-rw-r--r-- | mod/doc/context/third/rst/inc-first.rst | 14 | ||||
-rw-r--r-- | mod/doc/context/third/rst/inc-second.rst | 9 | ||||
-rw-r--r-- | mod/doc/context/third/rst/inc-third.rst | 14 | ||||
-rw-r--r-- | mod/doc/context/third/rst/inc.tex | 11 | ||||
-rw-r--r-- | mod/tex/context/third/rst/rst_parser.lua | 51 | ||||
-rw-r--r-- | mod/tex/context/third/rst/t-rst.mkiv | 35 |
7 files changed, 126 insertions, 9 deletions
@@ -40,3 +40,4 @@ syntax:glob ./tmp.tex *–rst_temporary* ./tmp/* +./test/* diff --git a/mod/doc/context/third/rst/inc-first.rst b/mod/doc/context/third/rst/inc-first.rst new file mode 100644 index 0000000..392649f --- /dev/null +++ b/mod/doc/context/third/rst/inc-first.rst @@ -0,0 +1,14 @@ +============= +First Chapter +============= + +Mountaineer? *Mountaineer* where the devil are they, mound, mount... mountain... +a mountaineer: ‘two men skilled in climbing mountains’. Jolly good, well you’re +in. Congratulations, both of you. + +We’ll be leaving on January 22nd and taking the following routes. The A23s +through Purleys down on the main roads near Purbrights avoiding Leatherheads and +then taking the A231s entering Rottingdeans from the North. From Rottingdeans we +go through Africa to Nairobis. We take the South road out of Nairobis for about +twelve miles and then ask. + diff --git a/mod/doc/context/third/rst/inc-second.rst b/mod/doc/context/third/rst/inc-second.rst new file mode 100644 index 0000000..eff120e --- /dev/null +++ b/mod/doc/context/third/rst/inc-second.rst @@ -0,0 +1,9 @@ +============== +Second Chapter +============== +Well Bruce, I heard the Prime Minister use it. S’hot enough to boil a monkey’s +bum in ’ere, your Majesty, he said and she smiled quietly to herself. + +Now, Bruce teaches classical philosophy, Bruce teaches Hegelian philosophy, and +Bruce here teaches logical positivism, and is also in charge of the sheepdip. + diff --git a/mod/doc/context/third/rst/inc-third.rst b/mod/doc/context/third/rst/inc-third.rst new file mode 100644 index 0000000..67e6d5a --- /dev/null +++ b/mod/doc/context/third/rst/inc-third.rst @@ -0,0 +1,14 @@ +============= +Third Chapter +============= +You are hereby charged that on the 28th day of May 1970, you did wilfully, +unlawfully, and with malice aforethought publish an alleged English-Hungarian +phrasebook with intent to cause a breach of the peace. How do you plead? + +Not guilty. + +I quote an example. The Hungarian phrase meaning ‘Can you direct me to the +station?’ is translated by the English phrase, ‘Please fondle my bum’. + +I wish to plead incompetence. + diff --git a/mod/doc/context/third/rst/inc.tex b/mod/doc/context/third/rst/inc.tex new file mode 100644 index 0000000..7703fae --- /dev/null +++ b/mod/doc/context/third/rst/inc.tex @@ -0,0 +1,11 @@ +\usemodule[rst] + +\defineRSTinclusion [first][inc-first.rst] +\defineRSTinclusion[second][inc-second.rst] +\defineRSTinclusion [third][inc-third.rst] + +\startRSTproject +\RSTinclusion [first] +\RSTinclusion[second] +\RSTinclusion [third] +\stopRSTproject 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) diff --git a/mod/tex/context/third/rst/t-rst.mkiv b/mod/tex/context/third/rst/t-rst.mkiv index bb727b0..7971e3f 100644 --- a/mod/tex/context/third/rst/t-rst.mkiv +++ b/mod/tex/context/third/rst/t-rst.mkiv @@ -122,7 +122,7 @@ %D %D \showsetup{typesetRSTfile} -\def\do_typesetRSTfile[#1]#2{% +\def\do_typeset_RST_file[#1]#2{% \iffirstargument \getparameters[RST][#1]% \doifdefined{RSTstripBOM} {\ctxlua{thirddata.rst.strip_BOM = \RSTstripBOM}}% @@ -133,7 +133,7 @@ } \def\typesetRSTfile{% - \dosingleempty\do_typesetRSTfile% + \dosingleempty\do_typeset_RST_file% } %D \subsection{Typesetting Inline Snippets} @@ -178,6 +178,37 @@ \ctxlua{thirddata.rst.do_rst_snippet(\!!bs#1\!!es)}% } +\def\do_define_RST_inclusion[#1][#2]{% + \ifsecondargument + \ctxlua{thirddata.rst.do_rst_inclusion("#1", "#2")}% + \fi% +} + +\def\defineRSTinclusion{% + \dodoubleempty\do_define_RST_inclusion% +} + +\def\do_RST_inclusion[#1]{% + \iffirstargument + \ctxlua{thirddata.rst.get_rst_inclusion("#1")}% + \fi% +} + +\def\do_RST_setups{% + \ctxlua{thirddata.rst.do_rst_setups()}% +} + +\def\startRSTproject{ + \begingroup + \def\RSTinclusion{\dosingleempty\do_RST_inclusion} + \do_RST_setups + \starttext% +} + +\def\stopRSTproject{ + \stoptext \endgroup \endinput +} + \protect \endinput % vim:ft=context:sw=2:ts=2 |