* Adding syntax highlighting when typesetting from xml (asciidoc/docbook)
@ 2020-11-30 20:08 Mojca Miklavec
2020-12-01 10:41 ` Hans Hagen
0 siblings, 1 reply; 2+ messages in thread
From: Mojca Miklavec @ 2020-11-30 20:08 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1: Type: text/plain, Size: 1314 bytes --]
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
[-- Attachment #2: test-syntax-highlighting.xml --]
[-- Type: text/xml, Size: 644 bytes --]
<?xml version="1.0" encoding="UTF-8"?>
<?asciidoc-toc?>
<?asciidoc-numbered?>
<article xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0" xml:lang="en">
<info>
<title>Syntax highlighting with AsciiDoc</title>
<date>2020-11-30</date>
</info>
<section xml:id="_hello_world_in_c">
<title>Hello World in C</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>
</article>
[-- Attachment #3: test-syntax-highlighting.tex --]
[-- Type: application/octet-stream, Size: 108 bytes --]
\usemodule[asciidoc-basic]
\starttext
\xmlprocessfile{main}{test-syntax-highlighting.xml}{}
\stoptext
[-- Attachment #4: m-asciidoc-basic.tex --]
[-- Type: application/octet-stream, Size: 2324 bytes --]
% \enabletrackers[context*]
\usemodule[cals]
\startxmlsetups xml:whatever:a
\xmlsetsetup {#1} {
article|
section|
simpara|
itemizedlist|orderedlist|listitem|
emphasis|guibutton|
literal|programlisting|
superscript|subscript|
equation|inlineequation|
figure|mediaobject|informalfigure
} {xml:*}
\xmlsetsetup {#1} {
imageobject/imagedata
} {xml:image}
\xmlsetsetup {#1} {
imageobject
} {+}
\xmlsetfunction {#1} {table} {moduledata.cals.table}
\stopxmlsetups
\xmlregisterdocumentsetup{main}{xml:whatever:a}
\startxmlsetups xml:article
\startbodymatter
\xmlfilter{#1}{/section/command(xml:section)}
\stopbodymatter
\stopxmlsetups
\startxmlsetups xml:section
\startsectionlevel[title={\xmltext{#1}{/title}}]
\xmlall{#1}{/!title}
%\xmlall{#1}{}
\stopsectionlevel
\stopxmlsetups
\startxmlsetups xml:simpara
\xmlflush{#1}\par
\stopxmlsetups
\startxmlsetups xml:itemizedlist
\startitemize
\xmlflush{#1}
\stopitemize
\stopxmlsetups
\defineitemgroup[ordered]
\setupitemgroup[ordered][1][symbol=n]
\setupitemgroup[ordered][2][symbol=a]
\setupitemgroup[ordered][3][symbol=i]
\startxmlsetups xml:orderedlist
\startitemgroup[ordered]
\xmlflush{#1}
\stopitemgroup
\stopxmlsetups
\startxmlsetups xml:listitem
\startitem
\xmlflush{#1}
\stopitem
\stopxmlsetups
\xmlmapvalue{emphasis}{strong}{\bf}
\xmlmapvalue{emphasis}{normal}{\em}
\startxmlsetups xml:emphasis
\dontleavehmode
\start
\xmlvalue{emphasis}{\xmlattdef{#1}{role}{normal}}{normal}
\xmlflush{#1}
\stop
\stopxmlsetups
\startxmlsetups xml:literal
\dontleavehmode
\start
\tt
\xmlflush{#1}
\stop
\stopxmlsetups
\startxmlsetups xml:programlisting
\dontleavehmode
\startframedtext[background=color,backgroundcolor=lightgray]
\obeylines
\tt
\xmlflush{#1}
\stopframedtext
\stopxmlsetups
\startluacode
function xml.finalizers.tex.cdatatocontext(c)
context(xml.cdata(c[1]))
end
\stopluacode
\setupbodyfont
[dejavu,10pt]
\setuplayout
[middle]
\setupwhitespace
[big]
[-- Attachment #5: test-syntax-highlighting.adoc --]
[-- Type: application/octet-stream, Size: 296 bytes --]
= Syntax highlighting with AsciiDoc
:source-highlighter: pygments
== Hello World in C and ConTeXt
[source,cpp]
----
#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}
----
[source,context,linenums]
----
\starttext
Hello world!
\stoptext
----
[-- Attachment #6: Type: text/plain, Size: 493 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Adding syntax highlighting when typesetting from xml (asciidoc/docbook)
2020-11-30 20:08 Adding syntax highlighting when typesetting from xml (asciidoc/docbook) Mojca Miklavec
@ 2020-12-01 10:41 ` Hans Hagen
0 siblings, 0 replies; 2+ messages in thread
From: Hans Hagen @ 2020-12-01 10:41 UTC (permalink / raw)
To: mailing list for ConTeXt users, Mojca Miklavec
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
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-12-01 10:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-30 20:08 Adding syntax highlighting when typesetting from xml (asciidoc/docbook) Mojca Miklavec
2020-12-01 10:41 ` Hans Hagen
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).