ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* [NTG-context] Replacing %20 with spaces in xml attributes
@ 2023-07-21 10:37 denis.maier
  2023-07-21 14:25 ` [NTG-context] " Hans van der Meer via ntg-context
  0 siblings, 1 reply; 3+ messages in thread
From: denis.maier @ 2023-07-21 10:37 UTC (permalink / raw)
  To: ntg-context


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

Hi,

I'm typesetting an XML document where the links to the images contain spaces which are encoded as %20
<graphic xlink:href="a%20filename%20with%20spaces.jpg"/>

Using this works in cases without spaces:

\startxmlsetups xml:fig:graphic
  \externalfigure[\xmlatt{#1}{xlink:href}]
\stopxmlsetups

This also works for normal spaces, but is there a way to decode/expand the %20s to regular spaces?

I've tried with some Lua, but I don't really know how to pass data around.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\startluacode
function replaceSpaces(s)
  result = string.gsub(s, "%%20", " ")
  context(result)
end
\stopluacode

\define[1]\replaceSpaces{\ctxlua{replaceSpaces("#1")}}

\startxmlsetups xml:fig:graphic
  \externalfigure[\replaceSpaces{\xmlatt{#1}{xlink:href}}]
\stopxmlsetups
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Any hints, why this does not work?`

Also, maybe there's a simpler way for this kind of scenario?

Best,
Denis

[-- Attachment #1.2: Type: text/html, Size: 3912 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [NTG-context] Re: Replacing %20 with spaces in xml attributes
  2023-07-21 10:37 [NTG-context] Replacing %20 with spaces in xml attributes denis.maier
@ 2023-07-21 14:25 ` Hans van der Meer via ntg-context
  2023-07-21 15:27   ` denis.maier
  0 siblings, 1 reply; 3+ messages in thread
From: Hans van der Meer via ntg-context @ 2023-07-21 14:25 UTC (permalink / raw)
  To: NTG ConTeXt; +Cc: Hans van der Meer


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

Here in Terminal on my Mac:

21 ~: lua
Lua 5.4.6  Copyright (C) 1994-2023 Lua.org, PUC-Rio
> string.gsub('a%20b', '%%20', ' ')
a b	1
> (string.gsub('a%20b', '%%20', ' '))
a b
> ^D
21 ~: 

The first call returns the 1 giving the match, the extra ()'s get rid of that second return value.

yours sincerely
dr. Hans van der Meer



> On 21 Jul 2023, at 12:37, denis.maier@unibe.ch wrote:
> 
> Hi,
>  
> I’m typesetting an XML document where the links to the images contain spaces which are encoded as %20
> <graphic xlink:href="a%20filename%20with%20spaces.jpg"/>
>  
> Using this works in cases without spaces:
>  
> \startxmlsetups xml:fig:graphic
>   \externalfigure[\xmlatt{#1}{xlink:href}]
> \stopxmlsetups
>  
> This also works for normal spaces, but is there a way to decode/expand the %20s to regular spaces?
>  
> I’ve tried with some Lua, but I don’t really know how to pass data around.
>  
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> \startluacode
> function replaceSpaces(s)
>   result = string.gsub(s, "%%20", " ")
>   context(result)
> end
> \stopluacode
>  
> \define[1]\replaceSpaces{\ctxlua{replaceSpaces("#1")}}
>  
> \startxmlsetups xml:fig:graphic
>   \externalfigure[\replaceSpaces{\xmlatt{#1}{xlink:href}}]
> \stopxmlsetups
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>  
> Any hints, why this does not work?`
>  
> Also, maybe there’s a simpler way for this kind of scenario?
> 
> Best,
> Denis
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
> 
> maillist : ntg-context@ntg.nl <mailto:ntg-context@ntg.nl> / https://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : https://www.pragma-ade.nl <https://www.pragma-ade.nl/> / http://context.aanhet.net <http://context.aanhet.net/>
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki     : https://contextgarden.net <https://contextgarden.net/>
> ___________________________________________________________________________________


[-- Attachment #1.2: Type: text/html, Size: 19488 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [NTG-context] Re: Replacing %20 with spaces in xml attributes
  2023-07-21 14:25 ` [NTG-context] " Hans van der Meer via ntg-context
@ 2023-07-21 15:27   ` denis.maier
  0 siblings, 0 replies; 3+ messages in thread
From: denis.maier @ 2023-07-21 15:27 UTC (permalink / raw)
  To: ntg-context


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

Thanks, but I'm still getting the same error. I'm thinking that it has something to do with the percent characters...

This here works just fine:

\startluacode
function test(s)
  result = string.gsub(s, 'x20', 'MATCH')
  context(result)
end
\stopluacode

\define[1]\test{\ctxlua{test("#1")}}

\starttext
\test{asdfx20} % -> asdfMATCH
\stoptext

But this here won't:

\startluacode
function test(s)
  result = string.gsub(s, '%%20', 'MATCH')
  context(result)
end
\stopluacode

\define[1]\test{\ctxlua{test("#1")}}

\starttext
\test{asdf%20} % -> does not work
\stoptext

Any ideas?

Best,
Denis


Von: Hans van der Meer via ntg-context <ntg-context@ntg.nl>
Gesendet: Freitag, 21. Juli 2023 16:26
An: NTG ConTeXt <ntg-context@ntg.nl>
Cc: Hans van der Meer <havdmeer@ziggo.nl>
Betreff: [NTG-context] Re: Replacing %20 with spaces in xml attributes

Here in Terminal on my Mac:


21 ~: lua

Lua 5.4.6  Copyright (C) 1994-2023 Lua.org, PUC-Rio

> string.gsub('a%20b', '%%20', ' ')

a b        1

> (string.gsub('a%20b', '%%20', ' '))

a b

> ^D

21 ~:


The first call returns the 1 giving the match, the extra ()'s get rid of that second return value.


yours sincerely
dr. Hans van der Meer




On 21 Jul 2023, at 12:37, denis.maier@unibe.ch<mailto:denis.maier@unibe.ch> wrote:

Hi,

I'm typesetting an XML document where the links to the images contain spaces which are encoded as %20
<graphic xlink:href="a%20filename%20with%20spaces.jpg"/>

Using this works in cases without spaces:

\startxmlsetups xml:fig:graphic
  \externalfigure[\xmlatt{#1}{xlink:href}]
\stopxmlsetups

This also works for normal spaces, but is there a way to decode/expand the %20s to regular spaces?

I've tried with some Lua, but I don't really know how to pass data around.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\startluacode
function replaceSpaces(s)
  result = string.gsub(s, "%%20", " ")
  context(result)
end
\stopluacode

\define[1]\replaceSpaces{\ctxlua{replaceSpaces("#1")}}

\startxmlsetups xml:fig:graphic
  \externalfigure[\replaceSpaces{\xmlatt{#1}{xlink:href}}]
\stopxmlsetups
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Any hints, why this does not work?`

Also, maybe there's a simpler way for this kind of scenario?

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

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


[-- Attachment #1.2: Type: text/html, Size: 18373 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-07-21 15:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-21 10:37 [NTG-context] Replacing %20 with spaces in xml attributes denis.maier
2023-07-21 14:25 ` [NTG-context] " Hans van der Meer via ntg-context
2023-07-21 15:27   ` denis.maier

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).