fix(formats): support backslash space, soft breaks and zero-width spaces in RTF (#2250)

This commit is contained in:
divyanshu2074
2026-10-25 10:29:09 -04:00
committed by GitHub
parent 14f0eec255
commit 0d2d1776dd
+13 -3
View File
@@ -2128,9 +2128,9 @@ impl Reader {
"cell" => self.end_cell(),
"nestcell" => self.end_para(true),
"row" => self.end_row(),
"line" => self.ch('\n'),
"line" | "softline" => self.ch('\n'),
"tab" => self.ch('\t'),
"page" => self.ch('\u{000C}'),
"page" | "softpage" => self.ch('\u{000C}'),
"column" => self.ch('\u{000E}'),
"emdash" => self.ch('—'),
"endash" => self.ch('–'),
@@ -2144,6 +2144,8 @@ impl Reader {
"qmspace" => self.ch('\u{2005}'),
"zwj" => self.ch('\u{200D}'),
"zwnj" => self.ch('\u{200C}'),
"zwbo" => self.ch('\u{200B}'),
"zwnbo" => self.ch('\u{2060}'),
"u" => {
let u = (pv as i64).rem_euclid(65_536) as u16;
if (0xD800..0xDC00).contains(&u) {
@@ -2727,7 +2729,7 @@ fn parse_full(bytes: &[u8]) -> Result<Parsed, String> {
i += 2;
continue;
}
b'~' => {
b'~' | b' ' => {
r.ch('\u{00A0}');
i += 2;
}
@@ -4397,4 +4399,12 @@ mod tests {
assert!(exported.contains("\\clvertalc"));
assert!(exported.contains("\\clvertalb"));
}
#[test]
fn rtf_backslash_space_and_special_breaks() {
let rtf = br"{\rtf1\ansi A\ B\~C\zwbo D\softline E\softpage F\par}";
let doc = import(rtf).unwrap();
let p = doc.body.first().unwrap().as_para().unwrap();
assert_eq!(p.text, "A\u{00A0}B\u{00A0}C\u{200B}D\nE\u{000C}F");
}
}