-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Please make SUMMARY.md support urlencode markdown file name #1640
Comments
Can I take this if no one else is already working on this? |
Yea, of course! I would probably start looking at around here. I don't know if mdbook has any existing escape function, or if one is readily available in a dependency. |
Thank you @ehuss for the pointers. I am trying to see how mdbook reacts to the following entry in
The mdbook uses pulldown-cmark library to parse links in summary.md. The presense of "?" breaks the parser.
The above code dumps the following response: event=Start(Paragraph)
event=Text(Borrowed("["))
event=Text(Borrowed("Hello World"))
event=Text(Borrowed("]"))
event=Text(Borrowed("(./Hello World?.md)"))
event=End(Paragraph) The library is able to parse the links if we use the format Example:
There is an existing function but it only works for "<" and ">". I found a percent_encoding which lets us control what characters need to be escaped. I am assuming since the toc should only contain names of the md book file, is it safe to escape "?" character as well? There seems to be some weird rules like this. |
Hey, sorry to jump in the middle of your work, but I would like to ask, would it be better to sanitize the path instead of urlencoding it? Urlencoding can get tricky with multiple characters, and as per the stack overflow link @apatniv has added, it depends on which RFC is used, which encoding is used etc. Added to that, the url-encoded name will not be easily legible as a file name, if generating a file, with possible added issues that the filesystem, depending on OS might not support the characters used, especially with chapter names that might contain Unicode non-ascii symbols. |
I don't think it is the In general, mdbook doesn't seem to support any sort of escaping in the summary other than space (added in #1293). Although I'd be reluctant to encourage anyone to use strange characters like |
Good observation. It is actually the space that is breaking the parser. text = event=Start(Paragraph)
event=Start(Link(Inline, Borrowed("./HelloWorld?.md"), Borrowed("")))
event=Text(Borrowed("first"))
event=End(Link(Inline, Borrowed("./HelloWorld?.md"), Borrowed("")))
event=End(Paragraph) text = event=Start(Paragraph)
event=Text(Borrowed("["))
event=Text(Borrowed("first"))
event=Text(Borrowed("]"))
event=Text(Borrowed("(./Hello World?.md)"))
event=End(Paragraph) |
Hello, I have hit this issue when working with an external tool that generate markdowns with url-encoded links. The current implementation only replaces %20 with spaces, so any other special character (accents for example) create 404 links. The common mark specification qualifies links as "URI" and other editors supporting markdown (vscode, obsidian) also support percent-encoded links, I think that urldecoding links is a sane approach here. I have an implementation using urlencoding to do this, and simply decoding the url from summary fixes my issue with exported markdown and the question mark one of this issue. It does not enforce it, so both @ehuss and other readers, if this approach is alright, I'll open the PR :) (the only missing thing is documenting the change I think) |
By the way, the fix according to CommonMark is to enclose the destination in angle brackets. So both of these should function normally:
|
Example,There is a markdown file with a question mark in its file name.
now i have to show it in SUMMARY.md
and the result in toc is
after click the link, the page will jump to the wrong url, the part "?.html" of the url will be the search part of url.
I hope I can write the markdown as
and the result is
so, please support
The text was updated successfully, but these errors were encountered: