Apologies, there are two rogue * in the lxml.preprocessor code, but even
when they are removed it doesn't work.
On Mon, 2 May 2022 at 08:19, Duncan Hothersall
I have a big set of existing XML books (held in a derivative of DocBook) which I'm looking to start processing directly with ConTeXt. (Up to now I have a system which converts the XML into ConTeXt code which is then processed, but this is inefficient and lots of the code is now unsupported.)
I've had some success producing output, but my first real sticking point has come with processing instructions. The existing XML contains lots of processing instructions of the form <?capdm whatever?>, some of which can be conditional and introduce new data etc. But I'd be happy at this stage if I could just process the most basic one of them, which is used to introduce a line stop in a running paragraph of text.
My best guess at how to do this was to use the lxml.preprocessor function to convert the processing instruction into an element, and then process the element as normal. But (a) my attempt didn't work, and (b) there may well be a better way.
Minimal working example below, except that obviously the processing instruction bit doesn't work!
Thanks for any help or insights.
Duncan
MWE: ------
\startbuffer[demo] <book> <para>A paragraph with<?capdm force_line_stop?>a processing instruction.</para> </book> \stopbuffer
\startxmlsetups xml:demo:base \xmlsetsetup{#1}{*}{xml:demo:*} \stopxmlsetups \xmlregisterdocumentsetup{demo}{xml:demo:base}
\startxmlsetups xml:demo:book \xmlflush{#1} \stopxmlsetups
\startxmlsetups xml:demo:para \xmlflush{#1}\endgraf \stopxmlsetups
\startluacode function lxml.preprocessor(data,settings) return string.find(data,"<?capdm *force_line_stop?>") and string.gsub(data,"<?capdm *force_line_stop?>","<capdmlinestop>") or data end \stopluacode
\startxmlsetups xml:demo:capdmlinestop \crlf \xmlflush{#1} \stopxmlsetups
\setupbodyfont[modern] \starttext \xmlprocessbuffer{demo}{demo}{} \stoptext
------
-- Duncan Hothersall, Operations Director CAPDM Limited - Online Program Enablers 0131 677 2400 www.capdm.com Registered in Scotland: SC168970 VAT: 682 846 983 Registered address: 20 Forth Street Edinburgh EH1 3LH UK https://maps.google.com/?q=22+Forth+Street,+Edinburgh,+EH1+3LH,+UK&entry=gmail&source=g Capture, author, publish, deliver and manage your learning materials. *Sign up to the CAPDM newsletter here http://eepurl.com/bqzBQn*