rust-lang / mdBook

Create book from markdown files. Like Gitbook but implemented in Rust
https://rust-lang.github.io/mdBook/
Mozilla Public License 2.0
17.84k stars 1.62k forks source link

Keep summary links untouched (including Markdown formatting) instead of extracting just plain text #2412

Open max-heller opened 2 months ago

max-heller commented 2 months ago

Problem

When a link/part title/etc. in SUMMARY.md contains Markdown fancier than plaintext, mdBook strips out all of the formatting and uses just the plaintext as the name of the item:

https://github.com/rust-lang/mdBook/blob/ec996d350955a8974f8cae5a55c1374ae8da4fac/src/book/summary.rs#L595-L606

I'm running into an issue where:

Proposed Solution

I propose that mdBook preserve the original Markdown for links/part titles/etc. in SUMMARY.md.

https://github.com/rust-lang/mdBook/pull/1785, which relates to a similar issue, noted this, stating that:

The only safe thing to do would be to grab the raw text from the original markdown, which is awkward to do with pulldown_cmark.

Is this still an issue? It should be possible to use the ranges provided by pulldown_cmark through its offset iterator (which mdBook already uses to parse the summary) to grab the Markdown source from the raw &str of the summary by keeping track of the start of the range when the name begins and the end of the range when the name ends.

https://github.com/rust-lang/mdBook/blob/ec996d350955a8974f8cae5a55c1374ae8da4fac/src/book/summary.rs#L164-L165

Notes

This would have to be a breaking change