Fix markdown escaping
Closes #29255 Release Notes: - Improved handling of markdown escape sequences
This commit is contained in:
parent
d23024609f
commit
053fafa90e
3 changed files with 200 additions and 112 deletions
|
@ -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");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue