Skip to content
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

Update pulldown-cmark dependency to 0.10 #67

Merged
merged 16 commits into from
Mar 16, 2024
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: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ edition = "2018"
include = ["src/lib.rs", "LICENSE-APACHE", "README.md", "CHANGELOG.md"]

[dependencies]
pulldown-cmark = { version = "0.9.0", default-features = false }
pulldown-cmark = { version = "0.10.0", default-features = false }

[dev-dependencies]
indoc = "1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/stupicat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}

fn read_to_string(path: OsString) -> String {
let mut file = File::open(&path).expect("file to exist for reading");
let mut file = File::open(path).expect("file to exist for reading");
let mut buf = String::new();
file.read_to_string(&mut buf).expect("file to be readable");
buf
Expand Down
233 changes: 160 additions & 73 deletions src/lib.rs

Large diffs are not rendered by default.

143 changes: 107 additions & 36 deletions tests/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ use pulldown_cmark::Event;
use pulldown_cmark_to_cmark::*;

fn s(e: Event) -> String {
es([e])
}
fn es<'a>(es: impl IntoIterator<Item = Event<'a>>) -> String {
let mut buf = String::new();
cmark([e].iter(), &mut buf).unwrap();
cmark(es.into_iter(), &mut buf).unwrap();
buf
}
mod code {
Expand Down Expand Up @@ -46,11 +49,27 @@ mod start {
}
#[test]
fn header1() {
assert_eq!(s(Start(Heading(HeadingLevel::H1, None, vec![]))), "# ")
assert_eq!(
s(Start(Heading {
level: HeadingLevel::H1,
id: None,
classes: vec![],
attrs: vec![]
})),
"# "
)
}
#[test]
fn header2() {
assert_eq!(s(Start(Heading(HeadingLevel::H2, None, vec![]))), "## ")
assert_eq!(
s(Start(Heading {
level: HeadingLevel::H2,
id: None,
classes: vec![],
attrs: vec![]
})),
"## "
)
}
#[test]
fn blockquote() {
Expand Down Expand Up @@ -89,19 +108,51 @@ mod start {
}
#[test]
fn link() {
assert_eq!(s(Start(Link(Inline, "uri".into(), "title".into()))), "[")
assert_eq!(
s(Start(Link {
link_type: Inline,
dest_url: "uri".into(),
title: "title".into(),
id: "".into(),
})),
"["
)
}
#[test]
fn link_without_title() {
assert_eq!(s(Start(Link(Inline, "uri".into(), "".into()))), "[")
assert_eq!(
s(Start(Link {
link_type: Inline,
dest_url: "uri".into(),
title: "".into(),
id: "".into()
})),
"["
)
}
#[test]
fn image() {
assert_eq!(s(Start(Image(Inline, "uri".into(), "title".into()))), "![")
assert_eq!(
s(Start(Image {
link_type: Inline,
dest_url: "uri".into(),
title: "title".into(),
id: "".into()
})),
"!["
)
}
#[test]
fn image_without_title() {
assert_eq!(s(Start(Image(Inline, "uri".into(), "".into()))), "![")
assert_eq!(
s(Start(Image {
link_type: Inline,
dest_url: "uri".into(),
title: "".into(),
id: "".into()
})),
"!["
)
}
#[test]
fn table() {
Expand All @@ -122,87 +173,107 @@ mod start {
}

mod end {
use pulldown_cmark::{
Alignment::{self, Center, Left, Right},
CodeBlockKind,
Event::*,
HeadingLevel,
LinkType::*,
Tag::*,
};
use pulldown_cmark::{Event::*, HeadingLevel, LinkType::*, Tag, TagEnd};

use super::s;
use super::{es, s};

#[test]
fn header() {
assert_eq!(s(End(Heading(HeadingLevel::H2, None, vec![]))), "")
let tag = Tag::Heading {
level: HeadingLevel::H2,
id: None,
classes: Default::default(),
attrs: Default::default(),
};
assert_eq!(es([Start(tag.clone()), End(tag.to_end())]), "## ")
}
#[test]
fn paragraph() {
assert_eq!(s(End(Paragraph)), "")
assert_eq!(s(End(TagEnd::Paragraph)), "")
}
#[test]
fn blockquote() {
assert_eq!(s(End(BlockQuote)), "")
assert_eq!(s(End(TagEnd::BlockQuote)), "")
}
#[test]
fn codeblock() {
assert_eq!(s(End(CodeBlock(CodeBlockKind::Fenced("asdf".into())))), "````")
assert_eq!(s(End(TagEnd::CodeBlock)), "````")
}
#[test]
fn footnote_definition() {
assert_eq!(s(End(FootnoteDefinition("asdf".into()))), "")
assert_eq!(s(End(TagEnd::FootnoteDefinition)), "")
}
#[test]
fn emphasis() {
assert_eq!(s(End(Emphasis)), "*")
assert_eq!(s(End(TagEnd::Emphasis)), "*")
}
#[test]
fn strong() {
assert_eq!(s(End(Strong)), "**")
assert_eq!(s(End(TagEnd::Strong)), "**")
}
#[test]
fn list_unordered() {
assert_eq!(s(End(List(None))), "")
assert_eq!(s(End(TagEnd::List(false))), "")
}
#[test]
fn list_ordered() {
assert_eq!(s(End(List(Some(1)))), "")
assert_eq!(s(End(TagEnd::List(true))), "")
}
#[test]
fn item() {
assert_eq!(s(End(Item)), "")
assert_eq!(s(End(TagEnd::Item)), "")
}
#[test]
fn link() {
assert_eq!(s(End(Link(Inline, "/uri".into(), "title".into()))), "](/uri \"title\")")
let tag = Tag::Link {
link_type: Inline,
dest_url: "/uri".into(),
title: "title".into(),
id: "".into(),
};
assert_eq!(es([Start(tag.clone()), End(tag.to_end())]), "[](/uri \"title\")")
}
#[test]
fn link_without_title() {
assert_eq!(s(End(Link(Inline, "/uri".into(), "".into()))), "](/uri)")
let tag = Tag::Link {
link_type: Inline,
dest_url: "/uri".into(),
title: "".into(),
id: "".into(),
};
assert_eq!(es([Start(tag.clone()), End(tag.to_end())]), "[](/uri)")
}
#[test]
fn image() {
assert_eq!(
s(End(Image(Inline, "/uri".into(), "title".into()))),
"](/uri \"title\")"
)
let tag = Tag::Image {
link_type: Inline,
dest_url: "/uri".into(),
title: "title".into(),
id: "".into(),
};
assert_eq!(es([Start(tag.clone()), End(tag.to_end())]), "![](/uri \"title\")")
}
#[test]
fn image_without_title() {
assert_eq!(s(End(Image(Inline, "/uri".into(), "".into()))), "](/uri)")
let tag = Tag::Image {
link_type: Inline,
dest_url: "/uri".into(),
title: "".into(),
id: "".into(),
};
assert_eq!(es([Start(tag.clone()), End(tag.to_end())]), "![](/uri)")
}
#[test]
fn table() {
assert_eq!(s(End(Table(vec![Left, Center, Right, Alignment::None]))), "")
assert_eq!(s(End(TagEnd::Table)), "")
}
#[test]
fn table_row() {
assert_eq!(s(End(TableRow)), "|")
assert_eq!(s(End(TagEnd::TableRow)), "|")
}
#[test]
fn table_cell() {
assert_eq!(s(End(TableCell)), "")
assert_eq!(s(End(TagEnd::TableCell)), "")
}
}

Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/heading-id-classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
## with class {.classh2}

### multiple {#myh3 .classh3}

# text { #id .class1 .class2 myattr, other_attr=myvalue }
2 changes: 1 addition & 1 deletion tests/fixtures/snapshots/stupicat-event-by-event-output
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Ordered lists:
1. dolor sit amet
1. Nested

1. With
1. With
Paragraphs and nested blocks:

>
Expand Down
8 changes: 5 additions & 3 deletions tests/fixtures/snapshots/stupicat-heading-id-classes-output
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# nothing

# with ID {#myh1}
# with ID { #myh1 }

## with class {.classh2}
## with class { .classh2 }

### multiple {#myh3 .classh3}
### multiple { #myh3 .classh3 }

# text { #id .class1 .class2 myattr, other_attr=myvalue }
1 change: 1 addition & 0 deletions tests/fixtures/snapshots/stupicat-nested-output
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*emphasized*

</div>

<div>
second line
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/snapshots/stupicat-output
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Ordered lists:
1. dolor sit amet
1. Nested

1. With
1. With
Paragraphs and nested blocks:

>
Expand Down
Loading
Loading