On Feb 5, 2017, at 12:09 PM, Aditya Mahajan
wrote: 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
Thanks! I figured there must be a function like that. Michael ________________________________ This e-mail message (including any attachments) is for the sole use of the intended recipient(s) and may contain confidential and privileged information. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message (including any attachments) is strictly prohibited. If you have received this message in error, please contact the sender by reply e-mail message and destroy all copies of the original message (including attachments).