From 7d2d346eaad031892ae2c80baf8d87ec533af46f Mon Sep 17 00:00:00 2001
From: Oskar Dahlin <3540971+xpopy@users.noreply.github.com>
Date: Tue, 19 Oct 2021 16:08:10 +0200
Subject: [PATCH] feat: split tables docx (#51)
* Split tables by adding a tiny text after each table
* Update and add test
* Update CHANGELOG
* Fix test
* Fix tests
* format tests
---
packages/abstract-document/CHANGELOG.md | 1 +
.../docx2/test-defs/multiple-tables.tsx | 553 ++++++++++++++++++
.../docx2/test-defs/simple-table.tsx | 369 ++++++------
.../docx2/render.ts | 5 +-
4 files changed, 726 insertions(+), 202 deletions(-)
create mode 100644 packages/abstract-document/src/abstract-document-exporters/__tests__/docx2/test-defs/multiple-tables.tsx
diff --git a/packages/abstract-document/CHANGELOG.md b/packages/abstract-document/CHANGELOG.md
index 48c4f3e7..58334391 100644
--- a/packages/abstract-document/CHANGELOG.md
+++ b/packages/abstract-document/CHANGELOG.md
@@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. The format
- Catch-up of the changelog.
- Parsing svg colors to lower case to work with Svg-To-PdfKit.
+- Splitting tables if they are directly after each other.
### Removed
diff --git a/packages/abstract-document/src/abstract-document-exporters/__tests__/docx2/test-defs/multiple-tables.tsx b/packages/abstract-document/src/abstract-document-exporters/__tests__/docx2/test-defs/multiple-tables.tsx
new file mode 100644
index 00000000..727f3696
--- /dev/null
+++ b/packages/abstract-document/src/abstract-document-exporters/__tests__/docx2/test-defs/multiple-tables.tsx
@@ -0,0 +1,553 @@
+import React from "react";
+import { ExportTestDef } from "../export-test-def";
+import {
+ Paragraph,
+ AbstractDoc,
+ Section,
+ Table,
+ TableRow,
+ TableCell,
+ TextRun,
+} from "../../../../abstract-document-jsx";
+
+export const test: ExportTestDef = {
+ name: "Multiple tables",
+ abstractDocJsx: (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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
+
+
+
+
+
+
+
+
+
+
+
+ `,
+ },
+};
diff --git a/packages/abstract-document/src/abstract-document-exporters/__tests__/docx2/test-defs/simple-table.tsx b/packages/abstract-document/src/abstract-document-exporters/__tests__/docx2/test-defs/simple-table.tsx
index 96b72ae5..696a2e85 100644
--- a/packages/abstract-document/src/abstract-document-exporters/__tests__/docx2/test-defs/simple-table.tsx
+++ b/packages/abstract-document/src/abstract-document-exporters/__tests__/docx2/test-defs/simple-table.tsx
@@ -38,206 +38,173 @@ export const test: ExportTestDef = {
),
expectedDocxZipContexts: {
- "word/document.xml": `
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Hello 1
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Hello 2
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Hello 3
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-`,
+ "word/document.xml": `
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Hello 1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Hello 2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Hello 3
+
+
+
+
+
+
+
+
+
+
+
+ .
+
+
+
+
+
+
+
+
+
+
+
+
+ `,
},
};
diff --git a/packages/abstract-document/src/abstract-document-exporters/docx2/render.ts b/packages/abstract-document/src/abstract-document-exporters/docx2/render.ts
index e6920ae5..f5001092 100644
--- a/packages/abstract-document/src/abstract-document-exporters/docx2/render.ts
+++ b/packages/abstract-document/src/abstract-document-exporters/docx2/render.ts
@@ -147,7 +147,10 @@ function renderSectionElement(
case "Group":
return [...renderGroup(element, parentResources)];
case "Table":
- return [renderTable(element, resources)];
+ return [
+ renderTable(element, resources),
+ new DOCXJS.Paragraph({ children: [new DOCXJS.TextRun({ text: ".", size: 0.000001 })] }),
+ ];
case "PageBreak":
return [
new DOCXJS.Paragraph({