diff --git a/src/renderer/html_handlebars/search.rs b/src/renderer/html_handlebars/search.rs index bce0844a28..46327bda40 100644 --- a/src/renderer/html_handlebars/search.rs +++ b/src/renderer/html_handlebars/search.rs @@ -81,10 +81,7 @@ fn render_item( .chain_err(|| "Could not convert HTML path to str")?; let anchor_base = utils::fs::normalize_path(filepath); - let mut opts = Options::empty(); - opts.insert(Options::ENABLE_TABLES); - opts.insert(Options::ENABLE_FOOTNOTES); - let p = Parser::new_ext(&chapter.content, opts); + let p = utils::new_cmark_parser(&chapter.content); let mut in_header = false; let max_section_depth = i32::from(search_config.heading_split_level); diff --git a/src/utils/mod.rs b/src/utils/mod.rs index ace2858998..0f199fb729 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -111,14 +111,18 @@ pub fn render_markdown(text: &str, curly_quotes: bool) -> String { render_markdown_with_base(text, curly_quotes, "") } -pub fn render_markdown_with_base(text: &str, curly_quotes: bool, base: &str) -> String { - let mut s = String::with_capacity(text.len() * 3 / 2); - +pub fn new_cmark_parser(text: &str) -> Parser<'_> { let mut opts = Options::empty(); opts.insert(Options::ENABLE_TABLES); opts.insert(Options::ENABLE_FOOTNOTES); + opts.insert(Options::ENABLE_STRIKETHROUGH); + opts.insert(Options::ENABLE_TASKLISTS); + Parser::new_ext(text, opts) +} - let p = Parser::new_ext(text, opts); +pub fn render_markdown_with_base(text: &str, curly_quotes: bool, base: &str) -> String { + let mut s = String::with_capacity(text.len() * 3 / 2); + let p = new_cmark_parser(text); let mut converter = EventQuoteConverter::new(curly_quotes); let events = p .map(clean_codeblock_headers) diff --git a/tests/dummy_book/src/SUMMARY.md b/tests/dummy_book/src/SUMMARY.md index ee2426e4a8..f14f4e21a5 100644 --- a/tests/dummy_book/src/SUMMARY.md +++ b/tests/dummy_book/src/SUMMARY.md @@ -7,6 +7,7 @@ - [Nested Chapter](first/nested.md) - [Includes](first/includes.md) - [Recursive](first/recursive.md) + - [Markdown](first/markdown.md) - [Second Chapter](second.md) - [Nested Chapter](second/nested.md) diff --git a/tests/dummy_book/src/first/markdown.md b/tests/dummy_book/src/first/markdown.md new file mode 100644 index 0000000000..d65d3d389e --- /dev/null +++ b/tests/dummy_book/src/first/markdown.md @@ -0,0 +1,29 @@ +# Markdown tests + +Tests for some markdown output. + +## Tables + +| foo | bar | +| --- | --- | +| baz | bim | + +## Footnotes + +Footnote example[^1], or with a word[^word]. + +[^1]: This is a footnote. + +[^word]: A longer footnote. + With multiple lines. + Third line. + +## Strikethrough + +~~strikethrough example~~ + +## Tasklisks + +- [X] Apples +- [X] Broccoli +- [ ] Carrots diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index dd579903ef..f293fb6dc2 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -29,8 +29,9 @@ const TOC_TOP_LEVEL: &[&str] = &[ const TOC_SECOND_LEVEL: &[&str] = &[ "1.1. Nested Chapter", "1.2. Includes", - "2.1. Nested Chapter", "1.3. Recursive", + "1.4. Markdown", + "2.1. Nested Chapter", ]; /// Make sure you can load the dummy book and build it without panicking. @@ -431,6 +432,39 @@ fn no_index_for_print_html() { assert_doesnt_contain_strings(index_html, &[r##"noindex"##]); } +#[test] +fn markdown_options() { + let temp = DummyBook::new().build().unwrap(); + let md = MDBook::load(temp.path()).unwrap(); + md.build().unwrap(); + + let path = temp.path().join("book/first/markdown.html"); + assert_contains_strings( + &path, + &[ + "