Skip to content

Commit 6647b0a

Browse files
geezoriageezoria1337claude
authored
fix(web): rich text previews keep paragraphs that end with a backslash (#30812)
Co-authored-by: Geezy <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent cddfc8d commit 6647b0a

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎apps/web/src/components/files/FilePreviewPanel.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,24 @@ describe("document preview contents", () => {
173173
expect(html).not.toContain("https:");
174174
});
175175

176+
it("treats a backslash before a line break as a paragraph break, as TextEdit writes them", () => {
177+
const html = (rtf: string) => {
178+
const result = openRtf(bytes(rtf));
179+
if (result.type !== "document") throw new Error("Expected document");
180+
return result.pages.map((page) => page.html);
181+
};
182+
const textEdit = String.raw`{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}
183+
\pard\f0\fs24 \cf0 First\
184+
Second\
185+
\
186+
Third}`;
187+
const expected = html(
188+
String.raw`{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\pard\f0\fs24 \cf0 First\par Second\par \par Third}`,
189+
);
190+
expect(html(textEdit)).toEqual(expected);
191+
expect(html(textEdit.replaceAll("\n", "\r\n"))).toEqual(expected);
192+
});
193+
176194
it("preserves rich text page breaks and formatting without splitting hidden destinations", () => {
177195
const result = openRtf(
178196
bytes(String.raw`{\rtf1\b First\page Second\b0{\*\unknown \page hidden}\page Third\page}`),

‎apps/web/src/components/files/extendedDocumentPreview.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,8 @@ export function openRtf(bytes: ArrayBuffer): OfficeWorkerResult {
565565
const match = /^([a-z]+)(-?\d+)? ?/i.exec(source.slice(i));
566566
if (!match) {
567567
if (next === "~") emit("\u00a0");
568+
// A backslash before a line break is \par; TextEdit ends paragraphs this way.
569+
else if ((next === "\n" || next === "\r") && !state.skip) html += "<br>";
568570
i++;
569571
continue;
570572
}

0 commit comments

Comments
 (0)