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 -----------------------------------------------------------------