Skip to content

Commit 3690c6e

Browse files
palmer-clclarencepalmer
andauthored
fix(line-break): make gdocs compatible line breaks (#789)
* fix(line-break): make gdocs compatible line breaks * chore: push rename file --------- Co-authored-by: clarencepalmer <cole@rollprogramcole.com>
1 parent b1fcd4d commit 3690c6e

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

packages/super-editor/src/core/super-converter/exporter.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,13 @@ function translateLineBreak(params) {
945945
}
946946

947947
return {
948-
name: 'w:br',
948+
name: 'w:r',
949+
elements: [
950+
{
951+
name: 'w:br',
952+
attributes,
953+
},
954+
],
949955
attributes,
950956
};
951957
}
14 KB
Binary file not shown.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { getExportedResult } from './export-helpers/index';
2+
3+
describe('LineBreakExporter', () => {
4+
let result;
5+
let body;
6+
7+
beforeAll(async () => {
8+
result = await getExportedResult('line-break.docx');
9+
});
10+
11+
beforeEach(() => {
12+
body = result.elements?.find((el) => el.name === 'w:body');
13+
});
14+
15+
it('exports lineBreak nodes wrapped in w:r (run) elements', () => {
16+
// Grab the first paragraph that contains line breaks
17+
const paragraphWithLineBreaks = body.elements?.find(
18+
(el) =>
19+
el.name === 'w:p' &&
20+
el.elements?.some((run) => run.name === 'w:r' && run.elements?.some((element) => element.name === 'w:br')),
21+
);
22+
23+
expect(paragraphWithLineBreaks).toBeDefined();
24+
expect(paragraphWithLineBreaks.name).toBe('w:p');
25+
26+
const runs = paragraphWithLineBreaks.elements?.filter((el) => el.name === 'w:r') || [];
27+
expect(runs.length).toBeGreaterThan(0);
28+
29+
const runsWithLineBreaks = runs.filter((run) => run.elements?.some((element) => element.name === 'w:br'));
30+
31+
expect(runsWithLineBreaks.length).toBeGreaterThan(0);
32+
33+
// Verify the structure: w:r -> w:br
34+
runsWithLineBreaks.forEach((run) => {
35+
expect(run.name).toBe('w:r');
36+
const lineBreak = run.elements?.find((element) => element.name === 'w:br');
37+
expect(lineBreak).toBeDefined();
38+
expect(lineBreak.name).toBe('w:br');
39+
});
40+
});
41+
});

0 commit comments

Comments
 (0)