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
This commit is contained in:
Michael Bryan 2018-01-19 01:21:04 +08:00 committed by GitHub
parent 947d0312c6
commit fa84da0856
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 9 deletions

View file

@ -66,5 +66,3 @@ doc = false
name = "mdbook"
path = "src/bin/mdbook.rs"
[patch.crates-io]
pulldown-cmark = { git = "https://github.com/google/pulldown-cmark" }

View file

@ -3,7 +3,7 @@ use std::iter::FromIterator;
use std::ops::{Deref, DerefMut};
use std::path::{Path, PathBuf};
use memchr::{self, Memchr};
use pulldown_cmark::{self, Event, Tag};
use pulldown_cmark::{self, Alignment, Event, Tag};
use errors::*;
@ -310,17 +310,24 @@ impl<'a> SummaryParser<'a> {
break;
}
Some(Event::Start(other_tag)) => {
if Tag::Rule == other_tag {
// FIXME: Remove this when google/pulldown_cmark#120 lands (new patch release)
// replace with `other_tag == Tag::Rule`
if tag_eq(&other_tag, &Tag::Rule) {
items.push(SummaryItem::Separator);
}
trace!("Skipping contents of {:?}", other_tag);
// Skip over the contents of this tag
loop {
let next = self.next_event();
if next.is_none() || next == Some(Event::End(other_tag.clone())) {
break;
while let Some(event) = self.next_event() {
// FIXME: Remove this when google/pulldown_cmark#120 lands (new patch release)
// and replace the nested if-let with:
// if next == Event::End(other_tag.clone()) {
// break;
// }
if let Event::End(tag) = event {
if tag_eq(&tag, &other_tag) {
break;
}
}
}
@ -474,6 +481,41 @@ fn stringify_events(events: Vec<Event>) -> String {
.collect()
}
// FIXME: Remove this when google/pulldown_cmark#120 lands (new patch release)
fn tag_eq(left: &Tag, right: &Tag) -> bool {
match (left, right) {
(&Tag::Paragraph, &Tag::Paragraph) => true,
(&Tag::Rule, &Tag::Rule) => true,
(&Tag::Header(a), &Tag::Header(b)) => a == b,
(&Tag::BlockQuote, &Tag::BlockQuote) => true,
(&Tag::CodeBlock(ref a), &Tag::CodeBlock(ref b)) => a == b,
(&Tag::List(ref a), &Tag::List(ref b)) => a == b,
(&Tag::Item, &Tag::Item) => true,
(&Tag::FootnoteDefinition(ref a), &Tag::FootnoteDefinition(ref b)) => a == b,
(&Tag::Table(ref a), &Tag::Table(ref b)) => a.iter().zip(b.iter()).all(|(l, r)| alignment_eq(*l, *r)),
(&Tag::TableHead, &Tag::TableHead) => true,
(&Tag::TableRow, &Tag::TableRow) => true,
(&Tag::TableCell, &Tag::TableCell) => true,
(&Tag::Emphasis, &Tag::Emphasis) => true,
(&Tag::Strong, &Tag::Strong) => true,
(&Tag::Code, &Tag::Code) => true,
(&Tag::Link(ref a_1, ref a_2), &Tag::Link(ref b_1, ref b_2)) => a_1 == b_1 && a_2 == b_2,
(&Tag::Image(ref a_1, ref a_2), &Tag::Image(ref b_1, ref b_2)) => a_1 == b_1 && a_2 == b_2,
_ => false,
}
}
// FIXME: Remove this when google/pulldown_cmark#120 lands (new patch release)
fn alignment_eq(left: Alignment, right: Alignment) -> bool {
match (left, right) {
(Alignment::None, Alignment::None) => true,
(Alignment::Left, Alignment::Left) => true,
(Alignment::Center, Alignment::Center) => true,
(Alignment::Right, Alignment::Right) => true,
_ => false
}
}
/// A section number like "1.2.3", basically just a newtype'd `Vec<u32>` with
/// a pretty `Display` impl.
#[derive(Debug, PartialEq, Clone, Default, Serialize, Deserialize)]