ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <j.hagen@xs4all.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
	Mojca Miklavec <mojca.miklavec.lists@gmail.com>
Subject: Re: Adding syntax highlighting when typesetting from xml (asciidoc/docbook)
Date: Tue, 1 Dec 2020 11:41:12 +0100	[thread overview]
Message-ID: <bb8fbd03-49cd-b271-3d4b-b746fbbbf1f4@xs4all.nl> (raw)
In-Reply-To: <CALBOmsZWmA86OTcYeWJWOhWYawoQVkR48=8M87gxFz7-hOtCsw@mail.gmail.com>

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
> &lt;stdio.h&gt;
> 
> 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
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

      reply	other threads:[~2020-12-01 10:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-30 20:08 Mojca Miklavec
2020-12-01 10:41 ` Hans Hagen [this message]

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=bb8fbd03-49cd-b271-3d4b-b746fbbbf1f4@xs4all.nl \
    --to=j.hagen@xs4all.nl \
    --cc=mojca.miklavec.lists@gmail.com \
    --cc=ntg-context@ntg.nl \
    /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).