diff --git a/src/lib.rs b/src/lib.rs index 2217399..6701114 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,7 +26,7 @@ mod site; mod markdown; mod section; -pub use site::Site; +pub use site::{Site, GUTENBERG_TERA}; pub use config::{Config, get_config}; pub use front_matter::{FrontMatter, split_content}; pub use page::{Page, populate_previous_and_next_pages}; diff --git a/src/markdown.rs b/src/markdown.rs index 5e49acd..c11e470 100644 --- a/src/markdown.rs +++ b/src/markdown.rs @@ -236,7 +236,7 @@ pub fn markdown_to_html(content: &str, permalinks: &HashMap, ter match error { Some(e) => Err(e), - None => Ok(html), + None => Ok(html.replace("

", "")), } } @@ -245,18 +245,12 @@ pub fn markdown_to_html(content: &str, permalinks: &HashMap, ter mod tests { use std::collections::HashMap; + use site::GUTENBERG_TERA; use tera::Tera; use config::Config; use super::{markdown_to_html, parse_shortcode}; - fn create_test_tera() -> Tera { - let mut tera = Tera::default(); - tera.add_raw_template("shortcodes/youtube.html", "Youtube video: {{id}}").unwrap(); - tera.add_raw_template("shortcodes/quote.html", "Quote: {{body}} - {{author}}").unwrap(); - tera - } - #[test] fn test_parse_simple_shortcode_one_arg() { let (name, args) = parse_shortcode(r#"{{ youtube(id="w7Ft2ymGmfc") }}"#); @@ -326,28 +320,53 @@ mod tests { } #[test] - fn test_markdown_to_html_simple_shortcode() { + fn test_markdown_to_html_with_shortcode() { let res = markdown_to_html(r#" Hello -{{ youtube(id="w7Ft2ymGmfc") }} - "#, &HashMap::new(), &create_test_tera(), &Config::default()).unwrap(); - assert_eq!(res, "

Hello\n

Youtube video: w7Ft2ymGmfc"); + +{{ youtube(id="ub36ffWAqgQ") }} + "#, &HashMap::new(), &GUTENBERG_TERA, &Config::default()).unwrap(); + assert!(res.contains("

Hello

\n
")); + assert!(res.contains(r#" +
diff --git a/src/templates/shortcodes/youtube.html b/src/templates/shortcodes/youtube.html new file mode 100644 index 0000000..5f10206 --- /dev/null +++ b/src/templates/shortcodes/youtube.html @@ -0,0 +1,4 @@ +
+ +
diff --git a/test_site/content/posts/simple.md b/test_site/content/posts/simple.md index 53ce0ad..ee8367f 100644 --- a/test_site/content/posts/simple.md +++ b/test_site/content/posts/simple.md @@ -5,3 +5,10 @@ date = "2017-04-01" +++ A simple page + +{{ youtube(id="e1C9kpMV2e8") }} +{{ youtube(id="e1C9kpMV2e8", autoplay=true) }} + +{{ vimeo(id="210073083") }} + +{{ gist(url="https://gist.github.com/Keats/32d26f699dcc13ebd41b") }}