diff --git a/CHANGELOG.md b/CHANGELOG.md index b950bce..05f5a74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Load only .html files in themes from the templates folder - Background colour is set fewer times when highlighting syntaxes - Link checker will not try to validate email links anymore +- Load table and footnote markdown extensions in `markdown` filter ## 0.4.2 (2018-09-03) diff --git a/components/templates/src/filters.rs b/components/templates/src/filters.rs index f1536a8..956f1fb 100644 --- a/components/templates/src/filters.rs +++ b/components/templates/src/filters.rs @@ -12,8 +12,12 @@ pub fn markdown(value: Value, args: HashMap) -> TeraResult None => false, }; + let mut opts = cmark::Options::empty(); + opts.insert(cmark::OPTION_ENABLE_TABLES); + opts.insert(cmark::OPTION_ENABLE_FOOTNOTES); + let mut html = String::new(); - let parser = cmark::Parser::new(&s); + let parser = cmark::Parser::new_ext(&s, opts); cmark::html::push_html(&mut html, parser); if inline { @@ -71,6 +75,21 @@ mod tests { assert_eq!(result.unwrap(), to_value(&"Using map, filter, and fold instead of for").unwrap()); } + // https://github.com/Keats/gutenberg/issues/417 + #[test] + fn markdown_filter_inline_tables() { + let mut args = HashMap::new(); + args.insert("inline".to_string(), to_value(true).unwrap()); + let result = markdown(to_value(&r#" +|id|author_id| timestamp_created|title |content | +|-:|--------:|-----------------------:|:---------------------|:-----------------| +| 1| 1|2018-09-05 08:03:43.141Z|How to train your ORM |Badly written blog| +| 2| 1|2018-08-22 13:11:50.050Z|How to bake a nice pie|Badly written blog| + "#).unwrap(), args); + assert!(result.is_ok()); + assert!(result.unwrap().as_str().unwrap().contains("")); + } + #[test] fn base64_encode_filter() { // from https://tools.ietf.org/html/rfc4648#section-10