How to prevent spaces being changed into '%20' when using file links? #10231
Replies: 3 comments 1 reply
-
I am not sure you can or maybe using the raw syntax, see https://quarto.org/docs/authoring/markdown-basics.html#raw-content. Note that creating links (independently of the protocol) with spaces in it is really considered as a bad practice for obvious reasons such as the issue you are facing. |
Beta Was this translation helpful? Give feedback.
-
Thank you - I will certainly try the 'raw' option. I agree about the spaces in links. In this case I need to create links into a repository of existing documents and files. Those documents have been created by many people who use Windows as their primary operating system and are used to using spaces in file names. As you say - it is not desirable, but at the moment I am stuck with it. I may, in the future, do a bulk renaming of documents in the repository but as you can imagine, this can easily cause problems in itself. Thank you for your help. |
Beta Was this translation helpful? Give feedback.
-
I believe this is due to own Pandoc behavior that will HTML escaped the target part of the link
Pandoc does URL escape in the Reader directly > quarto pandoc --to native
[My file](file:///C:\Users\Fred Bloggs\Doc 000-000-0001.docx)
^Z
[ Para
[ Link
( "" , [] , [] )
[ Str "My" , Space , Str "file" ]
( "file:///C:\\Users\\Fred%20Bloggs\\Doc%20000-000-0001.docx"
, ""
)
]
] So as this is quite specific right now, I do think you should leverage a custom filter option to catch those links of yours, and unnescape what needs to be For example Link = function(l)
if (l.target:match('^file://')) then
l.target = l.target:gsub("%%20", " ")
end
return l
end and then in your document or project filters:
- custom.lua You could even add an attribute or class to catch on the link to decode those only. You may need more than FWIW we have internal function for this kind of things but we don't export them yet. quarto-cli/src/resources/filters/common/url.lua Lines 4 to 24 in 913292c Hope it helps |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
I want to insert a hyperlink to a file I have stored on my computer. I am using Windows 10.
When I include a link as below, the exported versions in both HTML and pdf subsitute %20 for all of the spaces. This would work on a web-based URL .. but does not work on windows as a file reference.
Produces this:
<p><a href="file:///C:\Users\Fred%20Bloggs\Doc%20000-000-0001.docx">My file</a></p>
Which does not work on windows (I get a 'file not found error")
I need this:
<p><a
href="file:///C:\Users\Fred Bloggs\Doc 000-000-0001.docx">My fileBeta Was this translation helpful? Give feedback.
All reactions