ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Duncan Hothersall via ntg-context <ntg-context@ntg.nl>
To: denis.maier@unibe.ch
Cc: Duncan Hothersall <dh@capdm.com>,
	mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: XML processing instructions
Date: Mon, 2 May 2022 09:24:55 +0100	[thread overview]
Message-ID: <CAN8fp9WcOrx9BJnFu1Mmu_qq0TpLtZcyWPb7XpovcSFOOFj5eQ@mail.gmail.com> (raw)
In-Reply-To: <b42b97ee7f634220a277bde55c8c1c5b@unibe.ch>


[-- Attachment #1.1: Type: text/plain, Size: 4164 bytes --]

Many thanks Denis. Very useful tip on the injectors and generalised command
usage. That will definitely come in useful.

My problem is that I already have a lot of XML data with the existing
processing instructions in it. I know I could use an external preprocess in
something like Python to change them into injectors before they are fed
into ConTeXt, but I was hoping there was a way to handle them directly as
part of the ConTeXt / lua process.

Thanks again though.

Duncan




On Mon, 2 May 2022, 08:48 , <denis.maier@unibe.ch> wrote:

> That was too quick, sorry.
>
>
>
> Hi Duncan,
>
>
>
> I have used context’s own injectors for this :
>
>
>
> <?context-directive injector addlinetopage ?>
>
>
>
> \startsetups xml:directive:injector:addlinetopage
>
>   \adaptlayout[lines=+1]
>
> \stopsetups
>
>
>
> Or, for your line break example :
>
>
>
> <?context-directive injector newline ?>
>
>
>
> \startsetups xml:directive:injector:newline
>
>   \crlf
>
> \stopsetups
>
>
>
> Also, I have learned that you can just use arbitrary context code in xml:
>
>
>
> \def\xmltexdirective#1#2{\doif{#1}{command}{#2}}
>
>
>
> \xmlinstalldirective{tex}{xmltexdirective}
>
>
>
>          <?context-directive tex command \inframed{xxx} ?>
>
>          <?context-directive tex command \page ?>
>
>          <?context-directive tex command \crlf ?>
>
>
>
> Best,
>
> Denis
>
>
>
> *Von:* Maier, Denis Christian (UB)
> *Gesendet:* Montag, 2. Mai 2022 09:45
> *An:* 'mailing list for ConTeXt users' <ntg-context@ntg.nl>
> *Cc:* Duncan Hothersall <dh@capdm.com>
> *Betreff:* AW: [NTG-context] XML processing instructions
>
>
>
>
>
> *Von:* ntg-context <ntg-context-bounces@ntg.nl> *Im Auftrag von *Duncan
> Hothersall via ntg-context
> *Gesendet:* Montag, 2. Mai 2022 09:20
> *An:* mailing list for ConTeXt users <ntg-context@ntg.nl>
> *Cc:* Duncan Hothersall <dh@capdm.com>
> *Betreff:* [NTG-context] XML processing instructions
>
>
>
> 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></capdmlinestop/>")
>    or data
>  end
> \stopluacode
>
> \startxmlsetups xml:demo:capdmlinestop
>  \crlf
>  \xmlflush{#1}
> \stopxmlsetups
>
> \setupbodyfont[modern]
> \starttext
> \xmlprocessbuffer{demo}{demo}{}
> \stoptext
>
>
>
> ------
>

[-- Attachment #1.2: Type: text/html, Size: 9709 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

  reply	other threads:[~2022-05-02  8:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-02  7:19 Duncan Hothersall via ntg-context
2022-05-02  7:33 ` Duncan Hothersall via ntg-context
2022-05-02  7:44 ` Denis Maier via ntg-context
2022-05-02  7:48   ` Denis Maier via ntg-context
2022-05-02  8:24     ` Duncan Hothersall via ntg-context [this message]
2022-05-03  7:30       ` Duncan Hothersall via ntg-context
  -- strict thread matches above, loose matches on Subject: below --
2002-03-18 20:11 XML Processing Instructions Michael Wiedmann
2002-03-21 19:36 ` Simon Pepping
2002-03-23 13:28   ` Michael Wiedmann
2002-03-23 10:08     ` Hans Hagen
2002-03-24 21:23     ` Simon Pepping
2002-03-24 22:50       ` Michael Wiedmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAN8fp9WcOrx9BJnFu1Mmu_qq0TpLtZcyWPb7XpovcSFOOFj5eQ@mail.gmail.com \
    --to=ntg-context@ntg.nl \
    --cc=denis.maier@unibe.ch \
    --cc=dh@capdm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).