Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions apps/web/src/components/files/FilePreviewPanel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,24 @@ describe("document preview contents", () => {
expect(html).not.toContain("https:");
});

it("treats a backslash before a line break as a paragraph break, as TextEdit writes them", () => {
const html = (rtf: string) => {
const result = openRtf(bytes(rtf));
if (result.type !== "document") throw new Error("Expected document");
return result.pages.map((page) => page.html);
};
const textEdit = String.raw`{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}
\pard\f0\fs24 \cf0 First\
Second\
\
Third}`;
const expected = html(
String.raw`{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\pard\f0\fs24 \cf0 First\par Second\par \par Third}`,
);
expect(html(textEdit)).toEqual(expected);
expect(html(textEdit.replaceAll("\n", "\r\n"))).toEqual(expected);
});

it("preserves rich text page breaks and formatting without splitting hidden destinations", () => {
const result = openRtf(
bytes(String.raw`{\rtf1\b First\page Second\b0{\*\unknown \page hidden}\page Third\page}`),
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/components/files/extendedDocumentPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,8 @@ export function openRtf(bytes: ArrayBuffer): OfficeWorkerResult {
const match = /^([a-z]+)(-?\d+)? ?/i.exec(source.slice(i));
if (!match) {
if (next === "~") emit("\u00a0");
// A backslash before a line break is \par; TextEdit ends paragraphs this way.
else if ((next === "\n" || next === "\r") && !state.skip) html += "<br>";
i++;
continue;
}
Expand Down
Loading