Adding syntax highlighting when typesetting from xml (asciidoc/docbook)
![](https://secure.gravatar.com/avatar/6114858d84b0f40cf715f12237ab67a1.jpg?s=120&d=mm&r=g)
Hi, A while ago Hans provided an example of typesetting a document from a docbook source. I'm attaching an over-simplified version of the initial module (a somewhat more complete version exists, but it still needs lots of work) and a minimum working example with XML. I'm not sure how to extend the xml parser to support typesetting from something like this: <section xml:id="_hello_world_in_c_and_context"> <title>Hello World in C and ConTeXt</title> <programlisting language="cpp" linenumbering="unnumbered">#include <stdio.h> int main() { printf("Hello, World!\n"); return 0; }</programlisting> <programlisting language="context" linenumbering="numbered">\starttext Hello world! \stoptext</programlisting> </section> Maybe using the vim module would be the right approach here (since the built-in parser only has support for a limited set of languages), but I'm not exactly sure about the implementation to achieve that goal. I started with \startxmlsetups xml:programlisting \dontleavehmode \startframedtext[background=color,backgroundcolor=lightgray] \obeylines \tt \xmlflush{#1} \stopframedtext \stopxmlsetups but something more is needed to properly handle new lines and to properly pass the text to vim, for example. Any hints welcome. Thank you, Mojca
![](https://secure.gravatar.com/avatar/46562c7d27388490d62e8d7a5bc960dd.jpg?s=120&d=mm&r=g)
On 11/30/2020 9:08 PM, Mojca Miklavec wrote:
Hi,
A while ago Hans provided an example of typesetting a document from a docbook source.
I'm attaching an over-simplified version of the initial module (a somewhat more complete version exists, but it still needs lots of work) and a minimum working example with XML.
I'm not sure how to extend the xml parser to support typesetting from something like this:
<section xml:id="_hello_world_in_c_and_context"> <title>Hello World in C and ConTeXt</title> <programlisting language="cpp" linenumbering="unnumbered">#include <stdio.h>
int main() { printf("Hello, World!\n"); return 0; }</programlisting> <programlisting language="context" linenumbering="numbered">\starttext Hello world! \stoptext</programlisting> </section>
Maybe using the vim module would be the right approach here (since the built-in parser only has support for a limited set of languages), but I'm not exactly sure about the implementation to achieve that goal.
I started with
\startxmlsetups xml:programlisting \dontleavehmode \startframedtext[background=color,backgroundcolor=lightgray] \obeylines \tt \xmlflush{#1} \stopframedtext \stopxmlsetups
but something more is needed to properly handle new lines and to properly pass the text to vim, for example.
Any hints welcome. \startbuffer[demo] <doc> <pre type='tex'> \def\whatever#1{[whatever #1]}
\ctxlua{print("okay")} </pre> <pre type='xml'> <html> <b>bold</b> </html> </pre> </doc> \stopbuffer \usemodule[scite] \startxmlsetups xml:initialize \xmlsetsetup{#1}{doc|pre}{xml:*} \stopxmlsetups \xmlregistersetup{xml:initialize} \startxmlsetups xml:doc \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:pre \blank \xmlprettyprint{#1}{\xmlattdef{#1}{type}{txt}} \blank \stopxmlsetups \starttext \xmlprocessbuffer{main}{demo}{} \stoptext ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
participants (2)
-
Hans Hagen
-
Mojca Miklavec