From 49793314a0c27fa761eca8432cda6bb677df7254 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Fri, 26 Jan 2018 16:07:44 +0100 Subject: [PATCH 1/2] Update benchmarks --- Cargo.lock | 14 ++-- components/site/benches/gen.py | 6 +- components/site/benches/load.rs | 122 ++++++++++++++++---------------- 3 files changed, 72 insertions(+), 70 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d5a59d5..f55efc8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -747,15 +747,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "pest" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "pest_derive" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "pest 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "pest 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1157,8 +1157,8 @@ dependencies = [ "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "humansize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "pest 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "pest_derive 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "pest 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "pest_derive 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1495,8 +1495,8 @@ dependencies = [ "checksum onig_sys 67.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e49311d8357c2173fe429cd6a592a2578ec69d59c7508efb4516634ada85bbb8" "checksum os_pipe 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7f547689aea1f11fac90333d573854a8e3e52a9160df1c42aefa8cd16734a3c0" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" -"checksum pest 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f3db16272e194d43f5cf2be1a4fa9866b3582821f410a00c094951d6b97ff6eb" -"checksum pest_derive 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9e2abeb78379aa216ce65ae83f16c44e3fee1d8c417dadddc8fae972baba9429" +"checksum pest 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e1117ca38a751edc66a4cd9ca1b35644b7d00305971306e07e0d3befbc61e906" +"checksum pest_derive 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1debf85717cb8fa6bf2aad21fbbe888fda5797aae22d332cefec9ba79b6c7a33" "checksum phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "cb325642290f28ee14d8c6201159949a872f220c62af6e110a56ea914fbe42fc" "checksum phf_codegen 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "d62594c0bb54c464f633175d502038177e90309daf2e0158be42ed5f023ce88f" "checksum phf_generator 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "6b07ffcc532ccc85e3afc45865469bf5d9e4ef5bfcf9622e3cfe80c2d275ec03" diff --git a/components/site/benches/gen.py b/components/site/benches/gen.py index cc9c4e9..c5b0420 100644 --- a/components/site/benches/gen.py +++ b/components/site/benches/gen.py @@ -14,7 +14,7 @@ CATEGORIES = ["c1", "c2", "c3", "c4"] PAGE = """ +++ title = "Hello" -date = "REPLACE_DATE" +date = REPLACE_DATE tags = REPLACE_TAG category = "REPLACE_CATEGORY" +++ @@ -105,6 +105,7 @@ title = "My site" base_url = "https://replace-this-with-your-url.com" generate_tags_pages = true generate_categories_pages = true +theme = "sample" [extra.author] name = "Vincent Prouillet" @@ -113,14 +114,15 @@ name = "Vincent Prouillet" f.write(""" title = "My site" base_url = "https://replace-this-with-your-url.com" +theme = "sample" [extra.author] name = "Vincent Prouillet" """) - # Re-use the test templates shutil.copytree("../test_site/templates", os.path.join(name, "templates")) + shutil.copytree("../test_site/themes", os.path.join(name, "themes")) def gen_section(path, num_pages, is_blog): diff --git a/components/site/benches/load.rs b/components/site/benches/load.rs index 48ec332..2d6a906 100644 --- a/components/site/benches/load.rs +++ b/components/site/benches/load.rs @@ -30,47 +30,47 @@ fn bench_loading_small_blog_with_syntax_highlighting(b: &mut test::Bencher) { b.iter(|| site.load().unwrap()); } -#[bench] -fn bench_loading_medium_blog(b: &mut test::Bencher) { - let mut path = env::current_dir().unwrap().to_path_buf(); - path.push("benches"); - path.push("medium-blog"); - let mut site = Site::new(&path, "config.toml").unwrap(); - - b.iter(|| site.load().unwrap()); -} - -#[bench] -fn bench_loading_medium_blog_with_syntax_highlighting(b: &mut test::Bencher) { - let mut path = env::current_dir().unwrap().to_path_buf(); - path.push("benches"); - path.push("medium-blog"); - let mut site = Site::new(&path, "config.toml").unwrap(); - site.config.highlight_code = Some(true); - - b.iter(|| site.load().unwrap()); -} - -#[bench] -fn bench_loading_big_blog(b: &mut test::Bencher) { - let mut path = env::current_dir().unwrap().to_path_buf(); - path.push("benches"); - path.push("big-blog"); - let mut site = Site::new(&path, "config.toml").unwrap(); - - b.iter(|| site.load().unwrap()); -} - -#[bench] -fn bench_loading_big_blog_with_syntax_highlighting(b: &mut test::Bencher) { - let mut path = env::current_dir().unwrap().to_path_buf(); - path.push("benches"); - path.push("big-blog"); - let mut site = Site::new(&path, "config.toml").unwrap(); - site.config.highlight_code = Some(true); - - b.iter(|| site.load().unwrap()); -} +//#[bench] +//fn bench_loading_medium_blog(b: &mut test::Bencher) { +// let mut path = env::current_dir().unwrap().to_path_buf(); +// path.push("benches"); +// path.push("medium-blog"); +// let mut site = Site::new(&path, "config.toml").unwrap(); +// +// b.iter(|| site.load().unwrap()); +//} +// +//#[bench] +//fn bench_loading_medium_blog_with_syntax_highlighting(b: &mut test::Bencher) { +// let mut path = env::current_dir().unwrap().to_path_buf(); +// path.push("benches"); +// path.push("medium-blog"); +// let mut site = Site::new(&path, "config.toml").unwrap(); +// site.config.highlight_code = Some(true); +// +// b.iter(|| site.load().unwrap()); +//} +// +//#[bench] +//fn bench_loading_big_blog(b: &mut test::Bencher) { +// let mut path = env::current_dir().unwrap().to_path_buf(); +// path.push("benches"); +// path.push("big-blog"); +// let mut site = Site::new(&path, "config.toml").unwrap(); +// +// b.iter(|| site.load().unwrap()); +//} +// +//#[bench] +//fn bench_loading_big_blog_with_syntax_highlighting(b: &mut test::Bencher) { +// let mut path = env::current_dir().unwrap().to_path_buf(); +// path.push("benches"); +// path.push("big-blog"); +// let mut site = Site::new(&path, "config.toml").unwrap(); +// site.config.highlight_code = Some(true); +// +// b.iter(|| site.load().unwrap()); +//} //#[bench] //fn bench_loading_huge_blog(b: &mut test::Bencher) { @@ -114,26 +114,26 @@ fn bench_loading_small_kb_with_syntax_highlighting(b: &mut test::Bencher) { b.iter(|| site.load().unwrap()); } -#[bench] -fn bench_loading_medium_kb(b: &mut test::Bencher) { - let mut path = env::current_dir().unwrap().to_path_buf(); - path.push("benches"); - path.push("medium-kb"); - let mut site = Site::new(&path, "config.toml").unwrap(); - - b.iter(|| site.load().unwrap()); -} - -#[bench] -fn bench_loading_medium_kb_with_syntax_highlighting(b: &mut test::Bencher) { - let mut path = env::current_dir().unwrap().to_path_buf(); - path.push("benches"); - path.push("medium-kb"); - let mut site = Site::new(&path, "config.toml").unwrap(); - site.config.highlight_code = Some(true); - - b.iter(|| site.load().unwrap()); -} +//#[bench] +//fn bench_loading_medium_kb(b: &mut test::Bencher) { +// let mut path = env::current_dir().unwrap().to_path_buf(); +// path.push("benches"); +// path.push("medium-kb"); +// let mut site = Site::new(&path, "config.toml").unwrap(); +// +// b.iter(|| site.load().unwrap()); +//} +// +//#[bench] +//fn bench_loading_medium_kb_with_syntax_highlighting(b: &mut test::Bencher) { +// let mut path = env::current_dir().unwrap().to_path_buf(); +// path.push("benches"); +// path.push("medium-kb"); +// let mut site = Site::new(&path, "config.toml").unwrap(); +// site.config.highlight_code = Some(true); +// +// b.iter(|| site.load().unwrap()); +//} //#[bench] //fn bench_loading_huge_kb(b: &mut test::Bencher) { From 29ce510aa3d19534e8c127fa656ffecf2db80d8c Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Fri, 26 Jan 2018 16:22:37 +0100 Subject: [PATCH 2/2] Add inline option of markdown filter Fix #197 --- CHANGELOG.md | 1 + components/templates/src/filters.rs | 23 ++++++++++++++++++- .../documentation/templates/overview.md | 7 ++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0acbf80..cd0c1c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 0.3.1 (unreleased) - Update Tera to fix regression +- Add option for inline in markdown filter ## 0.3.0 (2018-01-25) diff --git a/components/templates/src/filters.rs b/components/templates/src/filters.rs index 40f2f7c..a9a356d 100644 --- a/components/templates/src/filters.rs +++ b/components/templates/src/filters.rs @@ -5,13 +5,25 @@ use pulldown_cmark as cmark; use tera::{Value, to_value, Result as TeraResult}; -pub fn markdown(value: Value, _: HashMap) -> TeraResult { +pub fn markdown(value: Value, args: HashMap) -> TeraResult { let s = try_get_value!("markdown", "value", String, value); + let inline = match args.get("inline") { + Some(val) => try_get_value!("markdown", "inline", bool, val), + None => false, + }; let mut html = String::new(); let parser = cmark::Parser::new(&s); cmark::html::push_html(&mut html, parser); + if inline { + html = html + .trim_left_matches("

") + // pulldown_cmark finishes a paragraph with `

\n` + .trim_right_matches("

\n") + .to_string(); + } + Ok(to_value(&html).unwrap()) } @@ -50,6 +62,15 @@ mod tests { assert_eq!(result.unwrap(), to_value(&"

Hey

\n").unwrap()); } + #[test] + fn markdown_filter_inline() { + let mut args = HashMap::new(); + args.insert("inline".to_string(), to_value(true).unwrap()); + let result = markdown(to_value(&"Using `map`, `filter`, and `fold` instead of `for`").unwrap(), args); + assert!(result.is_ok()); + assert_eq!(result.unwrap(), to_value(&"Using map, filter, and fold instead of for").unwrap()); + } + #[test] fn base64_encode_filter() { // from https://tools.ietf.org/html/rfc4648#section-10 diff --git a/docs/content/documentation/templates/overview.md b/docs/content/documentation/templates/overview.md index 03f77ec..33b9c24 100644 --- a/docs/content/documentation/templates/overview.md +++ b/docs/content/documentation/templates/overview.md @@ -30,6 +30,13 @@ Gutenberg adds a few filters, in addition of the ones already present in Tera. Converts the given variable to HTML using Markdown. This doesn't apply any of the features that Gutenberg adds to Markdown: internal links, shortcodes etc won't work. +By default, the filter will wrap all text into a paragraph. To disable that, you can +pass `true` to the inline argument: + +```jinja2 +{{ some_text | markdown(inline=true) }} +``` + ### base64_encode Encode the variable to base64.