[NTG-context] How to do code listings & sections from XML (AsciiDoc)

Mojca Miklavec mojca.miklavec.lists at gmail.com
Sat Aug 13 08:13:56 CEST 2022

On Fri, 12 Aug 2022 at 23:20, Aditya Mahajan wrote:
> On Fri, 12 Aug 2022, Mojca Miklavec via ntg-context wrote:
> > Hi,
> >
> > Hans helped me out with some asciidoc processing a while ago.
> >
> > I played a bit further, but I'm currently facing two minor issues:
> >
> > (a) I don't know how to turn program listing (verbatim code) from xml
> > to (perhaps, vim-based) syntax highlighting (but most importantly, to
> > make sure that line breaks work properly)
> Does something like this work:
> https://wiki.contextgarden.net/Verbatim_XML

Yes, awesome, this does exactly what I want, thank you very much.

I used the following code:

    % this breaks if directory doesn't exist before
    % it would be potentially useful to have some predefined vimtyping
already present in the module

        function xml.functions.processprogramlisting(t)
.. tostring(xml.text(t)) .. "\n\\stopprogramlisting")
            context.getbuffer { "listing" }

    \startxmlsetups xml:programlisting

Now I need to get the "cpp" and "unnumbered" part processed
automatically, so that it will work for any language:

    <programlisting language="cpp" linenumbering="unnumbered">// test.cpp:
    int main()
        return 0;

which would then be transformed into

    int main()
        return 0;

For some reason the syntax highlighting doesn't work on the full
document, but it works inside the minimal example, so I still need to
investigate what's going on with the full document.

On an unrelated note:

I cannot make \startnarrow[middle=1cm] (or left=... for that matter)
produce any offset on the left. I was playing with the following
example, but the frame refuses to be shifted to the right


int main()
    return 0;


More information about the ntg-context mailing list