raw
1#![cfg(test)]
2use rstest::rstest;
3
4#[rstest]
5#[case("Hello, world!", "<p>Hello, world!</p>")]
6#[case("Hello, **world**!", "<p>Hello, <b>world</b>!</p>")]
7#[case("Hello, *world*!", "<p>Hello, <em>world</em>!</p>")]
8#[case("Hello, __world__!", "<p>Hello, <b>world</b>!</p>")]
9#[case("Hello, _world_!", "<p>Hello, <em>world</em>!</p>")]
10#[case("Hello, ~~world~~!", "<p>Hello, <s>world</s>!</p>")]
11#[case(
12 "1. Item 1\n2. Item 2",
13 "<ol start=\"1\"><li><p>Item 1</p></li><li><p>Item 2</p></li></ol>"
14)]
15#[case(
16 "* Item 1\n* Item 2",
17 "<ul class=\"list-kind-star\"><li><p>Item 1</p></li><li><p>Item 2</p></li></ul>"
18)]
19#[case("`code`", "<p><code>code</code></p>")]
20#[case(
22 "[Google][1]\n\n[1]: https://www.google.com 'Search engine'",
23 "<p><a href=\"https://www.google.com\" title=\"Search engine\">Google</a></p>"
24)]
25#[case(
26 "Hello[^1]\n\n[^1]: This is a footnote.",
27 "<p>Hello<a class=\"footnote-reference\" href=\"#footnote-1\">[1]</a></p><div class=\"footnote-definition\" id=\"footnote-1\"><span class=\"footnote-definition-index\">1. </span><span class=\"footnote-definition-content\"><p>This is a footnote.</p></span></div>"
28)]
29#[case(
30 "",
31 "<p><img src=\"https://example.com/image.png\" alt=\"alt text\"></img></p>"
32)]
33#[case(
34 "| Header 1 | Header 2 |
35| --- | --: |
36| Row 1 Col 1 | Row 1 Col 2 |
37| Row 2 Col 1 | Col 2 |",
38 "<table><thead><tr><th class=\"table-align-left\">Header 1</th><th class=\"table-align-right\">Header 2</th></tr></thead><tbody><tr><td class=\"table-align-left\">Row 1 Col 1</td><td class=\"table-align-right\">Row 1 Col 2</td></tr><tr><td class=\"table-align-left\">Row 2 Col 1</td><td class=\"table-align-right\">Col 2</td></tr></tbody></table>"
39)]
40fn render_to_html(#[case] input: &str, #[case] expected: &str) {
41 let config = crate::render::Config::default();
42 let ast = crate::parser::parse_markdown(input).unwrap();
43 println!("{input:?} => {ast:#?}");
44 let result = crate::render::render_html(&ast, &config);
45 assert_eq!(expected, result);
46}
47