fix: decode   to a non-breaking space so blank paragraphs survive trimming

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
NetterSilver
2026-10-18 18:01:49 +02:00
co-authored by Claude Haiku 5.5
parent e54bd2ccb7
commit 03993057a4
2 changed files with 25 additions and 1 deletions
+1 -1
View File
@@ -313,7 +313,7 @@ fn decode_text(raw: &str) -> String {
"gt" => Some('>'),
"quot" => Some('"'),
"apos" => Some('\''),
"nbsp" => Some(' '),
"nbsp" => Some('\u{a0}'),
_ => entity.strip_prefix('#').and_then(numeric_char),
};
if let Some(c) = decoded {
+24
View File
@@ -268,6 +268,30 @@ fn html_paste_with_a_source_newline_keeps_its_bold() {
assert_eq!(body.paragraphs[0].runs[0].props.bold, Some(true), "{body:?}");
}
#[test]
fn html_paste_keeps_a_blank_nbsp_paragraph_and_the_rich_path() {
for blank in ["<p>&nbsp;</p>", "<p><o:p>&nbsp;</o:p></p>"] {
let mut s = session();
let html = format!("<p><b>A</b></p>{blank}<p>B</p>");
s.execute("edit.paste", &json!({"text": "A\n\u{a0}\nB", "html": html})).unwrap();
let body = s
.doc()
.unwrap()
.current_slide()
.unwrap()
.shapes
.iter()
.find(|sh| sh.text.as_ref().is_some_and(|t| t.paragraphs.len() == 3))
.unwrap()
.text
.clone()
.unwrap();
assert_eq!(body.paragraphs[0].runs[0].text, "A", "{html}: {body:?}");
assert_eq!(body.paragraphs[0].runs[0].props.bold, Some(true), "{html}: {body:?}");
assert_eq!(body.paragraphs[2].runs[0].text, "B", "{html}: {body:?}");
}
}
#[test]
fn group_ungroup_roundtrip_positions() {
let mut s = session();