Skip to content

Commit

Permalink
Update ansi and pulldown dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
gyscos committed May 30, 2024
1 parent dcc9dff commit f3bd7e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions cursive-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -62,7 +62,7 @@ version = "0.4"
[dependencies.pulldown-cmark]
default-features = false
optional = true
version = "0.10"
version = "0.11"

[features]
default = []
Expand Down
22 changes: 15 additions & 7 deletions cursive-core/src/utils/markup/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ where
StyledString::with_spans(input, spans)
}

// Convert a CowStr from pulldown into a regular Cow<str>
// We lose the inline optimization, but oh well.
fn cowvert(cow: CowStr) -> Cow<str> {
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,
Expand Down Expand Up @@ -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})"))),
Expand All @@ -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 {
Expand Down

0 comments on commit f3bd7e9

Please sign in to comment.