fn run(input: &str, output: &str) { let output = if output.is_empty() { "".to_owned() } else { output.to_owned() + "\n" }; let md = &mut markdown_it::MarkdownIt::new(); markdown_it::plugins::cmark::add(md); markdown_it::plugins::html::add(md); markdown_it::plugins::extra::linkify::add(md); markdown_it::plugins::extra::typographer::add(md); let node = md.parse(&(input.to_owned() + "\n")); // make sure we have sourcemaps for everything node.walk(|node, _| assert!(node.srcmap.is_some())); let result = node.render(); assert_eq!(result, output); // make sure it doesn't crash without trailing \n let _ = md.parse(input.trim_end()); } /////////////////////////////////////////////////////////////////////////// // TESTGEN: fixtures/markdown-it/typographer-extra.txt #[rustfmt::skip] mod fixtures_markdown_it_typographer_extra_txt { use super::run; // this part of the file is auto-generated // don't edit it, otherwise your changes might be lost #[test] fn don_t_touch_text_in_autolinks() { let input = r#"URL with (C) (c) (R) (r) (TM) (tm): https://example.com/(c)(r)(tm)/(C)(R)(TM) what do you think?"#; let output = r#"
URL with © © ® ® ™ ™: https://example.com/(c)(r)(tm)/(C)(R)(TM) what do you think?
"#; run(input, output); } #[test] fn replacements_for_tm_should_allow_mixed_case_tm_and_tm() { let input = r#"These two should both end up the same as (TM) and (tm): (tM), (Tm)."#; let output = r#"These two should both end up the same as ™ and ™: ™, ™.
"#; run(input, output); } // end of auto-generated module } /////////////////////////////////////////////////////////////////////////// // TESTGEN: fixtures/markdown-it/typographer.txt #[rustfmt::skip] mod fixtures_markdown_it_typographer_txt { use super::run; // this part of the file is auto-generated // don't edit it, otherwise your changes might be lost #[test] fn unnamed() { let input = r#"(bad)"#; let output = r#"(bad)
"#; run(input, output); } #[test] fn copyright() { let input = r#"(c) (C)"#; let output = r#"© ©
"#; run(input, output); } #[test] fn reserved() { let input = r#"(r) (R)"#; let output = r#"® ®
"#; run(input, output); } #[test] fn trademark() { let input = r#"(tm) (TM)"#; let output = r#"™ ™
"#; run(input, output); } #[test] fn plus_minus() { let input = r#"+-5"#; let output = r#"±5
"#; run(input, output); } #[test] fn ellipsis() { let input = r#"test.. test... test..... test?..... test!...."#; let output = r#"test… test… test… test?.. test!..
"#; run(input, output); } #[test] fn dupes() { let input = r#"!!!!!! ???? ,,"#; let output = r#"!!! ??? ,
"#; run(input, output); } #[test] fn copyright_should_be_escapable() { let input = r#"\(c)"#; let output = r#"(c)
"#; run(input, output); } #[test] fn shouldn_t_replace_entities() { let input = r#"(c) (c) (c)"#; let output = r#"(c) (c) ©
"#; run(input, output); } #[test] fn dashes() { let input = r#"---markdownit --- super--- markdownit---awesome abc ---- --markdownit -- super-- markdownit--awesome"#; let output = r#"—markdownit — super—
markdownit—awesome
abc ----
–markdownit – super–
markdownit–awesome
"#; run(input, output); } #[test] fn dashes_should_be_escapable() { let input = r#"foo \-- bar foo -\- bar"#; let output = r#"foo -- bar
foo -- bar
"#; run(input, output); } #[test] fn regression_tests_for_624() { let input = r#"1---2---3 1--2--3 1 -- -- 3"#; let output = r#"1—2—3
1–2–3
1 – – 3
"#; run(input, output); } // end of auto-generated module }