From: Mojca Miklavec via ntg-context <ntg-context@ntg.nl>
To: Aditya Mahajan <adityam@umich.edu>
Cc: Mojca Miklavec <mojca.miklavec.lists@gmail.com>,
Mojca Miklavec via ntg-context <ntg-context@ntg.nl>
Subject: Re: How to do code listings & sections from XML (AsciiDoc)
Date: Sat, 13 Aug 2022 08:13:56 +0200 [thread overview]
Message-ID: <CALBOmsbwQLAnZJEeWU-qvMmSmaepD-5-UO6stgc05cqvRLoFcw@mail.gmail.com> (raw)
In-Reply-To: <nycvar.YAK.7.78.908.2208121718560.280663@nqv-guvaxcnq>
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:
\usemodule[vim]
% this breaks if directory doesn't exist before
\setupvimtyping[directory=output/]
% it would be potentially useful to have some predefined vimtyping
already present in the module
\definevimtyping
[programlisting]
[syntax=]
\startluacode
function xml.functions.processprogramlisting(t)
buffers.assign("listing","\\startprogramlisting[syntax=cpp]\n"
.. tostring(xml.text(t)) .. "\n\\stopprogramlisting")
context.getbuffer { "listing" }
end
\stopluacode
\startxmlsetups xml:programlisting
\pushcatcodetable
\setcatcodetable\ctxcatcodes
\xmlfunction{#1}{processprogramlisting}
\popcatcodetable
\stopxmlsetups
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;
}</programlisting>
which would then be transformed into
\startprogramlisting[syntax=cpp,numbering=no]
int main()
{
return 0;
}
\stopprogramlisting
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
\setupvimtyping
[before={
\startnarrow[left=1cm,before={\blank[10pt]}]
\switchtobodyfont[8pt]
\startframed
[align=flushleft,
background=color,
backgroundcolor=gray,
frame=off,
leftframe=on,
rulethickness=2pt,
framecolor=darkgray,
width=local,
offset=1ex]},
after={\stopframed\stopnarrow}]
Hello
\startprogramlisting[syntax=cpp,numbering=yes]
int main()
{
return 0;
}
\stopprogramlisting
Mojca
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage : https://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : https://contextgarden.net
___________________________________________________________________________________
next prev parent reply other threads:[~2022-08-13 6:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-12 15:37 Mojca Miklavec via ntg-context
2022-08-12 21:20 ` Aditya Mahajan via ntg-context
2022-08-13 6:13 ` Mojca Miklavec via ntg-context [this message]
2022-08-13 6:15 ` Mojca Miklavec via ntg-context
2022-08-12 22:30 ` Max Chernoff via ntg-context
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CALBOmsbwQLAnZJEeWU-qvMmSmaepD-5-UO6stgc05cqvRLoFcw@mail.gmail.com \
--to=ntg-context@ntg.nl \
--cc=adityam@umich.edu \
--cc=mojca.miklavec.lists@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).