Skip to content

Commit

Permalink
Add new constructor for markdown::Content
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Jan 31, 2025
1 parent bc2d662 commit 82e6ee0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/markdown/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Markdown {
if enable_stream {
self.mode = Mode::Stream {
pending: self.content.text(),
parsed: markdown::Content::parse(""),
parsed: markdown::Content::new(),
};

scrollable::snap_to(
Expand Down
11 changes: 7 additions & 4 deletions widget/src/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ pub struct Content {
}

impl Content {
pub fn new() -> Self {

Check failure on line 76 in widget/src/markdown.rs

View workflow job for this annotation

GitHub Actions / all

you should consider adding a `Default` implementation for `Content`
Self {
items: Vec::new(),
state: State::default(),
}
}

pub fn parse(markdown: &str) -> Self {
let mut state = State::default();
let items = parse_with(&mut state, markdown).collect();
Expand Down Expand Up @@ -595,16 +602,12 @@ fn parse_with<'a>(
pulldown_cmark::Event::Text(text) if !metadata && !table => {
#[cfg(feature = "highlighter")]
if let Some(highlighter) = &mut highlighter {
let start = std::time::Instant::now();

for line in text.lines() {
spans.extend_from_slice(
highlighter.highlight_line(&format!("{line}\n")),
);
}

dbg!(start.elapsed());

return None;
}

Expand Down

0 comments on commit 82e6ee0

Please sign in to comment.