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