From 78d44502d0e4dc5179b703189da54bc3dfe0d306 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 4 May 2011 17:44:12 +0200 Subject: confirming to Lua module namespace; alternate code from Wolfgang (resting for now) --- mod/tex/context/third/rst/t-rst.mkiv | 102 ++++++++++++++++++++++------------- 1 file changed, 66 insertions(+), 36 deletions(-) (limited to 'mod/tex/context/third/rst/t-rst.mkiv') diff --git a/mod/tex/context/third/rst/t-rst.mkiv b/mod/tex/context/third/rst/t-rst.mkiv index 015aa4a..d54af02 100644 --- a/mod/tex/context/third/rst/t-rst.mkiv +++ b/mod/tex/context/third/rst/t-rst.mkiv @@ -23,7 +23,7 @@ type=module, comment=reStructuredText module, version=0.2, - name=reST, + name=RST, style=no, command=yes, setup=list, @@ -31,63 +31,93 @@ ] %D Loading the reStructuredText parser. -\ctxlua{environment.loadluafile("rst_parser")} +\ctxloadluafile{rst_parser} + +\def\RST_enable_verbose{% + \doif{\RSTparameter{debug}}\v!yes\ctxlua{thirddata.rst_helpers.rst_debug = true}% +} +\appendtoks \RST_enable_verbose \to \everysetupRST %D Setting some globals. -\setupreST [ ] +\setupRST [debug=no] %D This command loads and processes the \type{*.rst} file. -\def\typesetRSTfile#1{\ctxlua{rst.do_rst_file("#1")}} +\def\typesetRSTfile#1{\ctxlua{thirddata.rst.do_rst_file("#1")}} %D To process inline reST markup we’ll have to reset all catcodes %D except for grouping, escaping and cs arguments. -\ifdefined\RSTcatcodes \else - \newcatcodetable \RSTcatcodes - \startcatcodetable \RSTcatcodes - \catcode`\^^I = 12 % ascii tab is a blank space - \catcode`\^^M = 12 % ascii return is end-line - \catcode`\^^L = 12 % ascii form-feed - \catcode`\ = 12 - \catcode`\^^Z = 12 - \catcode`\\ = 0 - \catcode`\% = 12 - \catcode`\# = 6 - \catcode`\_ = 12 - \catcode`\^ = 12 - \catcode`\& = 12 - \catcode`\| = 12 - \catcode`\{ = 1 - \catcode`\} = 2 - \catcode`\~ = 12 - \catcode`\$ = 12 - \stopcatcodetable -\fi +\newcatcodetable \RST_catcodes +\startcatcodetable \RST_catcodes + \catcode`\^^I = 12 % ascii tab is a blank space + \catcode`\^^M = 12 % ascii return is end-line + \catcode`\^^L = 12 % ascii form-feed + \catcode`\ = 12 + \catcode`\^^Z = 12 + \catcode`\\ = 0 + \catcode`\% = 12 + \catcode`\# = 6 + \catcode`\_ = 12 + \catcode`\^ = 12 + \catcode`\& = 12 + \catcode`\| = 12 + \catcode`\{ = 1 + \catcode`\} = 2 + \catcode`\~ = 12 + \catcode`\$ = 12 +\stopcatcodetable %D The environment \type{\[start|stop]RST} and the macro %D \type{\RST} allow access to reST-parser from inside a %D \CONTEXT-document when the module is loaded. -\unexpanded\def\startRST{ - \setcatcodetable \RSTcatcodes% - \dostartRST% +\unexpanded\def\startRST{% + \setcatcodetable \RST_catcodes% + \do_start_RST% } \let\stopRST\relax -\def\dostartRST#1\stopRST{% - \edef\RSTdata{#1}% +\def\do_start_RST#1\stopRST{% + \edef\RST_data{#1}% \setcatcodetable \ctxcatcodes% - \ctxlua{rst.do_rst_snippet([[\RSTdata]])}% + \ctxlua{thirddata.rst.do_rst_snippet([[\RST_data]])}% } \def\RST{% - \setcatcodetable \RSTcatcodes% - \doRST% + \setcatcodetable \RST_catcodes% + \do_RST% } -\def\doRST#1{% - \def\RSTdata{#1}% +\def\do_RST#1{% + \def\RST_data{#1}% \setcatcodetable \ctxcatcodes% - \ctxlua{rst.do_rst_snippet([[\RSTdata]])}% + \ctxlua{thirddata.rst.do_rst_snippet([[\RST_data]])}% } +%%% Wolfgang’s code below; needs testing +%\unexpanded\def\startRST{% + %\begingroup + %\setcatcodetable \RSTcatcodes + %\dostartRST% +%} + +%\let\stopRST\relax + +%\def\dostartRST#1\stopRST{% + %\ctxlua{thirddata.rst.do_rst_snippet(\!!bs#1\!!es)}% + %\endgroup% +%} + +%\def\RST{% + %\begingroup + %\setcatcodetable \RSTcatcodes + %\doRST% +%} + +%\def\doRST#1{% + %\ctxlua{thirddata.rst.do_rst_snippet(\!!bs#1\!!es)}% + %\endgroup% +%} + \protect \endinput + +% vim:ft=context:sw=2:ts=2 -- cgit v1.2.3