Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Files with spaces are not found #527

Closed
dns2utf8 opened this issue Jan 5, 2018 · 5 comments
Closed

Files with spaces are not found #527

dns2utf8 opened this issue Jan 5, 2018 · 5 comments

Comments

@dns2utf8
Copy link

dns2utf8 commented Jan 5, 2018

Hi all

I noticed that referenced files with spaces in the filename are not found.
However if I replace the spaces with + es mdbook finds the file.
Sadly the file is not accessable over http later.
Funny side effect reverting the + to spaces in the browser finds the correct file again.

Best,
Stefan

@Michael-F-Bryan
Copy link
Contributor

How exactly are you referencing these files? Can you provide an example?

It sounds like the issue is that markdown links are rendered as normal HTML links (the <a> tag), and browsers don't like having spaces in URLs.

@dns2utf8
Copy link
Author

dns2utf8 commented Jan 6, 2018

I have the book in a weird state currently, but with this commit I get the error from the file in the way as it does translate the link into html but it does not work.
https://gitlab.com/dns2utf8/buch.feuerfestival.org/-/jobs/46822514

The CI throws a file not found error but I dont know why yet.

@Michael-F-Bryan
Copy link
Contributor

I just checked out a local version of your book and I believe I was able to reproduce the issue you're talking about.

First you add a dummy chapter to the book where the name contains a space:

$ echo "- [Another Chapter](./another chapter.md)" >> src/SUMMARY.md
$ echo "# Another Chapter" >> "src/another chapter.md"

Then you go to another chapter and try to link to it.

None of these work:

  • [Another Chapter](./another chapter.md) - won't work because the rendered document being linked to is HTML
  • [Another Chapter](./another chapter.html) - links containing spaces aren't valid markdown (according to here)

However these work:

  • [Another Chapter](./another\ chapter.html) - the space is escaped (valid markdown)
  • [Another Chapter](./another%20chapter.html) - uses percent encoding
    [Another Chapter](./another+chapter.html) - the + is also a valid replacement for space in a URL

It seems the issue is actually intended behaviour from the Common Mark spec. Markdown links aren't allowed to contain space characters (it introduces ambiguities with the link title), so you need to escape them with either \, +, or %20.


The CI throws a file not found error but I dont know why yet.

The master version of mdbook has much better logging and error handling, so you get nicer error messages. Apparently you've put video.css as in your book.toml, but because additional CSS and JS files are resolved relative to the book's root it should actually be src/video.css.

Error: Unable to copy across additional CSS and JS
    Caused by: Copying video.css failed
    Caused by: No such file or directory (os error 2)

@dns2utf8
Copy link
Author

dns2utf8 commented Jan 6, 2018

Wow! Thank you very much for the deep analysis!
I applied the fixes and the build command runs trough now.

What confused me was the serve command would not mention any errors.

@Michael-F-Bryan
Copy link
Contributor

I think that's because the serve command was set up to re-run every time a file changes, but then if building fails it'll swallow the error instead of printing it to the user. Probably so you don't spam users with error messages.

The error message situation should be better since #522, where the code run each time a file changes was updated. It'll now log any errors which occur during re-rendering, as well as all that Caused By: ... chain, hopefully giving the user a better idea of what went wrong and how to fix it.

Ninjani added a commit to out-of-cheese-error/gooseberry that referenced this issue Jan 17, 2021
Ninjani added a commit to out-of-cheese-error/gooseberry that referenced this issue Jan 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants