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::typographer::add(md); markdown_it::plugins::extra::tables::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/tables.txt #[rustfmt::skip] mod fixtures_markdown_it_tables_txt { use super::run; // this part of the file is auto-generated // don't edit it, otherwise your changes might be lost #[test] fn simple() { let input = r#"| Heading 1 | Heading 2 | --------- | --------- | Cell 1 | Cell 2 | Cell 3 | Cell 4"#; let output = r#"
Heading 1 Heading 2
Cell 1 Cell 2
Cell 3 Cell 4
"#; run(input, output); } #[test] fn column_alignment() { let input = r#"| Header 1 | Header 2 | Header 3 | Header 4 | | :------: | -------: | :------- | -------- | | Cell 1 | Cell 2 | Cell 3 | Cell 4 | | Cell 5 | Cell 6 | Cell 7 | Cell 8 |"#; let output = r#"
Header 1 Header 2 Header 3 Header 4
Cell 1 Cell 2 Cell 3 Cell 4
Cell 5 Cell 6 Cell 7 Cell 8
"#; run(input, output); } #[test] fn nested_emphases() { let input = r#"Header 1|Header 2|Header 3|Header 4 :-------|:------:|-------:|-------- Cell 1 |Cell 2 |Cell 3 |Cell 4 *Cell 5*|Cell 6 |Cell 7 |Cell 8"#; let output = r#"
Header 1 Header 2 Header 3 Header 4
Cell 1 Cell 2 Cell 3 Cell 4
Cell 5 Cell 6 Cell 7 Cell 8
"#; run(input, output); } #[test] fn nested_tables_inside_blockquotes() { let input = r#"> foo|foo > ---|--- > bar|bar baz|baz"#; let output = r#"
foo foo
bar bar

baz|baz

"#; run(input, output); } #[test] fn minimal_one_column() { let input = r#"| foo |---- | test2"#; let output = r#"
foo
test2
"#; run(input, output); } #[test] fn this_is_parsed_as_one_big_table() { let input = r#"- foo|foo ---|--- bar|bar"#; let output = r#"
- foo foo
bar bar
"#; run(input, output); } #[test] fn second_line_should_not_contain_symbols_except_and() { let input = r#"foo|foo -----|-----s bar|bar"#; let output = r#"

foo|foo -----|-----s bar|bar

"#; run(input, output); } #[test] fn second_line_should_contain_symbol() { let input = r#"foo|foo -----:----- bar|bar"#; let output = r#"

foo|foo -----:----- bar|bar

"#; run(input, output); } #[test] fn second_line_should_not_have_empty_columns_in_the_middle() { let input = r#"foo|foo -----||----- bar|bar"#; let output = r#"

foo|foo -----||----- bar|bar

"#; run(input, output); } #[test] fn wrong_alignment_symbol_position() { let input = r#"foo|foo -----|-::- bar|bar"#; let output = r#"

foo|foo -----|-::- bar|bar

"#; run(input, output); } #[test] fn title_line_should_contain_symbol() { let input = r#"foo -----|----- bar|bar"#; let output = r#"

foo -----|----- bar|bar

"#; run(input, output); } #[test] fn allow_tabs_as_a_separator_on_2nd_line() { let input = "|\tfoo\t|\tbar\t| |\t---\t|\t---\t| |\tbaz\t|\tquux\t|"; let output = r#"
foo bar
baz quux
"#; run(input, output); } #[test] fn should_terminate_paragraph() { let input = r#"paragraph foo|foo ---|--- bar|bar"#; let output = r#"

paragraph

foo foo
bar bar
"#; run(input, output); } #[test] fn another_complicated_backticks_case() { let input = r#"| Heading 1 | Heading 2 | --------- | --------- | Cell 1 | Cell 2 | \\\`|\\\`"#; let output = r#"
Heading 1 Heading 2
Cell 1 Cell 2
\` \`
"#; run(input, output); } #[test] fn in_tables_should_not_count_as_escaped_backtick() { let input = r#"# | 1 | 2 --|--|-- x | `\` | `x`"#; let output = r#"
# 1 2
x \ x
"#; run(input, output); } #[test] fn tables_should_handle_escaped_backticks() { let input = r#"# | 1 | 2 --|--|-- x | \`\` | `x`"#; let output = r#"
# 1 2
x `` x
"#; run(input, output); } #[test] fn an_amount_of_rows_might_be_different_across_the_table_issue_171() { let input = r#"| 1 | 2 | | :-----: | :-----: | | 3 | 4 | 5 | 6 |"#; let output = r#"
1 2
3 4
"#; run(input, output); } #[test] fn an_amount_of_rows_might_be_different_across_the_table_2() { let input = r#"| 1 | 2 | 3 | 4 | | :-----: | :-----: | :-----: | :-----: | | 5 | 6 |"#; let output = r#"
1 2 3 4
5 6
"#; run(input, output); } #[test] fn allow_one_column_tables_issue_171() { let input = r#"| foo | :-----: | bar |"#; let output = r#"
foo
bar
"#; run(input, output); } #[test] fn allow_indented_tables_issue_325() { let input = r#" | Col1a | Col2a | | ----- | ----- | | Col1b | Col2b |"#; let output = r#"
Col1a Col2a
Col1b Col2b
"#; run(input, output); } #[test] fn tables_should_not_be_indented_more_than_4_spaces_1st_line() { let input = r#" | Col1a | Col2a | | ----- | ----- | | Col1b | Col2b |"#; let output = r#"
| Col1a | Col2a |

| ----- | ----- | | Col1b | Col2b |

"#; run(input, output); } #[test] fn tables_should_not_be_indented_more_than_4_spaces_2nd_line() { let input = r#" | Col1a | Col2a | | ----- | ----- | | Col1b | Col2b |"#; let output = r#"

| Col1a | Col2a | | ----- | ----- | | Col1b | Col2b |

"#; run(input, output); } #[test] fn tables_should_not_be_indented_more_than_4_spaces_3rd_line() { let input = r#" | Col1a | Col2a | | ----- | ----- | | Col1b | Col2b |"#; let output = r#"
Col1a Col2a
| Col1b | Col2b |
"#; run(input, output); } #[test] fn allow_tables_with_empty_body() { let input = r#" | Col1a | Col2a | | ----- | ----- |"#; let output = r#"
Col1a Col2a
"#; run(input, output); } #[test] fn align_row_should_be_at_least_as_large_as_any_actual_rows() { let input = r#"Col1a | Col1b | Col1c ----- | ----- Col2a | Col2b | Col2c"#; let output = r#"

Col1a | Col1b | Col1c ----- | ----- Col2a | Col2b | Col2c

"#; run(input, output); } #[test] fn escaped_pipes_inside_backticks_don_t_split_cells() { let input = r#"| Heading 1 | Heading 2 | --------- | --------- | Cell 1 | Cell 2 | `Cell 3\|` | Cell 4"#; let output = r#"
Heading 1 Heading 2
Cell 1 Cell 2
Cell 3| Cell 4
"#; run(input, output); } #[test] fn escape_before_escaped_pipes_inside_backticks_don_t_split_cells() { let input = r#"| Heading 1 | Heading 2 | --------- | --------- | Cell 1 | Cell 2 | `Cell 3\\|` | Cell 4"#; let output = r#"
Heading 1 Heading 2
Cell 1 Cell 2
Cell 3\| Cell 4
"#; run(input, output); } #[test] fn regression_test_for_721_table_in_a_list_indented_with_tabs() { let input = "- Level 1 \t- Level 2 \t\t| Column 1 | Column 2 | \t\t| -------- | -------- | \t\t| abcdefgh | ijklmnop |"; let output = r#""#; run(input, output); } #[test] fn table_without_any_columns_is_not_a_table_724() { let input = r#"| | |"#; let output = r#"

| | |

"#; run(input, output); } #[test] fn gfm_4_10_tables_extension_example_198() { let input = r#"| foo | bar | | --- | --- | | baz | bim |"#; let output = r#"
foo bar
baz bim
"#; run(input, output); } #[test] fn gfm_4_10_tables_extension_example_199() { let input = r#"| abc | defghi | :-: | -----------: bar | baz"#; let output = r#"
abc defghi
bar baz
"#; run(input, output); } #[test] fn gfm_4_10_tables_extension_example_200() { let input = r#"| f\|oo | | ------ | | b `\|` az | | b **\|** im |"#; let output = r#"
f|oo
b | az
b | im
"#; run(input, output); } #[test] fn gfm_4_10_tables_extension_example_201() { let input = r#"| abc | def | | --- | --- | | bar | baz | > bar"#; let output = r#"
abc def
bar baz

bar

"#; run(input, output); } #[test] fn gfm_4_10_tables_extension_example_202() { let input = r#"| abc | def | | --- | --- | | bar | baz | bar bar"#; let output = r#"
abc def
bar baz
bar

bar

"#; run(input, output); } #[test] fn gfm_4_10_tables_extension_example_203() { let input = r#"| abc | def | | --- | | bar |"#; let output = r#"

| abc | def | | — | | bar |

"#; run(input, output); } #[test] fn gfm_4_10_tables_extension_example_204() { let input = r#"| abc | def | | --- | --- | | bar | | bar | baz | boo |"#; let output = r#"
abc def
bar
bar baz
"#; run(input, output); } #[test] fn gfm_4_10_tables_extension_example_205() { let input = r#"| abc | def | | --- | --- |"#; let output = r#"
abc def
"#; run(input, output); } #[test] fn a_list_takes_precedence_in_case_of_ambiguity() { let input = r#"a | b - | - 1 | 2"#; let output = r#"

a | b

"#; run(input, output); } // end of auto-generated module } /////////////////////////////////////////////////////////////////////////// // TESTGEN: fixtures/markdown-it/markdown-it-rs.txt #[rustfmt::skip] mod fixtures_markdown_it_markdown_it_rs_txt { use super::run; // this part of the file is auto-generated // don't edit it, otherwise your changes might be lost #[test] fn regression_test_for_panic_in_40() { let input = r#"![hello'"`world](x)\"#; let output = r#"

hello'"`world\

"#; run(input, output); } // end of auto-generated module }