From: Aditya Mahajan <adityam@umich.edu>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Encoding reserved characters in URI query strings
Date: Sun, 5 Feb 2017 09:09:39 -0800 (PST) [thread overview]
Message-ID: <alpine.OSX.2.02.1702050907250.67748@nqv-znpobbx> (raw)
In-Reply-To: <E255428E-072A-4691-B8D2-A5A68505B392@emory.edu>
On Sun, 5 Feb 2017, Rogers, Michael K wrote:
> Let's say I want a link to plot x+2 in Wolfram|Alpha. I need to catenate "http://www.wolframalpha.com/input/?i=" and "plot+x%2B2". Is there any way already available in ConTeXt to translate reserved characters like "+" to the percent-hexcode "%2B"?
>
> Something like
>
> \encode[plot x+2]
>
> would become
>
> plot+x%2B2
>
> Or more generally, some languages have a query constructor like this
>
> \queryURI
> [http://www.wolframalpha.com/input]
> [i=plot x+2]
>
> which would construct the URI
>
> http://www.wolframalpha.com/input/?i=plot+x%2B2
>
> I could write my own, of course. But no need to reinvent the wheel.
url.escape does exactly that.
\startluacode
local base="http://www.wolframalpha.com/input"
local query="i=plot x+2"
local fullname = base .. query
print(url.escape(fullname))
\stopluacode
gives
http%3A//www.wolframalpha.com/inputi%3Dplot%20x%2B2
Also look at l-url.lua for other helper functions for parsing and
escaping/unescaping urls.
Aditya
___________________________________________________________________________________
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
___________________________________________________________________________________
next prev parent reply other threads:[~2017-02-05 17:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-05 14:06 Rogers, Michael K
2017-02-05 17:09 ` Aditya Mahajan [this message]
2017-02-05 17:22 ` Rogers, Michael K
2017-02-07 12:24 ` Bibliography Jean-Pierre Delange
2017-02-07 15:12 ` Bibliography Alan Braslau
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=alpine.OSX.2.02.1702050907250.67748@nqv-znpobbx \
--to=adityam@umich.edu \
--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).