diff --git a/src/__tests__/input/whitespaces-4.html b/src/__tests__/input/whitespaces-4.html new file mode 100644 index 0000000..b248d50 --- /dev/null +++ b/src/__tests__/input/whitespaces-4.html @@ -0,0 +1,21 @@ + + +
+ ++ euros +in
+ + \ No newline at end of file diff --git a/src/__tests__/output/whitespaces-4.html b/src/__tests__/output/whitespaces-4.html new file mode 100644 index 0000000..1449f60 --- /dev/null +++ b/src/__tests__/output/whitespaces-4.html @@ -0,0 +1 @@ +euros in
\ No newline at end of file diff --git a/src/cleanDocx.test.ts b/src/cleanDocx.test.ts index eb7a85f..c938274 100644 --- a/src/cleanDocx.test.ts +++ b/src/cleanDocx.test.ts @@ -45,4 +45,11 @@ describe('cleanDocx', () => { const result = cleanDocx(html, MOCK_RTF); expect(result).toBe(expected); }); + + it('Preserves newline-only spans', () => { + const html = readTestFile('input/whitespaces-4.html'); + const expected = readTestFile('output/whitespaces-4.html'); + const result = cleanDocx(html, MOCK_RTF); + expect(result).toBe(expected); + }); }); diff --git a/src/lib/cleanEmptyElements.ts b/src/lib/cleanEmptyElements.ts index 63cbe28..2a1faa4 100644 --- a/src/lib/cleanEmptyElements.ts +++ b/src/lib/cleanEmptyElements.ts @@ -3,7 +3,7 @@ import { traverseElements } from './traverseElements'; const ALLOWED_EMPTY_ELEMENTS = ['BR', 'IMG']; function isEmpty(element: Element): boolean { - return !ALLOWED_EMPTY_ELEMENTS.includes(element.nodeName) && !element.innerHTML.trim(); + return !ALLOWED_EMPTY_ELEMENTS.includes(element.nodeName) && !element.innerHTML; } function removeIfEmpty(element: Element): void {