Fix markdown escaping

Closes #29255

Release Notes:

- Improved handling of markdown escape sequences
This commit is contained in:
Conrad Irwin 2025-04-25 16:53:44 -06:00 committed by GitHub
parent d23024609f
commit 053fafa90e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 200 additions and 112 deletions

View file

@ -221,7 +221,12 @@ impl Markdown {
.count();
if count > 0 {
let mut output = String::with_capacity(s.len() + count);
let mut is_newline = false;
for c in s.chars() {
if is_newline && c == ' ' {
continue;
}
is_newline = c == '\n';
if c == '\n' {
output.push('\n')
} else if c.is_ascii_punctuation() {
@ -1722,6 +1727,15 @@ mod tests {
rendered.text
}
#[test]
fn test_escape() {
assert_eq!(Markdown::escape("hello `world`"), "hello \\`world\\`");
assert_eq!(
Markdown::escape("hello\n cool world"),
"hello\n\ncool world"
);
}
#[track_caller]
fn assert_mappings(rendered: &RenderedText, expected: Vec<Vec<(usize, usize)>>) {
assert_eq!(rendered.lines.len(), expected.len(), "line count mismatch");