diff --git a/cursive-core/Cargo.toml b/cursive-core/Cargo.toml index 68558f5f..1ba85864 100644 --- a/cursive-core/Cargo.toml +++ b/cursive-core/Cargo.toml @@ -44,7 +44,7 @@ version = "0.3.1" optional = true [dependencies.ansi-parser] -version = "0.8.0" +version = "0.9.0" optional = true [dependencies.time] @@ -62,7 +62,7 @@ version = "0.4" [dependencies.pulldown-cmark] default-features = false optional = true -version = "0.10" +version = "0.11" [features] default = [] diff --git a/cursive-core/src/utils/markup/markdown.rs b/cursive-core/src/utils/markup/markdown.rs index 8fa542c3..7f0cdd16 100644 --- a/cursive-core/src/utils/markup/markdown.rs +++ b/cursive-core/src/utils/markup/markdown.rs @@ -25,6 +25,16 @@ where StyledString::with_spans(input, spans) } +// Convert a CowStr from pulldown into a regular Cow +// We lose the inline optimization, but oh well. +fn cowvert(cow: CowStr) -> Cow { + match cow { + CowStr::Borrowed(text) => Cow::Borrowed(text), + CowStr::Boxed(text) => Cow::Owned(text.into()), + CowStr::Inlined(text) => Cow::Owned(text.to_string()), + } +} + /// Iterator that parse a markdown text and outputs styled spans. pub struct Parser<'a> { first: bool, @@ -74,7 +84,7 @@ impl<'a> Iterator for Parser<'a> { Tag::Heading { level, .. } => { return Some(self.literal(format!("{} ", heading(level as usize)))) } - Tag::BlockQuote => return Some(self.literal("> ")), + Tag::BlockQuote(_) => return Some(self.literal("> ")), Tag::Link { dest_url, title, .. } => return Some(self.literal(format!("[{title}]({dest_url})"))), @@ -101,12 +111,10 @@ impl<'a> Iterator for Parser<'a> { | Event::InlineHtml(text) | Event::Html(text) | Event::Text(text) - | Event::Code(text) => { - let text = match text { - CowStr::Boxed(text) => Cow::Owned(text.into()), - CowStr::Borrowed(text) => Cow::Borrowed(text), - CowStr::Inlined(text) => Cow::Owned(text.to_string()), - }; + | Event::Code(text) + | Event::InlineMath(text) + | Event::DisplayMath(text) => { + let text = cowvert(text); let width = text.width(); // Return something! return Some(StyledIndexedSpan {