Enable markdown extensions for markdown filter

Closes #417
This commit is contained in:
Vincent Prouillet 2018-09-10 17:22:35 +02:00
parent b4158921dd
commit c2b76d1850
2 changed files with 21 additions and 1 deletions

View file

@ -7,6 +7,7 @@
- Load only .html files in themes from the templates folder - Load only .html files in themes from the templates folder
- Background colour is set fewer times when highlighting syntaxes - Background colour is set fewer times when highlighting syntaxes
- Link checker will not try to validate email links anymore - 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) ## 0.4.2 (2018-09-03)

View file

@ -12,8 +12,12 @@ pub fn markdown(value: Value, args: HashMap<String, Value>) -> TeraResult<Value>
None => false, 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 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); cmark::html::push_html(&mut html, parser);
if inline { if inline {
@ -71,6 +75,21 @@ mod tests {
assert_eq!(result.unwrap(), to_value(&"Using <code>map</code>, <code>filter</code>, and <code>fold</code> instead of <code>for</code>").unwrap()); assert_eq!(result.unwrap(), to_value(&"Using <code>map</code>, <code>filter</code>, and <code>fold</code> instead of <code>for</code>").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("<table>"));
}
#[test] #[test]
fn base64_encode_filter() { fn base64_encode_filter() {
// from https://tools.ietf.org/html/rfc4648#section-10 // from https://tools.ietf.org/html/rfc4648#section-10