Restore direct use of the input text for Markdown Text (#27620)

PR #24388 changed the markdown parsing to copy parsed text in order to
handle markdown escaping, removing the optimization to instead reuse
text from the input.

Another issue with that change was that handling of finding links within
`Text` intermixed use of `text` and `parsed`, relying on the offsets
matching up (which I believe was true in practice).

The solution is to distinguish pulldown_cmark `Text` nodes that share
bytes with the input and those that do not.

Release Notes:

- N/A
This commit is contained in:
Michael Sloan
2025-04-04 23:12:32 +00:00
committed by GitHub
parent 4bcd37a537
commit e74af03065
3 changed files with 196 additions and 59 deletions
+4 -2
View File
@@ -951,8 +951,10 @@ mod tests {
for (range, event) in slice.iter() {
match event {
MarkdownEvent::Text(parsed) => rendered_text.push_str(parsed),
MarkdownEvent::Code => rendered_text.push_str(&text[range.clone()]),
MarkdownEvent::SubstitutedText(parsed) => rendered_text.push_str(parsed),
MarkdownEvent::Text | MarkdownEvent::Code => {
rendered_text.push_str(&text[range.clone()])
}
_ => {}
}
}