On 9/19/2018 2:50 PM, Taco Hoekwater wrote:
Hi,
Is there a more elegant way to feed an xml tree into a context() command that what I have below?
\startluacode function xml.functions.heading(t) context.section("{") lxml.flush(t) context("}") end \stopluacode
The subtree in âtâ could have embedded xml tags that should be processed, so just stripping it clean will not do.
(this is not about \section as such, I just needed an example. \startsection would be more modern, but it would not help fix the issue ) it actually depends on what you do ... anyway here is some insight (as xml-tex old-timer you'll probably recognize the madness)
% \enabletrackers[context*] \starttext % here is your missing mwe \startbuffer[test] <document> <section>some <b>bold</b> title</section> </document> \stopbuffer % this will assume xml and relate some handlers \setuphead[section] [coding=xml, xmlsetup=xml:flush] \startxmlsetups xml:flush \xmlflush{#1} \stopxmlsetups % comment this one for your amusement \startxmlsetups xml:b {\bf \xmlflush{#1}} \stopxmlsetups % here is the magic: you pass a reference \startluacode function xml.finalizers.heading(t) context.formatted.section("main::%i",t[1].ix) end \stopluacode % this loads only (can happen at the lua end ... you can sort that out) \xmlloadbuffer{main}{test}{} % this indexes the nodes (the ix keys, basically all these #1 argumehnts in setups use that trickery) \xmladdindex{main} % to be sure \xmlsetsetup{main}{b}{xml:b} % now we filter / apply your finalizer \xmlfilter{main}{section/heading()} % done \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 -----------------------------------------------------------------