-
Notifications
You must be signed in to change notification settings - Fork 8
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
Use mdbook::utils::new_cmark_parser
to preserve tables
#17
Conversation
This was accidentally lost in 900cd77.
Before, we would ignore the Markdown settings from mdBook and parse the content with default settings. This meant that we did not support Markdown tables, which are an extension to regular Markdown. The result was that tables were mangled after the preprocessor had run. We now use the mdBook utility function to construct the Markdown parser, thus getting consistent results. This makes tables survive the parsing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Thank you so much 👍
fix format
Thanks, happy to merge that of course! About the formatting: I'm pretty sure my editor ran |
Ah, I see now: the rustfmt run failed. The problem was that I had a |
let events = parser.map(|e| { | ||
use State::*; | ||
use Event::*; | ||
use CowStr::*; | ||
use CodeBlockKind::*; | ||
use Tag::{CodeBlock, Paragraph}; | ||
|
||
match (&e, &mut state) { | ||
(Start(CodeBlock(Fenced(Borrowed(mark)))), None) if mark == &cfg.code_block => { | ||
state = Open; | ||
Some(Start(Paragraph)) | ||
}, | ||
|
||
(Text(Borrowed(text)), Open) => { | ||
state = Closing; | ||
Some(Html(bob_handler(text, &cfg.settings).into())) | ||
}, | ||
|
||
(End(CodeBlock(Fenced(Borrowed(mark)))), Closing) if mark == &cfg.code_block => { | ||
state = None; | ||
Some(End(Paragraph)) | ||
}, | ||
_ => Some(e), | ||
} | ||
}) | ||
.flatten(); |
Check warning
Code scanning / clippy
called `map(..).flatten()` on `Iterator`
let events = parser.map(|e| { | ||
use State::*; | ||
use Event::*; | ||
use CowStr::*; | ||
use CodeBlockKind::*; | ||
use Tag::{CodeBlock, Paragraph}; | ||
|
||
match (&e, &mut state) { | ||
(Start(CodeBlock(Fenced(Borrowed(mark)))), None) if mark == &cfg.code_block => { | ||
state = Open; | ||
Some(Start(Paragraph)) | ||
}, | ||
|
||
(Text(Borrowed(text)), Open) => { | ||
state = Closing; | ||
Some(Html(bob_handler(text, &cfg.settings).into())) | ||
}, | ||
|
||
(End(CodeBlock(Fenced(Borrowed(mark)))), Closing) if mark == &cfg.code_block => { | ||
state = None; | ||
Some(End(Paragraph)) | ||
}, | ||
_ => Some(e), | ||
} | ||
}) | ||
.flatten(); |
Check warning
Code scanning / clippy
called `map(..).flatten()` on `Iterator`
Before, we would ignore the Markdown settings from mdBook and parse the content with default settings. This meant that we did not support Markdown tables, which are an extension to regular Markdown. The result was that tables were mangled after the preprocessor had run. They looked like this:
We now use the mdBook utility function to construct the Markdown parser, thus getting consistent results. This makes tables survive the parsing.
The PR also has a commit which restores the preprocessing functionality, it was accidentally lost in the refactor in 900cd77.