1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
extern crate micromark;
use micromark::{micromark, micromark_with_options, Options};
const DANGER: &Options = &Options {
allow_dangerous_html: true,
allow_dangerous_protocol: true,
default_line_ending: None,
};
#[test]
fn line_ending() {
assert_eq!(
micromark("a\nb"),
"<p>a\nb</p>",
"should support a line feed for a line ending inside a paragraph"
);
assert_eq!(
micromark("a\rb"),
"<p>a\rb</p>",
"should support a carriage return for a line ending inside a paragraph"
);
assert_eq!(
micromark("a\r\nb"),
"<p>a\r\nb</p>",
"should support a carriage return + line feed for a line ending inside a paragraph"
);
assert_eq!(
micromark("\ta\n\tb"),
"<pre><code>a\nb\n</code></pre>",
"should support a line feed in indented code (and prefer it)"
);
assert_eq!(
micromark("\ta\r\tb"),
"<pre><code>a\rb\r</code></pre>",
"should support a carriage return in indented code (and prefer it)"
);
assert_eq!(
micromark("\ta\r\n\tb"),
"<pre><code>a\r\nb\r\n</code></pre>",
"should support a carriage return + line feed in indented code (and prefer it)"
);
assert_eq!(
micromark("***\n### Heading"),
"<hr />\n<h3>Heading</h3>",
"should support a line feed between flow"
);
assert_eq!(
micromark("***\r### Heading"),
"<hr />\r<h3>Heading</h3>",
"should support a carriage return between flow"
);
assert_eq!(
micromark("***\r\n### Heading"),
"<hr />\r\n<h3>Heading</h3>",
"should support a carriage return + line feed between flow"
);
assert_eq!(
micromark("***\n\n\n### Heading\n"),
"<hr />\n<h3>Heading</h3>\n",
"should support several line feeds between flow"
);
assert_eq!(
micromark("***\r\r\r### Heading\r"),
"<hr />\r<h3>Heading</h3>\r",
"should support several carriage returns between flow"
);
assert_eq!(
micromark("***\r\n\r\n\r\n### Heading\r\n"),
"<hr />\r\n<h3>Heading</h3>\r\n",
"should support several carriage return + line feeds between flow"
);
assert_eq!(
micromark("```x\n\n\ny\n\n\n```\n\n\n"),
"<pre><code class=\"language-x\">\n\ny\n\n\n</code></pre>\n",
"should support several line feeds in fenced code"
);
assert_eq!(
micromark("```x\r\r\ry\r\r\r```\r\r\r"),
"<pre><code class=\"language-x\">\r\ry\r\r\r</code></pre>\r",
"should support several carriage returns in fenced code"
);
assert_eq!(
micromark("```x\r\n\r\n\r\ny\r\n\r\n\r\n```\r\n\r\n\r\n"),
"<pre><code class=\"language-x\">\r\n\r\ny\r\n\r\n\r\n</code></pre>\r\n",
"should support several carriage return + line feeds in fenced code"
);
assert_eq!(
micromark("A\r\nB\r\n-\r\nC"),
"<h2>A\r\nB</h2>\r\n<p>C</p>",
"should support a carriage return + line feed in content"
);
assert_eq!(
micromark_with_options("<div\n", DANGER),
"<div\n",
"should support a line feed after html"
);
assert_eq!(
micromark_with_options("<div\r", DANGER),
"<div\r",
"should support a carriage return after html"
);
assert_eq!(
micromark_with_options("<div\r\n", DANGER),
"<div\r\n",
"should support a carriage return + line feed after html"
);
assert_eq!(
micromark_with_options("<div>\n\nx", DANGER),
"<div>\n<p>x</p>",
"should support a blank line w/ line feeds after html"
);
assert_eq!(
micromark_with_options("<div>\r\rx", DANGER),
"<div>\r<p>x</p>",
"should support a blank line w/ carriage returns after html"
);
assert_eq!(
micromark_with_options("<div>\r\n\r\nx", DANGER),
"<div>\r\n<p>x</p>",
"should support a blank line w/ carriage return + line feeds after html"
);
assert_eq!(
micromark_with_options("<div>\nx", DANGER),
"<div>\nx",
"should support a non-blank line w/ line feed in html"
);
assert_eq!(
micromark_with_options("<div>\rx", DANGER),
"<div>\rx",
"should support a non-blank line w/ carriage return in html"
);
assert_eq!(
micromark_with_options("<div>\r\nx", DANGER),
"<div>\r\nx",
"should support a non-blank line w/ carriage return + line feed in html"
);
}
|