1
- use pulldown_cmark:: { Event , Parser , Tag } ;
1
+ use pulldown_cmark:: { Event , Parser , Tag , TagEnd } ;
2
2
use std:: ops:: Range ;
3
3
4
4
#[ derive( Debug ) ]
@@ -14,25 +14,35 @@ impl IgnoreBlocks {
14
14
if let Event :: Start ( Tag :: CodeBlock ( _) ) = event {
15
15
let start = range. start ;
16
16
while let Some ( ( event, range) ) = parser. next ( ) {
17
- if let Event :: End ( Tag :: CodeBlock ( _ ) ) = event {
17
+ if let Event :: End ( TagEnd :: CodeBlock ) = event {
18
18
ignore. push ( start..range. end ) ;
19
19
break ;
20
20
}
21
21
}
22
- } else if let Event :: Start ( Tag :: BlockQuote ) = event {
22
+ } else if let Event :: Start ( Tag :: BlockQuote ( _ ) ) = event {
23
23
let start = range. start ;
24
24
let mut count = 1 ;
25
25
while let Some ( ( event, range) ) = parser. next ( ) {
26
- if let Event :: Start ( Tag :: BlockQuote ) = event {
26
+ if let Event :: Start ( Tag :: BlockQuote ( _ ) ) = event {
27
27
count += 1 ;
28
- } else if let Event :: End ( Tag :: BlockQuote ) = event {
28
+ } else if let Event :: End ( TagEnd :: BlockQuote ( _ ) ) = event {
29
29
count -= 1 ;
30
30
if count == 0 {
31
31
ignore. push ( start..range. end ) ;
32
32
break ;
33
33
}
34
34
}
35
35
}
36
+ } else if let Event :: Start ( Tag :: HtmlBlock ) = event {
37
+ let start = range. start ;
38
+ while let Some ( ( event, range) ) = parser. next ( ) {
39
+ if let Event :: End ( TagEnd :: HtmlBlock ) = event {
40
+ ignore. push ( start..range. end ) ;
41
+ break ;
42
+ }
43
+ }
44
+ } else if let Event :: InlineHtml ( _) = event {
45
+ ignore. push ( range) ;
36
46
} else if let Event :: Code ( _) = event {
37
47
ignore. push ( range) ;
38
48
}
@@ -92,15 +102,27 @@ fn cbs_1() {
92
102
fn cbs_2 ( ) {
93
103
assert_eq ! (
94
104
bodies( "`hey you` <b>me too</b>" ) ,
95
- [ Ignore :: Yes ( "`hey you`" ) , Ignore :: No ( " <b>me too</b>" ) ]
105
+ [
106
+ Ignore :: Yes ( "`hey you`" ) ,
107
+ Ignore :: No ( " " ) ,
108
+ Ignore :: Yes ( "<b>" ) ,
109
+ Ignore :: No ( "me too" ) ,
110
+ Ignore :: Yes ( "</b>" )
111
+ ]
96
112
) ;
97
113
}
98
114
99
115
#[ test]
100
116
fn cbs_3 ( ) {
101
117
assert_eq ! (
102
118
bodies( r"`hey you\` <b>`me too</b>" ) ,
103
- [ Ignore :: Yes ( r"`hey you\`" ) , Ignore :: No ( " <b>`me too</b>" ) ]
119
+ [
120
+ Ignore :: Yes ( "`hey you\\ `" ) ,
121
+ Ignore :: No ( " " ) ,
122
+ Ignore :: Yes ( "<b>" ) ,
123
+ Ignore :: No ( "`me too" ) ,
124
+ Ignore :: Yes ( "</b>" )
125
+ ]
104
126
) ;
105
127
}
106
128
@@ -239,3 +261,24 @@ fn cbs_11() {
239
261
] ,
240
262
) ;
241
263
}
264
+
265
+ #[ test]
266
+ fn cbs_12 ( ) {
267
+ assert_eq ! (
268
+ bodies(
269
+ "
270
+ Test
271
+
272
+ <!-- Test -->
273
+ <!--
274
+ This is an HTML comment.
275
+ -->
276
+ "
277
+ ) ,
278
+ [
279
+ Ignore :: No ( "\n Test\n \n " ) ,
280
+ Ignore :: Yes ( "<!-- Test -->\n " ) ,
281
+ Ignore :: Yes ( "<!--\n This is an HTML comment.\n -->\n " )
282
+ ] ,
283
+ ) ;
284
+ }
0 commit comments