ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: <denis.maier@unibe.ch>
To: <ntg-context@ntg.nl>
Subject: [NTG-context] XML: Correct usage of hash symbol in url
Date: Fri, 25 Aug 2023 08:16:16 +0000	[thread overview]
Message-ID: <ZRAP278MB0495250B92D776D9493C540C83E3A@ZRAP278MB0495.CHEP278.PROD.OUTLOOK.COM> (raw)


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

Hi,

I need to process URLs in XML documents differently depending on the target. Thanks to Hans and Thomas I can now deal with the attributes.
Now I need to prefix certain kind of targets with a certain URL (a web viewer for IIIF images in this particular case). The prefix contains a #, which, as a special character seems to cause an error. Adding a double hash seems to work, but those ## will end up in the link URL. How can I properly escape a single #? I've already tried using \Ux{23}, but that won't work either.

Best,
Denis

\setupinteraction[state=start]

\startxmlsetups xml:test
                \xmlsetsetup{#1}{*}{-}
                \xmlsetsetup{#1}{doc|element}{xml:*}
\stopxmlsetups

\xmlregisterdocumentsetup{test}{xml:test}

\startxmlsetups xml:doc
\xmlflush{#1}
\stopxmlsetups

\startluacode
     function xml.finalizers.tex.url(e,a)
         local u = #e > 0 and e[1].at[a]
         local s = u and lpeg.match(lpeg.patterns.urlunescaper,u)
         context(s)
     end
\stopluacode

\startxmlsetups xml:element
\xmldoifelse{#1}{.[@href and contains(@href,'https://iiif.ub.unibe.ch')]}

                {\goto{\xmlflush{#1}}[url(https://uv-v4.netlify.app/##?manifest=\xmlatt{#1}{href})]} % gives me two hashes in the Link

                %{\goto{\xmlflush{#1}}[url(https://uv-v4.netlify.app/#?manifest=\xmlatt{#1}{xlink:href})]} \par % does not work

                {\goto{\xmlflush{#1}}[url(\xmlatt{#1}{href})]}
\stopxmlsetups


\startbuffer[test]
<?xml version="1.0" encoding="UTF-8"?>
<doc>
<element href="https://iiif.ub.unibe.ch/presentation/v2.1/berner-inkunabeln/manifest/Inc%20I%20104%20fol%20a1r">IIIF-Link</element>
<element href="https://wiki.contextgarden.net/">Other Link</element>
</doc>
\stopbuffer

\starttext

\xmlprocessbuffer{test}{test}{}

\stoptext

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

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

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : https://contextgarden.net
___________________________________________________________________________________

             reply	other threads:[~2023-08-25  8:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-25  8:16 denis.maier [this message]
2023-08-25  8:35 ` [NTG-context] " Hans Hagen via ntg-context
2023-08-27 11:52 ` [NTG-context] Re: XML: Correct usage of hash symbol in url / new upload Hans Hagen via ntg-context

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=ZRAP278MB0495250B92D776D9493C540C83E3A@ZRAP278MB0495.CHEP278.PROD.OUTLOOK.COM \
    --to=denis.maier@unibe.ch \
    --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