%D \module [ %D file=t-rst, %D version=0.2 ‘Sex and Violence’ %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.2, name=reST, style=no, command=yes, setup=list, parent=RST, ] %D Loading the reStructuredText parser. \ctxlua{environment.loadluafile("rst_parser")} %D Setting some globals. \setupreST [ ] %D This command loads and processes the \type{*.rst} file. \def\typesetRSTfile#1{\ctxlua{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 %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% } \let\stopRST\relax \def\dostartRST#1\stopRST{% \edef\RSTdata{#1}% \setcatcodetable \ctxcatcodes% \ctxlua{rst.do_rst_snippet([[\RSTdata]])}% } \def\RST{% \setcatcodetable \RSTcatcodes% \doRST% } \def\doRST#1{% \def\RSTdata{#1}% \setcatcodetable \ctxcatcodes% \ctxlua{rst.do_rst_snippet([[\RSTdata]])}% } \protect \endinput