1
Fork 0

auto format

This commit is contained in:
Jan-Erik Rediger 2019-07-16 12:18:33 +02:00
parent 01f997792e
commit 3979de2d32
2 changed files with 17 additions and 15 deletions

View file

@ -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() {

View file

@ -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)