@@ -3,7 +3,7 @@ use std::iter::FromIterator;
3
3
use std:: ops:: { Deref , DerefMut } ;
4
4
use std:: path:: { Path , PathBuf } ;
5
5
use memchr:: { self , Memchr } ;
6
- use pulldown_cmark:: { self , Event , Tag } ;
6
+ use pulldown_cmark:: { self , Alignment , Event , Tag } ;
7
7
use errors:: * ;
8
8
9
9
@@ -310,17 +310,24 @@ impl<'a> SummaryParser<'a> {
310
310
break ;
311
311
}
312
312
Some ( Event :: Start ( other_tag) ) => {
313
- if Tag :: Rule == other_tag {
313
+ // FIXME: Remove this when google/pulldown_cmark#120 lands (new patch release)
314
+ // replace with `other_tag == Tag::Rule`
315
+ if tag_eq ( & other_tag, & Tag :: Rule ) {
314
316
items. push ( SummaryItem :: Separator ) ;
315
317
}
316
318
trace ! ( "Skipping contents of {:?}" , other_tag) ;
317
319
318
320
// Skip over the contents of this tag
319
- loop {
320
- let next = self . next_event ( ) ;
321
-
322
- if next. is_none ( ) || next == Some ( Event :: End ( other_tag. clone ( ) ) ) {
323
- break ;
321
+ while let Some ( event) = self . next_event ( ) {
322
+ // FIXME: Remove this when google/pulldown_cmark#120 lands (new patch release)
323
+ // and replace the nested if-let with:
324
+ // if next == Event::End(other_tag.clone()) {
325
+ // break;
326
+ // }
327
+ if let Event :: End ( tag) = event {
328
+ if tag_eq ( & tag, & other_tag) {
329
+ break ;
330
+ }
324
331
}
325
332
}
326
333
@@ -474,6 +481,41 @@ fn stringify_events(events: Vec<Event>) -> String {
474
481
. collect ( )
475
482
}
476
483
484
+ // FIXME: Remove this when google/pulldown_cmark#120 lands (new patch release)
485
+ fn tag_eq ( left : & Tag , right : & Tag ) -> bool {
486
+ match ( left, right) {
487
+ ( & Tag :: Paragraph , & Tag :: Paragraph ) => true ,
488
+ ( & Tag :: Rule , & Tag :: Rule ) => true ,
489
+ ( & Tag :: Header ( a) , & Tag :: Header ( b) ) => a == b,
490
+ ( & Tag :: BlockQuote , & Tag :: BlockQuote ) => true ,
491
+ ( & Tag :: CodeBlock ( ref a) , & Tag :: CodeBlock ( ref b) ) => a == b,
492
+ ( & Tag :: List ( ref a) , & Tag :: List ( ref b) ) => a == b,
493
+ ( & Tag :: Item , & Tag :: Item ) => true ,
494
+ ( & Tag :: FootnoteDefinition ( ref a) , & Tag :: FootnoteDefinition ( ref b) ) => a == b,
495
+ ( & Tag :: Table ( ref a) , & Tag :: Table ( ref b) ) => a. iter ( ) . zip ( b. iter ( ) ) . all ( |( l, r) | alignment_eq ( * l, * r) ) ,
496
+ ( & Tag :: TableHead , & Tag :: TableHead ) => true ,
497
+ ( & Tag :: TableRow , & Tag :: TableRow ) => true ,
498
+ ( & Tag :: TableCell , & Tag :: TableCell ) => true ,
499
+ ( & Tag :: Emphasis , & Tag :: Emphasis ) => true ,
500
+ ( & Tag :: Strong , & Tag :: Strong ) => true ,
501
+ ( & Tag :: Code , & Tag :: Code ) => true ,
502
+ ( & Tag :: Link ( ref a_1, ref a_2) , & Tag :: Link ( ref b_1, ref b_2) ) => a_1 == b_1 && a_2 == b_2,
503
+ ( & Tag :: Image ( ref a_1, ref a_2) , & Tag :: Image ( ref b_1, ref b_2) ) => a_1 == b_1 && a_2 == b_2,
504
+ _ => false ,
505
+ }
506
+ }
507
+
508
+ // FIXME: Remove this when google/pulldown_cmark#120 lands (new patch release)
509
+ fn alignment_eq ( left : Alignment , right : Alignment ) -> bool {
510
+ match ( left, right) {
511
+ ( Alignment :: None , Alignment :: None ) => true ,
512
+ ( Alignment :: Left , Alignment :: Left ) => true ,
513
+ ( Alignment :: Center , Alignment :: Center ) => true ,
514
+ ( Alignment :: Right , Alignment :: Right ) => true ,
515
+ _ => false
516
+ }
517
+ }
518
+
477
519
/// A section number like "1.2.3", basically just a newtype'd `Vec<u32>` with
478
520
/// a pretty `Display` impl.
479
521
#[ derive( Debug , PartialEq , Clone , Default , Serialize , Deserialize ) ]
0 commit comments