auto format
This commit is contained in:
parent
01f997792e
commit
3979de2d32
|
@ -18,7 +18,8 @@ pub fn make_app() -> App<'static, 'static> {
|
|||
.subcommand(
|
||||
SubCommand::with_name("supports")
|
||||
.arg(Arg::with_name("renderer").required(true))
|
||||
.about("Check whether a renderer is supported by this preprocessor"))
|
||||
.about("Check whether a renderer is supported by this preprocessor"),
|
||||
)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
15
src/lib.rs
15
src/lib.rs
|
@ -2,13 +2,13 @@ extern crate mdbook;
|
|||
extern crate pulldown_cmark;
|
||||
extern crate pulldown_cmark_to_cmark;
|
||||
|
||||
use mdbook::errors::{Error, Result};
|
||||
use mdbook::book::{Book, BookItem, Chapter};
|
||||
use mdbook::errors::{Error, Result};
|
||||
use mdbook::preprocess::{Preprocessor, PreprocessorContext};
|
||||
use pulldown_cmark::{Event, Parser};
|
||||
use pulldown_cmark::Tag::*;
|
||||
use pulldown_cmark_to_cmark::fmt::cmark;
|
||||
use pulldown_cmark::CowStr;
|
||||
use pulldown_cmark::Tag::*;
|
||||
use pulldown_cmark::{Event, Parser};
|
||||
use pulldown_cmark_to_cmark::fmt::cmark;
|
||||
|
||||
pub struct Toc;
|
||||
|
||||
|
@ -88,21 +88,22 @@ fn add_toc(content: &str) -> Result<String> {
|
|||
let toc_events = build_toc(&toc_content);
|
||||
let toc_events = Parser::new(&toc_events).collect::<Vec<_>>();
|
||||
|
||||
let events = Parser::new(&content).map(|e| {
|
||||
let events = Parser::new(&content)
|
||||
.map(|e| {
|
||||
if let Event::Html(html) = e.clone() {
|
||||
if &*html == "<!-- toc -->\n" {
|
||||
return toc_events.clone();
|
||||
}
|
||||
}
|
||||
vec![e]
|
||||
}).flat_map(|e| e);
|
||||
})
|
||||
.flat_map(|e| e);
|
||||
|
||||
cmark(events, &mut buf, None)
|
||||
.map(|_| buf)
|
||||
.map_err(|err| Error::from(format!("Markdown serialization failed: {}", err)))
|
||||
}
|
||||
|
||||
|
||||
impl Toc {
|
||||
fn add_toc(chapter: &mut Chapter) -> Result<String> {
|
||||
add_toc(&chapter.content)
|
||||
|
|
Loading…
Reference in a new issue