Skip to content

Commit a7dcda0

Browse files
geezoria1337claude
andcommitted
fix(web): rich text previews keep paragraphs that end with a backslash
RTF treats a backslash followed by a carriage return or line feed as \par, and macOS TextEdit ends every paragraph that way. The preview skipped the pair as an unknown control symbol, so a TextEdit document rendered as one run-on paragraph. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8b44f42 commit a7dcda0

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
@@ -189,6 +189,24 @@ describe("document preview contents", () => {
189189
expect(html).not.toContain("https:");
190190
});
191191

192+
it("treats a backslash before a line break as a paragraph break, as TextEdit writes them", () => {
193+
const html = (rtf: string) => {
194+
const result = openRtf(bytes(rtf));
195+
if (result.type !== "document") throw new Error("Expected document");
196+
return result.pages.map((page) => page.html);
197+
};
198+
const textEdit = String.raw`{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}
199+
\pard\f0\fs24 \cf0 First\
200+
Second\
201+
\
202+
Third}`;
203+
const expected = html(
204+
String.raw`{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\pard\f0\fs24 \cf0 First\par Second\par \par Third}`,
205+
);
206+
expect(html(textEdit)).toEqual(expected);
207+
expect(html(textEdit.replaceAll("\n", "\r\n"))).toEqual(expected);
208+
});
209+
192210
it("preserves rich text page breaks and formatting without splitting hidden destinations", () => {
193211
const result = openRtf(
194212
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)