From 06af1b700af795b537c3c0a9fdfb9f32e448b3f5 Mon Sep 17 00:00:00 2001 From: Max Heller Date: Sat, 10 Feb 2024 16:46:56 -0500 Subject: [PATCH] WIP: update pulldown-cmark dependency --- Cargo.toml | 2 +- src/lib.rs | 54 ++++++++++++++++++++++++++++++------------------------ 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c6a23e2..09b121a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/lib.rs b/src/lib.rs index ef1d595..2b1678f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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. @@ -325,13 +325,19 @@ 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) => { @@ -339,7 +345,7 @@ where write!(formatter, "[^{}]: ", name) } Paragraph => Ok(()), - Heading(level, _, _) => { + Heading { level, .. } => { match level { HeadingLevel::H1 => formatter.write_str("#"), HeadingLevel::H2 => formatter.write_str("##"), @@ -395,8 +401,8 @@ 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 @@ -404,12 +410,12 @@ where } 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(" {")?; @@ -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; } @@ -455,7 +461,7 @@ where } Ok(()) } - Table(_) => { + TagEnd::Table => { if state.newlines_before_start < options.newlines_after_table { state.newlines_before_start = options.newlines_after_table; } @@ -463,7 +469,7 @@ where state.table_headers.clear(); Ok(()) } - TableCell => { + TagEnd::TableCell => { state.table_headers.push( state .text_for_header @@ -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))?; @@ -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 { @@ -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)), @@ -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; }