-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
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:
Lines 595 to 606 in ec996d3
| /// Removes the styling from a list of Markdown events and returns just the | |
| /// plain text. | |
| fn stringify_events(events: Vec<Event<'_>>) -> String { | |
| events | |
| .into_iter() | |
| .filter_map(|t| match t { | |
| Event::Text(text) | Event::Code(text) => Some(text.into_string()), | |
| Event::SoftBreak => Some(String::from(" ")), | |
| _ => None, | |
| }) | |
| .collect() | |
| } |
I'm running into an issue where:
- A chapter is named "`Box<T>`"
- The name of the chapter, as reported by
mdBook("Box<T>" without the backticks), is inserted into another chapter - The <T> is interpreted as raw HTML since it is no longer enclosed in inline code
- The chapter title is rendered as "Box" (with no <T>, since that is interpreted as an empty and meaningless HTML tag)
- When converting the book to EPUB, which is more strict about closing tags, the <T> being interpreted as HTML instead of inline code breaks rendering altogether
Proposed Solution
I propose that mdBook preserve the original Markdown for links/part titles/etc. in SUMMARY.md.
#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.
Lines 164 to 165 in ec996d3
| src: &'a str, | |
| stream: pulldown_cmark::OffsetIter<'a, DefaultBrokenLinkCallback>, |
Notes
This would have to be a breaking change