Skip to content

Stop pulling pulldown-cmark from master #555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
56 changes: 49 additions & 7 deletions src/book/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;


Expand Down Expand Up @@ -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;
}
}
}

Expand Down Expand Up @@ -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)]
Expand Down