1fn run(input: &str, output: &str) {
2 let output = if output.is_empty() {
3 "".to_owned()
4 } else {
5 output.to_owned() + "\n"
6 };
7 let md = &mut markdown_it::MarkdownIt::new();
8 markdown_it::plugins::cmark::add(md);
9 markdown_it::plugins::html::add(md);
10 markdown_it::plugins::extra::linkify::add(md);
11 markdown_it::plugins::extra::typographer::add(md);
12 let node = md.parse(&(input.to_owned() + "\n"));
13
14 // make sure we have sourcemaps for everything
15 node.walk(|node, _| assert!(node.srcmap.is_some()));
16
17 let result = node.render();
18 assert_eq!(result, output);
19
20 // make sure it doesn't crash without trailing \n
21 let _ = md.parse(input.trim_end());
22}
23///////////////////////////////////////////////////////////////////////////
24// TESTGEN: fixtures/markdown-it/typographer-extra.txt
25#[rustfmt::skip]
26mod fixtures_markdown_it_typographer_extra_txt {
27use super::run;
28// this part of the file is auto-generated
29// don't edit it, otherwise your changes might be lost
30#[test]
31fn don_t_touch_text_in_autolinks() {
32 let input = r#"URL with (C) (c) (R) (r) (TM) (tm): https://example.com/(c)(r)(tm)/(C)(R)(TM) what do you think?"#;
33 let output = r#"<p>URL with © © ® ® ™ ™: <a href="https://example.com/(c)(r)(tm)/(C)(R)(TM)">https://example.com/(c)(r)(tm)/(C)(R)(TM)</a> what do you think?</p>"#;
34 run(input, output);
35}
36
37#[test]
38fn replacements_for_tm_should_allow_mixed_case_tm_and_tm() {
39 let input = r#"These two should both end up the same as (TM) and (tm): (tM), (Tm)."#;
40 let output = r#"<p>These two should both end up the same as ™ and ™: ™, ™.</p>"#;
41 run(input, output);
42}
43// end of auto-generated module
44}
45///////////////////////////////////////////////////////////////////////////
46// TESTGEN: fixtures/markdown-it/typographer.txt
47#[rustfmt::skip]
48mod fixtures_markdown_it_typographer_txt {
49use super::run;
50// this part of the file is auto-generated
51// don't edit it, otherwise your changes might be lost
52#[test]
53fn unnamed() {
54 let input = r#"(bad)"#;
55 let output = r#"<p>(bad)</p>"#;
56 run(input, output);
57}
58
59#[test]
60fn copyright() {
61 let input = r#"(c) (C)"#;
62 let output = r#"<p>© ©</p>"#;
63 run(input, output);
64}
65
66#[test]
67fn reserved() {
68 let input = r#"(r) (R)"#;
69 let output = r#"<p>® ®</p>"#;
70 run(input, output);
71}
72
73#[test]
74fn trademark() {
75 let input = r#"(tm) (TM)"#;
76 let output = r#"<p>™ ™</p>"#;
77 run(input, output);
78}
79
80#[test]
81fn plus_minus() {
82 let input = r#"+-5"#;
83 let output = r#"<p>±5</p>"#;
84 run(input, output);
85}
86
87#[test]
88fn ellipsis() {
89 let input = r#"test.. test... test..... test?..... test!...."#;
90 let output = r#"<p>test… test… test… test?.. test!..</p>"#;
91 run(input, output);
92}
93
94#[test]
95fn dupes() {
96 let input = r#"!!!!!! ???? ,,"#;
97 let output = r#"<p>!!! ??? ,</p>"#;
98 run(input, output);
99}
100
101#[test]
102fn copyright_should_be_escapable() {
103 let input = r#"\(c)"#;
104 let output = r#"<p>(c)</p>"#;
105 run(input, output);
106}
107
108#[test]
109fn shouldn_t_replace_entities() {
110 let input = r#"&#40;c) (c&#41; (c)"#;
111 let output = r#"<p>(c) (c) ©</p>"#;
112 run(input, output);
113}
114
115#[test]
116fn dashes() {
117 let input = r#"---markdownit --- super---
118
119markdownit---awesome
120
121abc ----
122
123--markdownit -- super--
124
125markdownit--awesome"#;
126 let output = r#"<p>—markdownit — super—</p>
127<p>markdownit—awesome</p>
128<p>abc ----</p>
129<p>–markdownit – super–</p>
130<p>markdownit–awesome</p>"#;
131 run(input, output);
132}
133
134#[test]
135fn dashes_should_be_escapable() {
136 let input = r#"foo \-- bar
137
138foo -\- bar"#;
139 let output = r#"<p>foo -- bar</p>
140<p>foo -- bar</p>"#;
141 run(input, output);
142}
143
144#[test]
145fn regression_tests_for_624() {
146 let input = r#"1---2---3
147
1481--2--3
149
1501 -- -- 3"#;
151 let output = r#"<p>1—2—3</p>
152<p>1–2–3</p>
153<p>1 – – 3</p>"#;
154 run(input, output);
155}
156// end of auto-generated module
157}