Skip to content

Commit

Permalink
Avoid sharing State when re-parsing markdown sections
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Feb 2, 2025
1 parent 569ef13 commit 599d8b5
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions widget/src/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,6 @@ impl Content {

// Re-parse incomplete sections if new references are available
if !self.incomplete.is_empty() {
let mut state = State {
leftover: String::new(),
references: self.state.references.clone(),
highlighter: None,
};

self.incomplete.retain(|index, section| {
if self.items.len() <= *index {
return false;
Expand All @@ -147,11 +141,19 @@ impl Content {
.retain(|link| !self.state.references.contains_key(link));

if broken_links_before != section.broken_links.len() {
let mut state = State {
leftover: String::new(),
references: self.state.references.clone(),
highlighter: None,
};

if let Some((item, _source, _broken_links)) =
parse_with(&mut state, &section.content).next()
{
self.items[*index] = item;
}

drop(state);
}

!section.broken_links.is_empty()
Expand Down

0 comments on commit 599d8b5

Please sign in to comment.