%D \module [ %D file=t-rst, %D version=0.3 ‘How to Recognise Different Types of Trees from Quite a Long Way Away’ %D title=\CONTEXT\ User Module, %D subtitle=reStructuredText, %D author=Philipp Gesang, %D date=\currentdate, %D copyright=Philipp Gesang, %D license=2-clause BSD, %D ] %M \usemodule[rst] %M \loadsetups[t-rst.xml] \writestatus{loading}{ConTeXt User Module / reStructuredText} \unprotect \startinterface all \setinterfacevariable {RST} {RST} \stopinterface \definenamespace [RST] [ type=module, comment=reStructuredText module, version=0.3, name=RST, style=no, command=yes, setup=list, parent=RST, ] %D Loading the reStructuredText parser. \ctxloadluafile{rst_parser} \startmoduletestsection \ctxlua{thirddata.rst_helpers.rst_debug = true} \stopmoduletestsection %%% Leaving this here in case we need to revert to locally %%% toggling debugging code. %\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. %\setupRST [debug=no] %D This command loads and processes the \type{*.rst} file. \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. \newcatcodetable \RST_catcodes \startcatcodetable \RST_catcodes \catcode`\^^I = 12 \catcode`\^^M = 12 \catcode`\^^L = 12 \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. % Wolfgang’s code below. \unexpanded \def \startRST{% \begingroup \setcatcodetable \RST_catcodes \do_start_RST% } \let \stopRST \relax \def \do_start_RST#1\stopRST{% \endgroup% \ctxlua{thirddata.rst.do_rst_snippet(\!!bs#1\!!es)}% } \def \RST{% \begingroup \setcatcodetable \RST_catcodes \do_RST% } \def \do_RST#1{% \endgroup% \ctxlua{thirddata.rst.do_rst_snippet(\!!bs#1\!!es)}% } \protect \endinput % vim:ft=context:sw=2:ts=2