Skip to content

Commit fa84da0

Browse files
Stop pulling pulldown-cmark from master (#555)
* Manually implemented PartialEq for pulldown_cmark types * Fixed an issue where we wouldn't skip a tag properly
1 parent 947d031 commit fa84da0

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,3 @@ doc = false
6666
name = "mdbook"
6767
path = "src/bin/mdbook.rs"
6868

69-
[patch.crates-io]
70-
pulldown-cmark = { git = "https://github.com/google/pulldown-cmark" }

src/book/summary.rs

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::iter::FromIterator;
33
use std::ops::{Deref, DerefMut};
44
use std::path::{Path, PathBuf};
55
use memchr::{self, Memchr};
6-
use pulldown_cmark::{self, Event, Tag};
6+
use pulldown_cmark::{self, Alignment, Event, Tag};
77
use errors::*;
88

99

@@ -310,17 +310,24 @@ impl<'a> SummaryParser<'a> {
310310
break;
311311
}
312312
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) {
314316
items.push(SummaryItem::Separator);
315317
}
316318
trace!("Skipping contents of {:?}", other_tag);
317319

318320
// 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+
}
324331
}
325332
}
326333

@@ -474,6 +481,41 @@ fn stringify_events(events: Vec<Event>) -> String {
474481
.collect()
475482
}
476483

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+
477519
/// A section number like "1.2.3", basically just a newtype'd `Vec<u32>` with
478520
/// a pretty `Display` impl.
479521
#[derive(Debug, PartialEq, Clone, Default, Serialize, Deserialize)]

0 commit comments

Comments
 (0)