ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: mf <massifr@fastwebnet.it>
To: ntg-context@ntg.nl
Subject: Re: nbsp in XML (S01E01)
Date: Wed, 21 Apr 2021 23:28:57 +0200	[thread overview]
Message-ID: <4f7c8e45-b26c-ca00-4149-0914dab1ca9f@fastwebnet.it> (raw)
In-Reply-To: <CAPefzZ2uDvcDgQ1M1j1EcmJVnqc3gj7rio7LygRKvp+7jdj5LQ@mail.gmail.com>

Try this:

%\xmltexentity{nbsp}{\nobreakspace}

\xmlsetentity{nbsp}{ } % U+00A0 NBSP between braces

%\xmlsetentity{nbsp}{ } % U+0020 normal space between braces



\startbuffer[doc]

<?xml version "1.0"?>

<document>

         <p>Temperature 20 °C 20 °C 20 °C 20 °C average.</p>

         <p>Altitude 6000&nbsp;m 6000&nbsp;m 6000&nbsp;m 6000&nbsp;m 
average.</p>

</document>

\stopbuffer



\startluacode

--[[

function lxml.preprocessor(data)

     -- data = string.gsub(data, "&nbsp;", "~")

     -- replacement nbsp invisible in luacode

     data = string.gsub(data, "&nbsp;", " ")

     return data

end

--]]

\stopluacode





\startxmlsetups xml:name

     \xmlsetsetup{\xmldocument}{*}{-}

     \xmlsetsetup{\xmldocument}{document|p}{xml:name:*}

\stopxmlsetups

\xmlregistersetup{xml:name}



\startxmlsetups xml:name:document

\xmlflush{#1}\par

\stopxmlsetups



\startxmlsetups xml:name:p

\parfillskip0pt\xmlflush{#1}\par

\stopxmlsetups



\startTEXpage[offset=5mm,width=60mm]

\xmlprocessbuffer{xml:name}{doc}{}

\stopTEXpage




Massi

Il 21/04/21 20:17, Jano Kula ha scritto:
> Dear list,
> 
> first episode of series on nbsp of XML in lmtx.
> Unfortunately, not that catchy as Netflix.
> 
> Used XML input has two types of non-breakable space:
> 
>   * unicode character
>   * html entitity (in fact an ugly output of HTML editor)
> 
> HTML is preprocessed with ctx preprocessor (great feature!) and 
> substituted for unicode char nbsp or tilde.
> 
> MWE shows unichar spaces are non-breakable (see end of the first lines), 
> however they are not stretchable (see second line of the paragraphs).
> 
> Does unicode nbsp have fixed with in ctx?
> 
> When tilde is the replacement in preprocessor (uncomment first 
> replacement in preprocessor), xmlfush will display tilde (which is, as 
> character, non-breakable and unstretchable, no surprise).
> 
> Why tilde is displayed?
> 
> Replacing or adding nbsp (tilde) with finalizers have different results, 
> see next episode after this one is understood.
> 
> Thank you,
> Jano
> 
> MWE (rather use attached file not to loose invisible characters):
> 
> \startbuffer[doc]
> <?xml version "1.0"?>
> <document>
>          <p>Temperature 20 °C 20 °C 20 °C 20 °C average.</p>
>          <p>Altitude 6000&amp;nbsp;m 6000&amp;nbsp;m 6000&amp;nbsp;m 
> 6000&amp;nbsp;m average.</p>
> </document>
> \stopbuffer
> 
> \startluacode
> function lxml.preprocessor(data)
>      -- data = string.gsub(data, "&amp;nbsp;", "~")
>      -- replacement nbsp invisible in luacode
>      data = string.gsub(data, "&amp;nbsp;", " ")
>      return data
> end
> \stopluacode
> 
> 
> \startxmlsetups xml:name
>      \xmlsetsetup{\xmldocument}{*}{-}
>      \xmlsetsetup{\xmldocument}{document|p}{xml:name:*}
> \stopxmlsetups
> \xmlregistersetup{xml:name}
> 
> \startxmlsetups xml:name:document
> \xmlflush{#1}\par
> \stopxmlsetups
> 
> \startxmlsetups xml:name:p
> \parfillskip0pt\xmlflush{#1}\par
> \stopxmlsetups
> 
> \startTEXpage[offset=5mm,width=60mm]
> \xmlprocessbuffer{xml:name}{doc}{}
> \stopTEXpage
> 
___________________________________________________________________________________
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
___________________________________________________________________________________

  parent reply	other threads:[~2021-04-21 21:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-21 18:17 Jano Kula
2021-04-21 18:37 ` Hans van der Meer
2021-04-21 21:09   ` Jano Kula
2021-04-21 21:17     ` denis.maier
2021-04-22  6:02     ` Taco Hoekwater
2021-04-21 21:28 ` mf [this message]
2021-04-22  9:36 ` Hans Hagen
2021-04-23 18:01   ` Jano Kula

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=4f7c8e45-b26c-ca00-4149-0914dab1ca9f@fastwebnet.it \
    --to=massifr@fastwebnet.it \
    --cc=ntg-context@ntg.nl \
    /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).