My 2 cents: local xmlflush = lxml.flush local function text_or_xml(...) for i,v in ipairs(arg) do if "table" == type(v) then xmlflush(v) else context(v) end end end function xml.functions.heading(t) text_or_xml( "\\section{" , t , "}" ) end Massimiliano Il giorno mer, 19/09/2018 alle 15.56 +0200, Hans Hagen ha scritto:
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 ----------------------------------------------------------------- _____________________________________________________________________ ______________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net _____________________________________________________________________ ______________