![](https://secure.gravatar.com/avatar/5955e8e90611e77ccbfc7721b6112027.jpg?s=120&d=mm&r=g)
Hans, I have the following sample: \startbuffer[demo] <doc> <div> <source>\command[option=value]{text "<&>"}</source> </div> <div class="sourceCode"> <pre class="sourceCode tex"> <code class="sourceCode latex"> <span class="fu">\command</span>[option=value]{text "<&>"} </code> </pre> </div> </doc> \stopbuffer \startxmlsetups xml:initialize \xmlsetsetup{#1}{doc|source|div|span}{xml:*} \xmlsetsetup{\xmldocument} {pre[contains(@class,'sourceCode')]/ code[contains(@class,'sourceCode')]} {xml:pre:code} \stopxmlsetups \xmlregistersetup{xml:initialize} \startxmlsetups xml:doc \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:div \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:source \xmlprettyprint{#1}{tex} \stopxmlsetups \startxmlsetups xml:pre:code \xmlflushspacewise{#1} \stopxmlsetups \startxmlsetups xml:span \bgroup\xmlflush{#1}\egroup \stopxmlsetups The .sourceCode elements are the standard way in which pandoc serves colored code. I have to deal with them. In the sample above, for xml:pre:code, I would need and expanded \xmlprettyprint that also ignores tags inside (anything between < and >, but not the entities). Which is the way to get this expanded \xmlprettyprint? Many thanks for your help, Pablo -- http://www.ousia.tk
![](https://secure.gravatar.com/avatar/49e63acb01f2ca80efce7eed08310ce8.jpg?s=120&d=mm&r=g)
On 7/23/2017 9:28 PM, Pablo Rodriguez wrote:
Hans,
I have the following sample:
\startbuffer[demo] <doc> <div> <source>\command[option=value]{text "<&>"}</source> </div>
<div class="sourceCode"> <pre class="sourceCode tex"> <code class="sourceCode latex"> <span class="fu">\command</span>[option=value]{text "<&>"} </code> </pre> </div> </doc> \stopbuffer
\startxmlsetups xml:initialize \xmlsetsetup{#1}{doc|source|div|span}{xml:*} \xmlsetsetup{\xmldocument} {pre[contains(@class,'sourceCode')]/ code[contains(@class,'sourceCode')]} {xml:pre:code} \stopxmlsetups
\xmlregistersetup{xml:initialize}
\startxmlsetups xml:doc \xmlflush{#1} \stopxmlsetups
\startxmlsetups xml:div \xmlflush{#1} \stopxmlsetups
\startxmlsetups xml:source \xmlprettyprint{#1}{tex} \stopxmlsetups
\startxmlsetups xml:pre:code \xmlflushspacewise{#1} \stopxmlsetups
\startxmlsetups xml:span \bgroup\xmlflush{#1}\egroup \stopxmlsetups
The .sourceCode elements are the standard way in which pandoc serves colored code. I have to deal with them.
In the sample above, for xml:pre:code, I would need and expanded \xmlprettyprint that also ignores tags inside (anything between < and >, but not the entities).
Which is the way to get this expanded \xmlprettyprint? The xml that we see is getting more weird every day .. anyway
\startluacode function lxml.tobufferX(id,pattern,name) local collected = xml.applylpath(lxml.getid(id),pattern) if collected then local t = { } xml.string(collected[1],function(s) t[#t+1] = s end) buffers.assign(name,table.concat(t)) else buffers.erase(name) end end \stopluacode \unprotect \unexpanded\def\xmlprettyprinttext#1#2% {\ctxlua{lxml.tobufferX("#1",".","xml-temp")}% \ifdefined\scitebuffer \scitebuffer[#2][xml-temp]% \else \typebuffer[xml-temp][\c!option=#2]% \fi} \protect I'll add \xmlprettyprinttext to the core (somewhat different implementation) so that you can do \startxmlsetups xml:source \xmlprettyprinttext{#1}{tex} \stopxmlsetups \startxmlsetups xml:pre:code \xmlprettyprinttext{#1}{tex} \stopxmlsetups ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
![](https://secure.gravatar.com/avatar/5955e8e90611e77ccbfc7721b6112027.jpg?s=120&d=mm&r=g)
On 07/24/2017 10:48 AM, Hans Hagen wrote:
On 7/23/2017 9:28 PM, Pablo Rodriguez wrote:
[...] Which is the way to get this expanded \xmlprettyprint? The xml that we see is getting more weird every day .. anyway
\startluacode
function lxml.tobufferX(id,pattern,name) local collected = xml.applylpath(lxml.getid(id),pattern) if collected then local t = { } xml.string(collected[1],function(s) t[#t+1] = s end) buffers.assign(name,table.concat(t)) else buffers.erase(name) end end
\stopluacode
\unprotect
\unexpanded\def\xmlprettyprinttext#1#2% {\ctxlua{lxml.tobufferX("#1",".","xml-temp")}% \ifdefined\scitebuffer \scitebuffer[#2][xml-temp]% \else \typebuffer[xml-temp][\c!option=#2]% \fi}
\protect
I'll add \xmlprettyprinttext to the core (somewhat different implementation) [...]
Many thanks for your reply and the new \xmlprettyprinttext, Hans. Yesterday, I totally forgot about inline code, such as in the sample below. Which would be the \xmlprettyprinttext command for inline code? \startluacode function lxml.tobufferX(id,pattern,name) local collected = xml.applylpath(lxml.getid(id),pattern) if collected then local t = { } xml.string(collected[1],function(s) t[#t+1] = s end) buffers.assign(name,table.concat(t)) else buffers.erase(name) end end \stopluacode \unprotect \unexpanded\def\xmlprettyprinttext#1#2% {\ctxlua{lxml.tobufferX("#1",".","xml-temp")}% \ifdefined\scitebuffer \scitebuffer[#2][xml-temp]% \else \typebuffer[xml-temp][\c!option=#2]% \fi} \protect \startbuffer[demo] <doc> <div> <source>\command[option=value]{text "<&}</source> </div> <p>This is inline code <code class="sourceCode latex"><span class="fu">\command</span>[option=value]{text "<&}</code>.</p> </doc> \stopbuffer \startxmlsetups xml:initialize \xmlsetsetup{#1}{doc|source|div}{xml:*} \xmlsetsetup{#1} {code[contains(@class,'latex')]} {xml:code} \stopxmlsetups \xmlregistersetup{xml:initialize} \startxmlsetups xml:doc \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:div \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:source \xmlprettyprint{#1}{tex} \stopxmlsetups \startxmlsetups xml:code \xmlprettyprinttext{#1}{tex} \stopxmlsetups \starttext \xmlprocessbuffer{main}{demo}{} \stoptext Many thanks for your help, Pablo -- http://www.ousia.tk
![](https://secure.gravatar.com/avatar/49e63acb01f2ca80efce7eed08310ce8.jpg?s=120&d=mm&r=g)
On 7/23/2017 9:28 PM, Pablo Rodriguez wrote:
\xmlsetsetup{#1}{doc|source|div|span}{xml:*}
also use #1 here:
\xmlsetsetup{\xmldocument} \xmlsetsetup{#1}
----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
participants (2)
-
Hans Hagen
-
Pablo Rodriguez