wayver's git archive


an obsidian renderer
git clone https://git.wayver.dev/sable

sable-markdown/src/parser/blocks/tests/html_block.rs@main

raw
Date Commit Message Author Files + -
2026-02-23 01:55 initial mvp wayverd 139 17808 0
...

1use crate::{ast::*, parser::parse_markdown};
2
3#[test]
4fn html_block1() {
5    let doc = parse_markdown("<script>\n</script>").unwrap();
6    assert_eq!(
7        doc,
8        Document {
9            blocks: vec![Block::HtmlBlock("<script>\n</script>".to_owned())]
10        }
11    );
12
13    let doc = parse_markdown("<script>\n\n<h1>hello</h1></script>").unwrap();
14    assert_eq!(
15        doc,
16        Document {
17            blocks: vec![Block::HtmlBlock(
18                "<script>\n\n<h1>hello</h1></script>".to_owned()
19            )]
20        }
21    );
22}
23
24#[test]
25fn html_block2() {
26    let doc = parse_markdown("<!-- \n\nsome commented\n out code -->").unwrap();
27    assert_eq!(
28        doc,
29        Document {
30            blocks: vec![Block::HtmlBlock(
31                "<!-- \n\nsome commented\n out code -->".to_owned()
32            )]
33        }
34    );
35}
36
37#[test]
38fn html_block3() {
39    let doc = parse_markdown("  <? \n\nsome \n   code ?>  ").unwrap();
40    assert_eq!(
41        doc,
42        Document {
43            blocks: vec![Block::HtmlBlock("<? \n\nsome \n   code ?>".to_owned())]
44        }
45    );
46}
47
48#[test]
49fn html_block4() {
50    let doc = parse_markdown("  <!A some \n\n\n text >  ").unwrap();
51    assert_eq!(
52        doc,
53        Document {
54            blocks: vec![Block::HtmlBlock("<!A some \n\n\n text >".to_owned())]
55        }
56    );
57}
58
59#[test]
60fn html_block5() {
61    let doc = parse_markdown("  <![CDATA[ ]\n\n[[]]<> ]]> ").unwrap();
62    assert_eq!(
63        doc,
64        Document {
65            blocks: vec![Block::HtmlBlock("<![CDATA[ ]\n\n[[]]<> ]]>".to_owned())]
66        }
67    );
68}
69
70#[test]
71fn html_block6() {
72    let doc = parse_markdown("  <body  \n\n").unwrap();
73    assert_eq!(
74        doc,
75        Document {
76            blocks: vec![Block::HtmlBlock("<body  \n".to_owned())]
77        }
78    );
79
80    let doc = parse_markdown("  <body a b=c d='e' f=\"g\" >\n</body>\n\n").unwrap();
81    assert_eq!(
82        doc,
83        Document {
84            blocks: vec![Block::HtmlBlock(
85                "<body a b=c d='e' f=\"g\" >\n</body>\n".to_owned()
86            )]
87        }
88    );
89
90    let doc = parse_markdown("  </body> <p>\n</p>\n\n").unwrap();
91    assert_eq!(
92        doc,
93        Document {
94            blocks: vec![Block::HtmlBlock("</body> <p>\n</p>\n".to_owned())]
95        }
96    );
97}
98
99// #[test]
100// fn html_block_skip1() {
101//     let config = crate::parser::config::MarkdownParserConfig::default()
102//         .with_block_html_block_behavior(crate::parser::config::ElementBehavior::Skip);
103//     let doc = parse_markdown(
104//         MarkdownParserState::with_config(config.clone()),
105//         "<script>\n</script>",
106//     )
107//     .unwrap();
108//     assert_eq!(
109//         doc,
110//         Document {
111//             blocks: vec![Block::Empty]
112//         }
113//     );
114
115//     let doc = parse_markdown(
116//         MarkdownParserState::with_config(config),
117//         "<script>\n\n<h1>hello</h1></script>",
118//     )
119//     .unwrap();
120//     assert_eq!(
121//         doc,
122//         Document {
123//             blocks: vec![Block::Empty]
124//         }
125//     );
126// }
127
128// #[test]
129// fn html_block_ignore1() {
130//     let config = crate::parser::config::MarkdownParserConfig::default()
131//         .with_block_html_block_behavior(crate::parser::config::ElementBehavior::Ignore);
132//     let doc = parse_markdown(
133//         MarkdownParserState::with_config(config.clone()),
134//         "<script>\n</script>",
135//     )
136//     .unwrap();
137//     assert_eq!(
138//         doc,
139//         Document {
140//             blocks: vec![Block::Paragraph(vec![Inline::Text(
141//                 "<script>\n</script>".to_owned()
142//             )])]
143//         }
144//     );
145
146//     let doc = parse_markdown(
147//         MarkdownParserState::with_config(config),
148//         "<script>\n\n<h1>hello</h1></script>",
149//     )
150//     .unwrap();
151//     assert_eq!(
152//         doc,
153//         Document {
154//             blocks: vec![
155//                 Block::Paragraph(vec![Inline::Text("<script>".to_owned())]),
156//                 Block::Paragraph(vec![Inline::Text("<h1>hello</h1></script>".to_owned())])
157//             ]
158//         }
159//     );
160// }
161