1- use pulldown_cmark:: { Event , Parser , Tag } ;
1+ use pulldown_cmark:: { Event , Parser , Tag , TagEnd } ;
22use std:: ops:: Range ;
33
44#[ derive( Debug ) ]
@@ -14,25 +14,35 @@ impl IgnoreBlocks {
1414 if let Event :: Start ( Tag :: CodeBlock ( _) ) = event {
1515 let start = range. start ;
1616 while let Some ( ( event, range) ) = parser. next ( ) {
17- if let Event :: End ( Tag :: CodeBlock ( _ ) ) = event {
17+ if let Event :: End ( TagEnd :: CodeBlock ) = event {
1818 ignore. push ( start..range. end ) ;
1919 break ;
2020 }
2121 }
22- } else if let Event :: Start ( Tag :: BlockQuote ) = event {
22+ } else if let Event :: Start ( Tag :: BlockQuote ( _ ) ) = event {
2323 let start = range. start ;
2424 let mut count = 1 ;
2525 while let Some ( ( event, range) ) = parser. next ( ) {
26- if let Event :: Start ( Tag :: BlockQuote ) = event {
26+ if let Event :: Start ( Tag :: BlockQuote ( _ ) ) = event {
2727 count += 1 ;
28- } else if let Event :: End ( Tag :: BlockQuote ) = event {
28+ } else if let Event :: End ( TagEnd :: BlockQuote ( _ ) ) = event {
2929 count -= 1 ;
3030 if count == 0 {
3131 ignore. push ( start..range. end ) ;
3232 break ;
3333 }
3434 }
3535 }
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) ;
3646 } else if let Event :: Code ( _) = event {
3747 ignore. push ( range) ;
3848 }
@@ -92,15 +102,27 @@ fn cbs_1() {
92102fn cbs_2 ( ) {
93103 assert_eq ! (
94104 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+ ]
96112 ) ;
97113}
98114
99115#[ test]
100116fn cbs_3 ( ) {
101117 assert_eq ! (
102118 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+ ]
104126 ) ;
105127}
106128
@@ -239,3 +261,24 @@ fn cbs_11() {
239261 ] ,
240262 ) ;
241263}
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