From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/114829 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Duncan Hothersall via ntg-context Newsgroups: gmane.comp.tex.context Subject: Re: XML processing instructions Date: Mon, 2 May 2022 09:24:55 +0100 Message-ID: References: <643c4b177ba64ac1bb5c108776a9bb0a@unibe.ch> Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0741121420162790083==" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27592"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Duncan Hothersall , mailing list for ConTeXt users To: denis.maier@unibe.ch Original-X-From: ntg-context-bounces@ntg.nl Mon May 02 10:25:51 2022 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nlRNP-0006zJ-7H for gctc-ntg-context-518@m.gmane-mx.org; Mon, 02 May 2022 10:25:51 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 0C7972A374D; Mon, 2 May 2022 10:25:14 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uTmmMSV5rZTV; Mon, 2 May 2022 10:25:11 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id DD5212A3741; Mon, 2 May 2022 10:25:10 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 7FE7E2A373B for ; Mon, 2 May 2022 10:25:08 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id l_Kgr5MVYmk2 for ; Mon, 2 May 2022 10:25:06 +0200 (CEST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.167.45; helo=mail-lf1-f45.google.com; envelope-from=dh@capdm.com; receiver= Original-Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id 508E02A373A for ; Mon, 2 May 2022 10:25:06 +0200 (CEST) Original-Received: by mail-lf1-f45.google.com with SMTP id p12so24078573lfs.5 for ; Mon, 02 May 2022 01:25:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=capdm.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mq3VYJ5J9UddB0B5gG7Woa62TzvdSBS3dO3bbt1iFoI=; b=SAl4gt1vgMB1jPz+RiHnXBY8JP08vwrtT2SARZhAhs70QDoNEKCi+HISc5Y+1hc3qG AOROAAKo6nWz487aPfiKrIPzoe2R22dJiQ/HkElmk4/+U8DrT++6elui+2nANpRPi9Zr jSPA1Iz2l3KUpwU5zuf8howtB1lpayAueP5ZU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=mq3VYJ5J9UddB0B5gG7Woa62TzvdSBS3dO3bbt1iFoI=; b=laQvtyJWbdwt2k9KtUNE3uilzeS7T4FA5ot8COIF4Kj4N62XXVZsB1MNfy0cdK5RUz kDAcx5qjV4CXBQ6N98xYT5fP9KueQ1fTjXvHvyRUbHiwM5sgx8kfsB361yF+YNpsryVf Lmg9sO8S216Swv1YahS5LxiQuP3ZdZpx8jBCIBnwxqFOiIJdbNbG6Uujlf4xxqivbA0/ T2inURnB/JPiefjTHvONiK6BocNi3G/IHC5GnGHb3sL+B62pSvo5YfigifjYD1LulDHX 4eTe/E8rOvJ4RGsd6opcCicvJAWzoUia0Mk0DvVJTWv+osSmJU6RUHQOo1cFOfcVDPbq RX8Q== X-Gm-Message-State: AOAM532h1/nEsZlrR29KOMbOyc/y5aJAHFc7nea4JtlvKxHUfVOGIQh4 MUZ0hpZq2Z0QazMc0nLxZZddMxIEnQROMZBUF9JOQg== X-Google-Smtp-Source: ABdhPJznB0UhnaMDdse1YJvAbw4kFKqEm2wQnAA1vID9VJ0omeMLzbpujFPyyM3hkSnUvkAcQASKgPihvknmxHPKiVQ= X-Received: by 2002:a19:4f53:0:b0:472:1714:61f1 with SMTP id a19-20020a194f53000000b00472171461f1mr8181477lfk.473.1651479905599; Mon, 02 May 2022 01:25:05 -0700 (PDT) In-Reply-To: X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:114829 Archived-At: --===============0741121420162790083== Content-Type: multipart/alternative; boundary="0000000000002095f805de03218f" --0000000000002095f805de03218f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 , wrote: > That was too quick, sorry. > > > > Hi Duncan, > > > > I have used context=E2=80=99s own injectors for this : > > > > > > > > \startsetups xml:directive:injector:addlinetopage > > \adaptlayout[lines=3D+1] > > \stopsetups > > > > Or, for your line break example : > > > > > > > > \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} > > > > > > > > > > > > Best, > > Denis > > > > *Von:* Maier, Denis Christian (UB) > *Gesendet:* Montag, 2. Mai 2022 09:45 > *An:* 'mailing list for ConTeXt users' > *Cc:* Duncan Hothersall > *Betreff:* AW: [NTG-context] XML processing instructions > > > > > > *Von:* ntg-context *Im Auftrag von *Duncan > Hothersall via ntg-context > *Gesendet:* Montag, 2. Mai 2022 09:20 > *An:* mailing list for ConTeXt users > *Cc:* Duncan Hothersall > *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 unsupporte= d.) > > > > 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 > > , 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 t= he > 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] > > A paragraph witha processing > instruction. > > \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,"") > and string.gsub(data," *force_line_stop?>","") > or data > end > \stopluacode > > \startxmlsetups xml:demo:capdmlinestop > \crlf > \xmlflush{#1} > \stopxmlsetups > > \setupbodyfont[modern] > \starttext > \xmlprocessbuffer{demo}{demo}{} > \stoptext > > > > ------ > --0000000000002095f805de03218f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
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 l= ot of XML data with the existing processing instructions in it. I know I co= uld 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 w= ay 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.

=C2=A0

Hi Duncan,=

=C2=A0

I have used context=E2=80=99s o= wn injectors for this=C2=A0:

=C2=A0

<?context-directive injector= addlinetopage ?>

=C2=A0

\startsetups xml:directive:inje= ctor:addlinetopage

=C2=A0 \adaptlayout[lines=3D+1]=

\stopsetups

=C2=A0

Or, for your line break example= =C2=A0:

=C2=A0

<?context-directive injector= newline ?>

=C2=A0

\startsetups xml:directive:inje= ctor:newline

=C2=A0 \crlf

\stopsetups

=C2=A0

Also, I have learned that you c= an just use arbitrary context code in xml:

=C2=A0

\def\xmltexdirective#1#2{\doif{= #1}{command}{#2}}

=C2=A0

\xmlinstalldirective{tex}{xmlte= xdirective}

=C2=A0

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 <?context-directive tex command \inframed{xxx} ?><= u>

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 <?context-directive tex command \page ?>=

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 <?context-directive tex command \crlf ?>=

=C2=A0

Best,

Denis

=C2=A0

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=

=C2=A0

=C2=A0

Von: ntg-context <n= tg-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

=C2=A0

I have a big set of existing XM= L books (held in a derivative of DocBook) which I'm looking to start pr= ocessing directly with ConTeXt. (Up to now I have a system which converts t= he XML into ConTeXt code which is then processed, but this is inefficient and lots of the code is now unsupported.)

=C2=A0

I've had some success produ= cing output, but my first real sticking point has come with processing inst= ructions. The existing XML contains lots of processing instructions of the = form=C2=A0

<?capdm whatever?>, some = of which can be conditional and introduce new data etc. But I'd be happ= y at this stage if I could just process the most basic one of them, which i= s used to introduce a line stop in a running paragraph of text.

=C2=A0

My best guess at how to do this= was to use the=C2=A0lxml.preprocessor function to convert the processing i= nstruction into an element, and then process the element as normal. But (a) my attempt didn't work, and (b) there may well be a bett= er way.

=C2=A0

Minimal working example below, = except that obviously the processing instruction bit doesn't work!

=C2=A0

Thanks for any help or insights.

=C2=A0

Duncan

=C2=A0

=C2=A0

MWE:

------

=C2=A0

\startbuffer[demo]
<book>
=C2=A0 <para>A paragraph with<?capdm force_line_stop?>a process= ing instruction.</para>
</book>
\stopbuffer

\startxmlsetups xml:demo:base
=C2=A0\xmlsetsetup{#1}{*}{xml:demo:*}
\stopxmlsetups
\xmlregisterdocumentsetup{demo}{xml:demo:base}

\startxmlsetups xml:demo:book
=C2=A0\xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:demo:para
=C2=A0\xmlflush{#1}\endgraf
\stopxmlsetups

\startluacode
=C2=A0function lxml.preprocessor(data,settings)
=C2=A0 return string.find(data,"<?capdm *force_line_stop?>"= )
=C2=A0 =C2=A0and string.gsub(data,"<?capdm *force_line_stop?>&qu= ot;,"<capdmlinestop></capdmlinestop/>")
=C2=A0 =C2=A0or data
=C2=A0end
\stopluacode

\startxmlsetups xml:demo:capdmlinestop
=C2=A0\crlf
=C2=A0\xmlflush{#1}
\stopxmlsetups

\setupbodyfont[modern]
\starttext
\xmlprocessbuffer{demo}{demo}{}
\stoptext

=C2=A0

------

--0000000000002095f805de03218f-- --===============0741121420162790083== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============0741121420162790083==--