Markdown parser fork with extended syntax for personal use.
1use markdown::{
2 mdast::{Break, Node, Paragraph, Root, Text},
3 message, to_html, to_html_with_options, to_mdast,
4 unist::Position,
5 Constructs, Options, ParseOptions,
6};
7use pretty_assertions::assert_eq;
8
9#[test]
10fn hard_break_escape() -> Result<(), message::Message> {
11 assert_eq!(
12 to_html("foo\\\nbaz"),
13 "<p>foo<br />\nbaz</p>",
14 "should support a backslash to form a hard break"
15 );
16
17 assert_eq!(
18 to_html("foo\\\n bar"),
19 "<p>foo<br />\nbar</p>",
20 "should support leading spaces after an escape hard break"
21 );
22
23 assert_eq!(
24 to_html("*foo\\\nbar*"),
25 "<p><em>foo<br />\nbar</em></p>",
26 "should support escape hard breaks in emphasis"
27 );
28
29 assert_eq!(
30 to_html("``code\\\ntext``"),
31 "<p><code>code\\ text</code></p>",
32 "should not support escape hard breaks in code"
33 );
34
35 assert_eq!(
36 to_html("foo\\"),
37 "<p>foo\\</p>",
38 "should not support escape hard breaks at the end of a paragraph"
39 );
40
41 assert_eq!(
42 to_html("### foo\\"),
43 "<h3>foo\\</h3>",
44 "should not support escape hard breaks at the end of a heading"
45 );
46
47 assert_eq!(
48 to_html_with_options(
49 "a\\\nb",
50 &Options {
51 parse: ParseOptions {
52 constructs: Constructs {
53 hard_break_escape: false,
54 ..Constructs::default()
55 },
56 ..Default::default()
57 },
58 ..Default::default()
59 }
60 )?,
61 "<p>a\\\nb</p>",
62 "should support turning off hard break (escape)"
63 );
64
65 assert_eq!(
66 to_mdast("a\\\nb.", &Default::default())?,
67 Node::Root(Root {
68 children: vec![Node::Paragraph(Paragraph {
69 children: vec![
70 Node::Text(Text {
71 value: "a".into(),
72 position: Some(Position::new(1, 1, 0, 1, 2, 1))
73 }),
74 Node::Break(Break {
75 position: Some(Position::new(1, 2, 1, 2, 1, 3))
76 }),
77 Node::Text(Text {
78 value: "b.".into(),
79 position: Some(Position::new(2, 1, 3, 2, 3, 5))
80 }),
81 ],
82 position: Some(Position::new(1, 1, 0, 2, 3, 5))
83 })],
84 position: Some(Position::new(1, 1, 0, 2, 3, 5))
85 }),
86 "should support hard break (escape) as `Break`s in mdast"
87 );
88
89 Ok(())
90}