Repository navigation
Description
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
Prerequisites
- I'm using the latest version of Docusaurus.
- I have tried the
npm run clearoryarn clearcommand. - I have tried
rm -rf node_modules yarn.lock package-lock.jsonand re-installing packages. - I have tried creating a repro with https://new.docusaurus.io.
- I have read the console error message carefully (if applicable).
Description
Links that contain spaces have to be enclosed in pointy brackets (<>) according to the CommonMark specification (see here). In Docusaurus, the links are displayed properly, but are routed to the original filename (i.e. they also keep the original file extension). A link such as [Link](<./file 1.md>) will go to https://<yourwebsitehere>/<yourpathhere>/file%201.md if onBrokenLinks is set to warn and will completely fail the build process otherwise.
Reproducible demo
Steps to reproduce
- Create a file with a space in its name.
- Link to it using a Markdown link (do not forget to properly enclose it in pointy brackets).
- (Optional) Set
onBrokenLinkstowarnindocusaurus.config.js. - Build the website and try the link, or observe the error.
Expected behavior
Build succeeds if onBrokenLinks is not set to warn, link works properly otherwise.
In the linked reproduction, links 2 and 3 should go to https://vladnastase.github.io/docusaurus-bug/chapter1/doc%202 and https://vladnastase.github.io/docusaurus-bug/chapter%202/doc1 respectively (instead of https://vladnastase.github.io/docusaurus-bug/chapter1/doc%202.md and https://vladnastase.github.io/docusaurus-bug/chapter%202/doc1.md)
Actual behavior
Build fails if onBrokenLinks is not set to warn, links don't work properly (they keep the original file extension).
Your environment
- Public source code: https://github.com/VladNastase/docusaurus-bug
- Public site URL: https://vladnastase.github.io/docusaurus-bug/
- Docusaurus version used: 2.4.0
- Environment name and version (e.g. Chrome 89, Node.js 16.4): Chrome 111, Node.js 16.17.1
- Operating system and version (e.g. Ubuntu 20.04.2 LTS): Ubuntu 22.04.1 LTS
Self-service
- I'd be willing to fix this bug myself.
Activity
slorber commentedon Apr 6, 2023
Thanks, didn't know about this markdown link escaping rule in CommonMark.
Runnable repro: https://stackblitz.com/~/github.com/VladNastase/docusaurus-bug
Note repro shows:
To complete your repro:
I think we can consider this a valid bug, even though the linking to .md extensions is something proprietary, we should be able to use spaces in such links.
Using
%20instead of space is a good temporary workaroundHimmu5 commentedon Apr 9, 2023
Subject: Request to work on Issue #8867
Hi there,
My name is Himanshu Chauhan.
I noticed that there's an open issue [#8867] that I think I can help with. It's about to solve this bug. I'm interested in working on this issue and contributing to the project.
Before I start working on it, I wanted to check with you to see if it's okay for me to work on this issue. If it is, could you provide me with any guidance on how to proceed with the issue? I'm eager to learn more about the project and contribute to it in any way that I can.
Thank you for your time and consideration.
Best regards,
Himanshu Chauhan
morsko1 commentedon Apr 11, 2023
The problem is that existing regex for Markdown links doesn't match filenames that contain whitespaces and wrapped with
<>.I have created PR #8874 with modified regex.
I tested these changes locally with files and folders that contain spaces and looks like it fixes the issue.
Here is the link to updated regex where you can check how it matches filenames with or without spaces.