[NTG-context] Adding syntax highlighting when typesetting from xml (asciidoc/docbook)

Mojca Miklavec mojca.miklavec.lists at gmail.com
Mon Nov 30 21:08:03 CET 2020


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-syntax-highlighting.xml
Type: text/xml
Size: 644 bytes
Desc: not available
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20201130/c83407fc/attachment.xml>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-syntax-highlighting.tex
Type: application/octet-stream
Size: 108 bytes
Desc: not available
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20201130/c83407fc/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: m-asciidoc-basic.tex
Type: application/octet-stream
Size: 2324 bytes
Desc: not available
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20201130/c83407fc/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-syntax-highlighting.adoc
Type: application/octet-stream
Size: 296 bytes
Desc: not available
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20201130/c83407fc/attachment-0002.obj>


More information about the ntg-context mailing list