You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does Pandoc do any automatic URL/percent encoding in output URLs?
Does Pandoc decode in input URLs?
If (1) does Pandoc recognise when an URL already is wholly or partly encoded?
If (1) and (3) can I rely on URLs not becoming double-encoded?
What about identifiers/fragments? I'm not quite sure about the rules. (w) Is encoding at all supported in those, and (b) if so how does Pandoc handle it?
It seems like already encoded URLs are passed through as is,
but I want to be sure what gives. Somewhat heavy-handed
encoding1 with Lua is easy, but is it even needed? If it
is what about including (smarter) URL
encoding/decoding functions in the Lua API?
Footnotes
-- os.setlocale('C')
local url_encode
do
-- byte('!') --> %21
local pc_hex_fmt = '%%%02X'
local byte2pc_hex = function(b)
return pc_hex_fmt:format(b:byte())
end
url_encode = function(url)
-- TODO Return nil for nil?
if url == nil then
return ""
end
-- Must be a string (or nil)
if not ('string' == type(url)) then
error('Argument is not a string')
end
-- Return early if empty
if "" == url then
return ""
end
-- Network newlines
url = url:gsub("\n", "\r\n")
-- Encode all except unreserved and SPACE
-- DONE More fine-grained selection of "unsafe" chars
url = url:gsub('[^%w%-%_%~%.\x20]', byte2pc_hex)
-- SPACE --> +
url = url:gsub("\x20", '+')
return url
end
end
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
(Apologies if this is old hat!)
It seems like already encoded URLs are passed through as is,
but I want to be sure what gives. Somewhat heavy-handed
encoding1 with Lua is easy, but is it even needed? If it
is what about including (smarter) URL
encoding/decoding functions in the Lua API?
Footnotes
Beta Was this translation helpful? Give feedback.
All reactions