Skip to content

Commit

Permalink
WIP: update pulldown-cmark dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
max-heller committed Feb 10, 2024
1 parent 11344a7 commit 06af1b7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
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
54 changes: 30 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
fmt::{self, Write},
};

use pulldown_cmark::{Alignment as TableAlignment, Event, HeadingLevel, LinkType, Tag};
use pulldown_cmark::{Alignment as TableAlignment, Event, HeadingLevel, LinkType, Tag, TagEnd};

/// Similar to [Pulldown-Cmark-Alignment][Alignment], but with required
/// traits for comparison to allow testing.
Expand Down Expand Up @@ -325,21 +325,27 @@ where
state.text_for_header = Some(String::new());
formatter.write_char('|')
}
Link(LinkType::Autolink | LinkType::Email, ..) => formatter.write_char('<'),
Link(LinkType::Shortcut, ..) => {
Link {
link_type: LinkType::Autolink | LinkType::Email,
..
} => formatter.write_char('<'),
Link {
link_type: LinkType::Shortcut,
..
} => {
state.current_shortcut_text = Some(String::new());
formatter.write_char('[')
}
Link(..) => formatter.write_char('['),
Image(..) => formatter.write_str("!["),
Link { .. } => formatter.write_char('['),
Image { .. } => formatter.write_str("!["),
Emphasis => formatter.write_char(options.emphasis_token),
Strong => formatter.write_str(options.strong_token),
FootnoteDefinition(ref name) => {
state.padding.push(" ".into());
write!(formatter, "[^{}]: ", name)
}
Paragraph => Ok(()),
Heading(level, _, _) => {
Heading { level, .. } => {
match level {
HeadingLevel::H1 => formatter.write_str("#"),
HeadingLevel::H2 => formatter.write_str("##"),
Expand Down Expand Up @@ -395,21 +401,21 @@ where
}
}
End(ref tag) => match tag {
Link(LinkType::Autolink | LinkType::Email, ..) => formatter.write_char('>'),
Link(LinkType::Shortcut, ref uri, ref title) => {
TagEnd::Link(LinkType::Autolink | LinkType::Email, ..) => formatter.write_char('>'),
TagEnd::Link(LinkType::Shortcut, ref uri, ref title) => {
if let Some(shortcut_text) = state.current_shortcut_text.take() {
state
.shortcuts
.push((shortcut_text, uri.to_string(), title.to_string()));
}
formatter.write_char(']')
}
Image(_, ref uri, ref title) | Link(_, ref uri, ref title) => {
TagEnd::Image(_, ref uri, ref title) | Link(_, ref uri, ref title) => {
close_link(uri, title, &mut formatter, LinkType::Inline)
}
Emphasis => formatter.write_char(options.emphasis_token),
Strong => formatter.write_str(options.strong_token),
Heading(_, id, classes) => {
TagEnd::Emphasis => formatter.write_char(options.emphasis_token),
TagEnd::Strong => formatter.write_str(options.strong_token),
TagEnd::Heading(_, id, classes) => {
let emit_braces = id.is_some() || !classes.is_empty();
if emit_braces {
formatter.write_str(" {")?;
Expand All @@ -436,13 +442,13 @@ where
}
Ok(())
}
Paragraph => {
TagEnd::Paragraph => {
if state.newlines_before_start < options.newlines_after_paragraph {
state.newlines_before_start = options.newlines_after_paragraph;
}
Ok(())
}
CodeBlock(_) => {
TagEnd::CodeBlock => {
if state.newlines_before_start < options.newlines_after_codeblock {
state.newlines_before_start = options.newlines_after_codeblock;
}
Expand All @@ -455,15 +461,15 @@ where
}
Ok(())
}
Table(_) => {
TagEnd::Table => {
if state.newlines_before_start < options.newlines_after_table {
state.newlines_before_start = options.newlines_after_table;
}
state.table_alignments.clear();
state.table_headers.clear();
Ok(())
}
TableCell => {
TagEnd::TableCell => {
state.table_headers.push(
state
.text_for_header
Expand All @@ -473,13 +479,13 @@ where
);
Ok(())
}
ref t @ TableRow | ref t @ TableHead => {
ref t @ TagEnd::TableRow | ref t @ TagEnd::TableHead => {
if state.newlines_before_start < options.newlines_after_rest {
state.newlines_before_start = options.newlines_after_rest;
}
formatter.write_char('|')?;

if let TableHead = t {
if let TagEnd::TableHead = t {
formatter
.write_char('\n')
.and(padding(&mut formatter, &state.padding))?;
Expand All @@ -505,21 +511,21 @@ where
}
Ok(())
}
Item => {
TagEnd::Item => {
state.padding.pop();
if state.newlines_before_start < options.newlines_after_rest {
state.newlines_before_start = options.newlines_after_rest;
}
Ok(())
}
List(_) => {
TagEnd::List(_) => {
state.list_stack.pop();
if state.list_stack.is_empty() && state.newlines_before_start < options.newlines_after_list {
state.newlines_before_start = options.newlines_after_list;
}
Ok(())
}
BlockQuote => {
TagEnd::BlockQuote => {
state.padding.pop();

if state.newlines_before_start < options.newlines_after_blockquote {
Expand All @@ -528,11 +534,11 @@ where

Ok(())
}
FootnoteDefinition(_) => {
TagEnd::FootnoteDefinition => {
state.padding.pop();
Ok(())
}
Strikethrough => formatter.write_str("~~"),
TagEnd::Strikethrough => formatter.write_str("~~"),
},
HardBreak => formatter.write_str(" \n").and(padding(&mut formatter, &state.padding)),
SoftBreak => formatter.write_char('\n').and(padding(&mut formatter, &state.padding)),
Expand Down Expand Up @@ -710,7 +716,7 @@ where
Event::Start(Tag::CodeBlock(_)) => {
in_codeblock = true;
}
Event::End(Tag::CodeBlock(_)) => {
Event::End(TagEnd::CodeBlock) => {
in_codeblock = false;
prev_token_char = None;
}
Expand Down

0 comments on commit 06af1b7

Please sign in to comment.