1
1
import 'package:checks/checks.dart' ;
2
+ import 'package:html/parser.dart' ;
2
3
import 'package:test/scaffolding.dart' ;
3
4
import 'package:zulip/model/content.dart' ;
4
5
@@ -11,6 +12,16 @@ void testParse(String name, String html, List<BlockContentNode> nodes) {
11
12
});
12
13
}
13
14
15
+ UnimplementedBlockContentNode blockUnimplemented (String html) {
16
+ var fragment = HtmlParser (html, parseMeta: false ).parseFragment ();
17
+ return UnimplementedBlockContentNode (htmlNode: fragment.nodes.single);
18
+ }
19
+
20
+ UnimplementedInlineContentNode inlineUnimplemented (String html) {
21
+ var fragment = HtmlParser (html, parseMeta: false ).parseFragment ();
22
+ return UnimplementedInlineContentNode (htmlNode: fragment.nodes.single);
23
+ }
24
+
14
25
void main () {
15
26
// When writing test cases in this file:
16
27
//
@@ -147,5 +158,41 @@ void main() {
147
158
ParagraphNode (nodes: [TextNode ('world' )]),
148
159
]);
149
160
161
+ group ('parse headings' , () {
162
+ testParse ('plain h6' ,
163
+ // "###### six"
164
+ '<h6>six</h6>' , const [
165
+ HeadingNode (level: HeadingLevel .h6, nodes: [TextNode ('six' )])]);
166
+
167
+ testParse ('containing inline markup' ,
168
+ // "###### one [***`two`***](https://example/)"
169
+ '<h6>one <a href="https://example/"><strong><em><code>two'
170
+ '</code></em></strong></a></h6>' , const [
171
+ HeadingNode (level: HeadingLevel .h6, nodes: [
172
+ TextNode ('one ' ),
173
+ LinkNode (nodes: [StrongNode (nodes: [
174
+ EmphasisNode (nodes: [InlineCodeNode (nodes: [
175
+ TextNode ('two' )])])])]),
176
+ ])]);
177
+
178
+ testParse ('amidst paragraphs' ,
179
+ // "intro\n###### section\ntext"
180
+ "<p>intro</p>\n <h6>section</h6>\n <p>text</p>" , const [
181
+ ParagraphNode (nodes: [TextNode ('intro' )]),
182
+ HeadingNode (level: HeadingLevel .h6, nodes: [TextNode ('section' )]),
183
+ ParagraphNode (nodes: [TextNode ('text' )]),
184
+ ]);
185
+
186
+ testParse ('h1, h2, h3, h4, h5 unimplemented' ,
187
+ // "# one\n## two\n### three\n#### four\n##### five"
188
+ '<h1>one</h1>\n <h2>two</h2>\n <h3>three</h3>\n <h4>four</h4>\n <h5>five</h5>' , [
189
+ blockUnimplemented ('<h1>one</h1>' ),
190
+ blockUnimplemented ('<h2>two</h2>' ),
191
+ blockUnimplemented ('<h3>three</h3>' ),
192
+ blockUnimplemented ('<h4>four</h4>' ),
193
+ blockUnimplemented ('<h5>five</h5>' ),
194
+ ]);
195
+ });
196
+
150
197
// TODO write more tests for this code
151
198
}
0 commit comments