dealing with the lang attribute in XML
Dear list, I’m trying to write an environment to typeset HTML generated by pandoc with ConTeXt MkIV. One of the issues I’m experiencing is dealing with the lang attribute. The required sample: \startbuffer[demo] <doc lang="en"> <p>This is an English paragraph.</p> <p lang="de">Aber dieser Absatz ist auf Deutsch und enthält Spanisch (<span lang="es-ES">prueba</span>).</p> </doc> \stopbuffer \starttext \hsize\zeropoint \startxmlsetups xml:initialize \xmlsetsetup{#1}{p|doc|span}{xml:*} \stopxmlsetups \xmlregistersetup{xml:initialize} \startxmlsetups xml:doc \mainlanguage[\xmlatt{#1}{lang}] \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:p \begingroup\language[\xmlatt{#1}{lang}]\xmlflush{#1}\endgroup\par \stopxmlsetups \startxmlsetups xml:span \begingroup\language[\xmlatt{#1}{lang}]\xmlflush{#1}\endgroup \stopxmlsetups \xmlprocessbuffer{main}{demo}{} \stoptext The question is how to deal with the lang attribute in a single xmlsetup (at least for p and span [not all those elements might have a lang attribute, they can inherit it]). And a second question would be: how can I deal with language values in XML and ConTeXt? A \processaction command? Many thanks for your help, Pablo -- http://www.ousia.tk
On 1/6/2015 10:12 PM, Pablo Rodriguez wrote:
Dear list,
I’m trying to write an environment to typeset HTML generated by pandoc with ConTeXt MkIV.
One of the issues I’m experiencing is dealing with the lang attribute.
The required sample:
\startbuffer[demo] <doc lang="en">
<p>This is an English paragraph.</p>
<p lang="de">Aber dieser Absatz ist auf Deutsch und enthält Spanisch (<span lang="es-ES">prueba</span>).</p>
</doc> \stopbuffer
\starttext \hsize\zeropoint
\startxmlsetups xml:initialize \xmlsetsetup{#1}{p|doc|span}{xml:*} \stopxmlsetups
\xmlregistersetup{xml:initialize}
\startxmlsetups xml:doc \mainlanguage[\xmlatt{#1}{lang}] \xmlflush{#1} \stopxmlsetups
\startxmlsetups xml:p \begingroup\language[\xmlatt{#1}{lang}]\xmlflush{#1}\endgroup\par \stopxmlsetups
\startxmlsetups xml:span \begingroup\language[\xmlatt{#1}{lang}]\xmlflush{#1}\endgroup \stopxmlsetups
\xmlprocessbuffer{main}{demo}{}
\stoptext
The question is how to deal with the lang attribute in a single xmlsetup (at least for p and span [not all those elements might have a lang attribute, they can inherit it]).
And a second question would be: how can I deal with language values in XML and ConTeXt? A \processaction command?
there is \xmlval cum suis for mapping attributes but in this case you can just use \language and define language synomyms if needed
Many thanks for your help,
\startxmlsetups xml:initialize \xmlsetsetup{#1}{*}{xml:*} \xmlsetsetup{#1}{(p|span)[@lang]}{xml:lang} \stopxmlsetups \xmlregistersetup{xml:initialize} \startxmlsetups xml:lang \begingroup \language[\xmlatt{#1}{lang}] \xmlsetup{#1}{xml:\xmltag{#1}} \endgroup \stopxmlsetups \startxmlsetups xml:doc \mainlanguage[\xmlatt{#1}{lang}] \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:p \xmlflush{#1} \par \stopxmlsetups \startxmlsetups xml:span \xmlflush{#1} \stopxmlsetups Here is a solution that can save you some time: \usemodule[html] \startxmlsetups xml:initialize \xmlsetup{#1}{xml:html:basics} \xmlsetup{#1}{xml:html:tables} \xmlsetsetup{#1}{(p|span)[@lang]}{xml:lang} \stopxmlsetups \xmlregistersetup{xml:initialize} \startxmlsetups xml:lang \begingroup \language[\xmlatt{#1}{lang}] \xmlsetup{#1}{xml:html:\xmltag{#1}} \endgroup \stopxmlsetups (some reasonable defaults) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On 01/07/2015 12:17 AM, Hans Hagen wrote:
[...] And a second question would be: how can I deal with language values in XML and ConTeXt? A \processaction command?
there is \xmlval cum suis for mapping attributes but in this case you can just use \language and define language synomyms if needed
Many thanks for your reply, Hans. Which is the right way to to define language synonyms? (I cannot make \setlanguagesynonym work. This is what I found searching in the wiki.)
Here is a solution that can save you some time:
\usemodule[html]
Well, it seems that I was trying to reinvent the wheel. Where can I find the module and its documentation? (I haven’t found anything searching for html in the filename.) Many thanks for your help, Pablo -- http://www.ousia.tk
On 1/7/2015 9:30 AM, Pablo Rodriguez wrote:
On 01/07/2015 12:17 AM, Hans Hagen wrote:
[...] And a second question would be: how can I deal with language values in XML and ConTeXt? A \processaction command?
there is \xmlval cum suis for mapping attributes but in this case you can just use \language and define language synomyms if needed
Many thanks for your reply, Hans.
Which is the right way to to define language synonyms?
\installanguage[foo][nl]
(I cannot make \setlanguagesynonym work. This is what I found searching in the wiki.)
Here is a solution that can save you some time:
\usemodule[html]
Well, it seems that I was trying to reinvent the wheel.
Where can I find the module and its documentation? (I haven’t found anything searching for html in the filename.)
hm, i forgot to rename the file in the zip maker script .. will be in next beta
Many thanks for your help,
Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On 01/07/2015 11:05 AM, Hans Hagen wrote:
On 1/7/2015 9:30 AM, Pablo Rodriguez wrote:
[...] Which is the right way to to define language synonyms?
\installanguage[foo][nl]
Many thanks for your reply and the fixes, Hans. Pablo -- http://www.ousia.tk
participants (2)
-
Hans Hagen
-
Pablo Rodriguez