Browse Source

Enable markdown extensions for markdown filter

Closes #417
index-subcmd
Vincent Prouillet 5 years ago
parent
commit
c2b76d1850
2 changed files with 21 additions and 1 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +20
    -1
      components/templates/src/filters.rs

+ 1
- 0
CHANGELOG.md View File

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



+ 20
- 1
components/templates/src/filters.rs View File

@@ -12,8 +12,12 @@ pub fn markdown(value: Value, args: HashMap<String, Value>) -> TeraResult<Value>
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 <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]
fn base64_encode_filter() {
// from https://tools.ietf.org/html/rfc4648#section-10


Loading…
Cancel
Save