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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
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 character_reference() {
assert_eq!(
micromark(
" & © Æ Ď\n¾ ℋ ⅆ\n∲ ≧̸"
),
"<p> & © Æ Ď\n¾ ℋ ⅆ\n∲ ≧̸</p>",
"should support named character references"
);
assert_eq!(
micromark("# Ӓ Ϡ �"),
"<p># Ӓ Ϡ �</p>",
"should support decimal character references"
);
assert_eq!(
micromark("" ആ ಫ"),
"<p>" ആ ಫ</p>",
"should support hexadecimal character references"
);
assert_eq!(
micromark(
"  &x; &#; &#x;\n�\n&#abcdef0;\n&ThisIsNotDefined; &hi?;"
),
"<p>&nbsp &x; &#; &#x;\n&#987654321;\n&#abcdef0;\n&ThisIsNotDefined; &hi?;</p>",
"should not support other things that look like character references"
);
assert_eq!(
micromark("©"),
"<p>&copy</p>",
"should not support character references w/o semicolon"
);
assert_eq!(
micromark("&MadeUpEntity;"),
"<p>&MadeUpEntity;</p>",
"should not support unknown named character references"
);
assert_eq!(
micromark_with_options("<a href=\"öö.html\">", DANGER),
"<a href=\"öö.html\">",
"should not care about character references in html"
);
assert_eq!(
micromark("[foo](/föö \"föö\")"),
"<p><a href=\"/f%C3%B6%C3%B6\" title=\"föö\">foo</a></p>",
"should support character references in resource URLs and titles"
);
assert_eq!(
micromark("[foo]: /föö \"föö\"\n\n[foo]"),
"<p><a href=\"/f%C3%B6%C3%B6\" title=\"föö\">foo</a></p>",
"should support character references in definition URLs and titles"
);
assert_eq!(
micromark("``` föö\nfoo\n```"),
"<pre><code class=\"language-föö\">foo\n</code></pre>",
"should support character references in code language"
);
assert_eq!(
micromark("`föö`"),
"<p><code>f&ouml;&ouml;</code></p>",
"should not support character references in text code"
);
assert_eq!(
micromark(" föfö"),
"<pre><code>f&ouml;f&ouml;\n</code></pre>",
"should not support character references in indented code"
);
// To do: attention.
// assert_eq!(
// micromark("*foo*\n*foo*"),
// "<p>*foo*\n<em>foo</em></p>",
// "should not support character references as construct markers (1)"
// );
// To do: list.
// assert_eq!(
// micromark("* foo\n\n* foo"),
// "<p>* foo</p>\n<ul>\n<li>foo</li>\n</ul>",
// "should not support character references as construct markers (2)"
// );
assert_eq!(
micromark("[a](url "tit")"),
"<p>[a](url "tit")</p>",
"should not support character references as construct markers (3)"
);
assert_eq!(
micromark("foo bar"),
"<p>foo\n\nbar</p>",
"should not support character references as whitespace (1)"
);
assert_eq!(
micromark("	foo"),
"<p>\tfoo</p>",
"should not support character references as whitespace (2)"
);
// Extra:
assert_eq!(
micromark("∳"),
"<p>∳</p>",
"should support the longest possible named character reference"
);
assert_eq!(
micromark("�"),
"<p>�</p>",
"should “support” a longest possible hexadecimal character reference"
);
assert_eq!(
micromark("�"),
"<p>�</p>",
"should “support” a longest possible decimal character reference"
);
assert_eq!(
micromark("&CounterClockwiseContourIntegrali;"),
"<p>&CounterClockwiseContourIntegrali;</p>",
"should not support the longest possible named character reference"
);
assert_eq!(
micromark("�"),
"<p>&#xff99999;</p>",
"should not support a longest possible hexadecimal character reference"
);
assert_eq!(
micromark("�"),
"<p>&#99999999;</p>",
"should not support a longest possible decimal character reference"
);
assert_eq!(
micromark("&-;"),
"<p>&-;</p>",
"should not support the other characters after `&`"
);
assert_eq!(
micromark("&#-;"),
"<p>&#-;</p>",
"should not support the other characters after `#`"
);
assert_eq!(
micromark("&#x-;"),
"<p>&#x-;</p>",
"should not support the other characters after `#x`"
);
assert_eq!(
micromark("<-;"),
"<p>&lt-;</p>",
"should not support the other characters inside a name"
);
assert_eq!(
micromark("	-;"),
"<p>&#9-;</p>",
"should not support the other characters inside a demical"
);
assert_eq!(
micromark("	-;"),
"<p>&#x9-;</p>",
"should not support the other characters inside a hexademical"
);
// To do: turning things off.
// assert_eq!(
// micromark("&", {
// extensions: [{disable: {null: ["characterReferences"]}}]
// }),
// "<p>&</p>",
// "should support turning off character references"
// );
}
|