Skip to content

Commit

Permalink
Merge pull request #1 from boozook/fmt
Browse files Browse the repository at this point in the history
fix format
  • Loading branch information
mgeisler authored Dec 2, 2022
2 parents 8b7ef99 + 7f4754b commit ad4ea92
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions src/preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,33 +91,32 @@ fn process_code_blocks(chapter: &mut Chapter, cfg: &Cfg) -> Result<String, std::
// parses our output). It is important to use new_cmark_parser so
// that we parse things like tables consistently with mdBook.
let parser = mdbook::utils::new_cmark_parser(&chapter.content, false);
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();
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();
cmark(events, &mut buf).map(|_| buf)
}

Expand Down

0 comments on commit ad4ea92

Please sign in to comment.