[NTG-context] handling code in XML

Hans Hagen pragma at wxs.nl
Tue Feb 24 15:17:38 CET 2015


\startbuffer[demo]
<doc>
<pre>
\def\whatever#1{[whatever #1]}

\ctxlua{print("okay")}
</pre>
</doc>
\stopbuffer

\usemodule[scite]

\startxmlsetups xml:initialize
     \xmlsetsetup{#1}{doc|pre}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:initialize}

\starttexdefinition xmlsaveinbuffer #1
     \ctxlua{buffers.assign("foo",xml.content(lxml.id('#1')))}
\stoptexdefinition

\starttexdefinition xmlprettyprint #1#2
     \xmlsaveinbuffer{#1}
     \typebuffer[foo][option=#2]
\stoptexdefinition

\starttexdefinition xmlprettyprint #1#2
     \start
         \tt
         \xmlsaveinbuffer{#1}
         \setcatcodetable\ctxcatcodes
         \scitebuffer[#2][foo]
     \stop
\stoptexdefinition

\startxmlsetups xml:doc
     \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:pre
     \xmlprettyprint{#1}{tex}
\stopxmlsetups

\starttext

     \xmlprocessbuffer{main}{demo}{}

\stoptext




-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------


More information about the ntg-context mailing list