diff --git a/docx-core/src/reader/xml_element.rs b/docx-core/src/reader/xml_element.rs index f335a6b..0154f5a 100644 --- a/docx-core/src/reader/xml_element.rs +++ b/docx-core/src/reader/xml_element.rs @@ -246,6 +246,8 @@ impl FromStr for XMLElement { "bottom" => Ok(XMLElement::Bottom), "insideH" => Ok(XMLElement::InsideH), "insideV" => Ok(XMLElement::InsideV), + "tl2br" => Ok(XMLElement::Tl2br), + "tr2bl" => Ok(XMLElement::Tr2bl), "tblCellMar" => Ok(XMLElement::TableCellMargin), "tblGrid" => Ok(XMLElement::TableGrid), "tblPrChange" => Ok(XMLElement::TablePropertyChange), diff --git a/docx-wasm/js/json/run.ts b/docx-wasm/js/json/run.ts index e12cbdb..21fd60e 100644 --- a/docx-wasm/js/json/run.ts +++ b/docx-wasm/js/json/run.ts @@ -20,7 +20,7 @@ export type RunPropertyJSON = { italicCs: boolean | null; vanish: boolean | null; spacing: number | null; - TextBorder: TextBorderJSON | null; + textBorder: TextBorderJSON | null; }; export type RunChildJSON = diff --git a/docx-wasm/package.json b/docx-wasm/package.json index 135baad..6cdbd39 100644 --- a/docx-wasm/package.json +++ b/docx-wasm/package.json @@ -1,6 +1,6 @@ { "name": "docx-wasm", - "version": "0.0.171", + "version": "0.0.173", "main": "dist/node/index.js", "browser": "dist/web/index.js", "author": "bokuweb ", diff --git a/docx-wasm/test/__snapshots__/index.test.js.snap b/docx-wasm/test/__snapshots__/index.test.js.snap index e9fef31..d1a0f51 100644 --- a/docx-wasm/test/__snapshots__/index.test.js.snap +++ b/docx-wasm/test/__snapshots__/index.test.js.snap @@ -10754,6 +10754,1005 @@ Object { } `; +exports[`reader should read tr2bl docx 1`] = ` +Object { + "comments": Object { + "comments": Array [], + }, + "commentsExtended": Object { + "children": Array [], + }, + "contentType": Object { + "types": Object { + "/_rels/.rels": "application/vnd.openxmlformats-package.relationships+xml", + "/docProps/app.xml": "application/vnd.openxmlformats-officedocument.extended-properties+xml", + "/docProps/core.xml": "application/vnd.openxmlformats-package.core-properties+xml", + "/word/_rels/document.xml.rels": "application/vnd.openxmlformats-package.relationships+xml", + "/word/comments.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml", + "/word/commentsExtended.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml", + "/word/document.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml", + "/word/fontTable.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml", + "/word/header1.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml", + "/word/numbering.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml", + "/word/settings.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml", + "/word/styles.xml": "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml", + }, + }, + "docProps": Object { + "app": Object {}, + "core": Object { + "config": Object { + "created": null, + "creator": null, + "description": null, + "language": null, + "lastModifiedBy": null, + "modified": null, + "revision": null, + "subject": null, + "title": null, + }, + }, + }, + "document": Object { + "children": Array [ + Object { + "data": Object { + "grid": Array [ + 2829, + 2829, + 2830, + ], + "hasNumbering": false, + "property": Object { + "borders": Object { + "bottom": null, + "insideH": null, + "insideV": null, + "left": null, + "right": null, + "top": null, + }, + "indent": null, + "justification": "left", + "margins": Object { + "bottom": 55, + "left": 54, + "right": 55, + "top": 55, + }, + "style": "a3", + "width": Object { + "width": 0, + "widthType": "Auto", + }, + }, + "rows": Array [ + Object { + "cells": Array [ + Object { + "children": Array [ + Object { + "data": Object { + "children": Array [], + "hasNumbering": false, + "id": "5586561A", + "property": Object { + "alignment": null, + "indent": null, + "lineHeight": null, + "numberingProperty": null, + "runProperty": Object { + "bold": null, + "boldCs": null, + "color": null, + "fonts": null, + "highlight": null, + "italic": null, + "italicCs": null, + "spacing": null, + "sz": null, + "szCs": null, + "textBorder": null, + "underline": null, + "vanish": null, + }, + "style": null, + }, + }, + "type": "paragraph", + }, + ], + "hasNumbering": false, + "property": Object { + "borders": Object { + "bottom": null, + "insideH": null, + "insideV": null, + "left": null, + "right": null, + "tl2br": Object { + "borderType": "single", + "color": "auto", + "position": "tl2br", + "size": 4, + "space": 0, + }, + "top": null, + "tr2bl": null, + }, + "gridSpan": 2, + "shading": null, + "textDirection": null, + "verticalAlign": null, + "verticalMerge": null, + "width": Object { + "width": 5658, + "widthType": "DXA", + }, + }, + }, + Object { + "children": Array [ + Object { + "data": Object { + "children": Array [], + "hasNumbering": false, + "id": "1DA21770", + "property": Object { + "alignment": null, + "indent": null, + "lineHeight": null, + "numberingProperty": null, + "runProperty": Object { + "bold": null, + "boldCs": null, + "color": null, + "fonts": null, + "highlight": null, + "italic": null, + "italicCs": null, + "spacing": null, + "sz": null, + "szCs": null, + "textBorder": null, + "underline": null, + "vanish": null, + }, + "style": null, + }, + }, + "type": "paragraph", + }, + ], + "hasNumbering": false, + "property": Object { + "borders": Object { + "bottom": null, + "insideH": null, + "insideV": null, + "left": null, + "right": null, + "tl2br": null, + "top": null, + "tr2bl": Object { + "borderType": "single", + "color": "auto", + "position": "tr2bl", + "size": 4, + "space": 0, + }, + }, + "gridSpan": null, + "shading": null, + "textDirection": null, + "verticalAlign": null, + "verticalMerge": null, + "width": Object { + "width": 2830, + "widthType": "DXA", + }, + }, + }, + ], + "hasNumbering": false, + "property": Object { + "gridAfter": null, + "heightRule": "atLeast", + "rowHeight": 730, + "widthAfter": null, + }, + }, + Object { + "cells": Array [ + Object { + "children": Array [ + Object { + "data": Object { + "children": Array [], + "hasNumbering": false, + "id": "31861494", + "property": Object { + "alignment": null, + "indent": null, + "lineHeight": null, + "numberingProperty": null, + "runProperty": Object { + "bold": null, + "boldCs": null, + "color": null, + "fonts": null, + "highlight": null, + "italic": null, + "italicCs": null, + "spacing": null, + "sz": null, + "szCs": null, + "textBorder": null, + "underline": null, + "vanish": null, + }, + "style": null, + }, + }, + "type": "paragraph", + }, + ], + "hasNumbering": false, + "property": Object { + "borders": Object { + "bottom": null, + "insideH": null, + "insideV": null, + "left": Object { + "borderType": "dashed", + "color": "auto", + "position": "left", + "size": 4, + "space": 0, + }, + "right": null, + "tl2br": null, + "top": null, + "tr2bl": null, + }, + "gridSpan": null, + "shading": null, + "textDirection": null, + "verticalAlign": null, + "verticalMerge": null, + "width": Object { + "width": 2829, + "widthType": "DXA", + }, + }, + }, + Object { + "children": Array [ + Object { + "data": Object { + "children": Array [], + "hasNumbering": false, + "id": "7FD0387F", + "property": Object { + "alignment": null, + "indent": null, + "lineHeight": null, + "numberingProperty": null, + "runProperty": Object { + "bold": null, + "boldCs": null, + "color": null, + "fonts": null, + "highlight": null, + "italic": null, + "italicCs": null, + "spacing": null, + "sz": null, + "szCs": null, + "textBorder": null, + "underline": null, + "vanish": null, + }, + "style": null, + }, + }, + "type": "paragraph", + }, + ], + "hasNumbering": false, + "property": Object { + "borders": Object { + "bottom": null, + "insideH": null, + "insideV": null, + "left": null, + "right": null, + "tl2br": Object { + "borderType": "single", + "color": "auto", + "position": "tl2br", + "size": 4, + "space": 0, + }, + "top": null, + "tr2bl": Object { + "borderType": "single", + "color": "auto", + "position": "tr2bl", + "size": 4, + "space": 0, + }, + }, + "gridSpan": null, + "shading": null, + "textDirection": null, + "verticalAlign": null, + "verticalMerge": null, + "width": Object { + "width": 2829, + "widthType": "DXA", + }, + }, + }, + Object { + "children": Array [ + Object { + "data": Object { + "children": Array [], + "hasNumbering": false, + "id": "721462F5", + "property": Object { + "alignment": null, + "indent": null, + "lineHeight": null, + "numberingProperty": null, + "runProperty": Object { + "bold": null, + "boldCs": null, + "color": null, + "fonts": null, + "highlight": null, + "italic": null, + "italicCs": null, + "spacing": null, + "sz": null, + "szCs": null, + "textBorder": null, + "underline": null, + "vanish": null, + }, + "style": null, + }, + }, + "type": "paragraph", + }, + ], + "hasNumbering": false, + "property": Object { + "borders": null, + "gridSpan": null, + "shading": null, + "textDirection": null, + "verticalAlign": null, + "verticalMerge": null, + "width": Object { + "width": 2830, + "widthType": "DXA", + }, + }, + }, + ], + "hasNumbering": false, + "property": Object { + "gridAfter": null, + "heightRule": "atLeast", + "rowHeight": null, + "widthAfter": null, + }, + }, + ], + }, + "type": "table", + }, + Object { + "data": Object { + "children": Array [], + "hasNumbering": false, + "id": "1D17E6B2", + "property": Object { + "alignment": null, + "indent": null, + "lineHeight": null, + "numberingProperty": null, + "runProperty": Object { + "bold": null, + "boldCs": null, + "color": null, + "fonts": null, + "highlight": null, + "italic": null, + "italicCs": null, + "spacing": null, + "sz": null, + "szCs": null, + "textBorder": null, + "underline": null, + "vanish": null, + }, + "style": null, + }, + }, + "type": "paragraph", + }, + ], + "hasNumbering": false, + "sectionProperty": Object { + "columns": 425, + "docGrid": Object { + "charSpace": null, + "gridType": "lines", + "linePitch": 360, + }, + "headerReference": Object { + "headerType": "default", + "id": "rId4", + }, + "pageMargin": Object { + "bottom": 1701, + "footer": 992, + "gutter": 0, + "header": 851, + "left": 1701, + "right": 1701, + "top": 1985, + }, + "pageSize": Object { + "h": 16840, + "w": 11900, + }, + "sectionType": null, + }, + }, + "documentRels": Object { + "hasComments": false, + "hasNumberings": false, + "imageIds": Array [], + }, + "fontTable": Object {}, + "header": Object { + "children": Array [], + }, + "media": Array [], + "numberings": Object { + "abstractNums": Array [], + "numberings": Array [], + }, + "rels": Object { + "rels": Array [ + Array [ + "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties", + "rId1", + "docProps/core.xml", + ], + Array [ + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties", + "rId2", + "docProps/app.xml", + ], + Array [ + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", + "rId3", + "word/document.xml", + ], + ], + }, + "settings": Object { + "defaultTabStop": 709, + "docId": "9F52F717-3F03-584C-ACEF-96E0106FA905", + "docVars": Array [], + "zoom": 100, + }, + "styles": Object { + "docDefaults": Object { + "runPropertyDefault": Object { + "runProperty": Object { + "bold": null, + "boldCs": null, + "color": null, + "fonts": null, + "highlight": null, + "italic": null, + "italicCs": null, + "spacing": null, + "sz": 21, + "szCs": 21, + "textBorder": null, + "underline": null, + "vanish": null, + }, + }, + }, + "styles": Array [ + Object { + "basedOn": null, + "name": "Normal", + "paragraphProperty": Object { + "alignment": null, + "indent": null, + "lineHeight": null, + "numberingProperty": null, + "runProperty": Object { + "bold": null, + "boldCs": null, + "color": null, + "fonts": null, + "highlight": null, + "italic": null, + "italicCs": null, + "spacing": null, + "sz": null, + "szCs": null, + "textBorder": null, + "underline": null, + "vanish": null, + }, + "style": null, + }, + "runProperty": Object { + "bold": null, + "boldCs": null, + "color": null, + "fonts": null, + "highlight": null, + "italic": null, + "italicCs": null, + "spacing": null, + "sz": null, + "szCs": null, + "textBorder": null, + "underline": null, + "vanish": null, + }, + "styleId": "a", + "styleType": "paragraph", + "tableProperty": Object { + "borders": Object { + "bottom": Object { + "borderType": "single", + "color": "000000", + "position": "bottom", + "size": 2, + "space": 0, + }, + "insideH": Object { + "borderType": "single", + "color": "000000", + "position": "insideH", + "size": 2, + "space": 0, + }, + "insideV": Object { + "borderType": "single", + "color": "000000", + "position": "insideV", + "size": 2, + "space": 0, + }, + "left": Object { + "borderType": "single", + "color": "000000", + "position": "left", + "size": 2, + "space": 0, + }, + "right": Object { + "borderType": "single", + "color": "000000", + "position": "right", + "size": 2, + "space": 0, + }, + "top": Object { + "borderType": "single", + "color": "000000", + "position": "top", + "size": 2, + "space": 0, + }, + }, + "indent": null, + "justification": "left", + "margins": Object { + "bottom": 55, + "left": 54, + "right": 55, + "top": 55, + }, + "style": null, + "width": Object { + "width": 0, + "widthType": "Auto", + }, + }, + }, + Object { + "basedOn": null, + "name": "Default Paragraph Font", + "paragraphProperty": Object { + "alignment": null, + "indent": null, + "lineHeight": null, + "numberingProperty": null, + "runProperty": Object { + "bold": null, + "boldCs": null, + "color": null, + "fonts": null, + "highlight": null, + "italic": null, + "italicCs": null, + "spacing": null, + "sz": null, + "szCs": null, + "textBorder": null, + "underline": null, + "vanish": null, + }, + "style": null, + }, + "runProperty": Object { + "bold": null, + "boldCs": null, + "color": null, + "fonts": null, + "highlight": null, + "italic": null, + "italicCs": null, + "spacing": null, + "sz": null, + "szCs": null, + "textBorder": null, + "underline": null, + "vanish": null, + }, + "styleId": "a0", + "styleType": "character", + "tableProperty": Object { + "borders": Object { + "bottom": Object { + "borderType": "single", + "color": "000000", + "position": "bottom", + "size": 2, + "space": 0, + }, + "insideH": Object { + "borderType": "single", + "color": "000000", + "position": "insideH", + "size": 2, + "space": 0, + }, + "insideV": Object { + "borderType": "single", + "color": "000000", + "position": "insideV", + "size": 2, + "space": 0, + }, + "left": Object { + "borderType": "single", + "color": "000000", + "position": "left", + "size": 2, + "space": 0, + }, + "right": Object { + "borderType": "single", + "color": "000000", + "position": "right", + "size": 2, + "space": 0, + }, + "top": Object { + "borderType": "single", + "color": "000000", + "position": "top", + "size": 2, + "space": 0, + }, + }, + "indent": null, + "justification": "left", + "margins": Object { + "bottom": 55, + "left": 54, + "right": 55, + "top": 55, + }, + "style": null, + "width": Object { + "width": 0, + "widthType": "Auto", + }, + }, + }, + Object { + "basedOn": null, + "name": "Normal Table", + "paragraphProperty": Object { + "alignment": null, + "indent": null, + "lineHeight": null, + "numberingProperty": null, + "runProperty": Object { + "bold": null, + "boldCs": null, + "color": null, + "fonts": null, + "highlight": null, + "italic": null, + "italicCs": null, + "spacing": null, + "sz": null, + "szCs": null, + "textBorder": null, + "underline": null, + "vanish": null, + }, + "style": null, + }, + "runProperty": Object { + "bold": null, + "boldCs": null, + "color": null, + "fonts": null, + "highlight": null, + "italic": null, + "italicCs": null, + "spacing": null, + "sz": null, + "szCs": null, + "textBorder": null, + "underline": null, + "vanish": null, + }, + "styleId": "a1", + "styleType": "table", + "tableProperty": Object { + "borders": Object { + "bottom": null, + "insideH": null, + "insideV": null, + "left": null, + "right": null, + "top": null, + }, + "indent": null, + "justification": "left", + "margins": Object { + "bottom": 55, + "left": 54, + "right": 55, + "top": 55, + }, + "style": null, + "width": Object { + "width": 0, + "widthType": "Auto", + }, + }, + }, + Object { + "basedOn": null, + "name": "No List", + "paragraphProperty": Object { + "alignment": null, + "indent": null, + "lineHeight": null, + "numberingProperty": null, + "runProperty": Object { + "bold": null, + "boldCs": null, + "color": null, + "fonts": null, + "highlight": null, + "italic": null, + "italicCs": null, + "spacing": null, + "sz": null, + "szCs": null, + "textBorder": null, + "underline": null, + "vanish": null, + }, + "style": null, + }, + "runProperty": Object { + "bold": null, + "boldCs": null, + "color": null, + "fonts": null, + "highlight": null, + "italic": null, + "italicCs": null, + "spacing": null, + "sz": null, + "szCs": null, + "textBorder": null, + "underline": null, + "vanish": null, + }, + "styleId": "a2", + "styleType": "numbering", + "tableProperty": Object { + "borders": Object { + "bottom": Object { + "borderType": "single", + "color": "000000", + "position": "bottom", + "size": 2, + "space": 0, + }, + "insideH": Object { + "borderType": "single", + "color": "000000", + "position": "insideH", + "size": 2, + "space": 0, + }, + "insideV": Object { + "borderType": "single", + "color": "000000", + "position": "insideV", + "size": 2, + "space": 0, + }, + "left": Object { + "borderType": "single", + "color": "000000", + "position": "left", + "size": 2, + "space": 0, + }, + "right": Object { + "borderType": "single", + "color": "000000", + "position": "right", + "size": 2, + "space": 0, + }, + "top": Object { + "borderType": "single", + "color": "000000", + "position": "top", + "size": 2, + "space": 0, + }, + }, + "indent": null, + "justification": "left", + "margins": Object { + "bottom": 55, + "left": 54, + "right": 55, + "top": 55, + }, + "style": null, + "width": Object { + "width": 0, + "widthType": "Auto", + }, + }, + }, + Object { + "basedOn": "a1", + "name": "Table Grid", + "paragraphProperty": Object { + "alignment": null, + "indent": null, + "lineHeight": null, + "numberingProperty": null, + "runProperty": Object { + "bold": null, + "boldCs": null, + "color": null, + "fonts": null, + "highlight": null, + "italic": null, + "italicCs": null, + "spacing": null, + "sz": null, + "szCs": null, + "textBorder": null, + "underline": null, + "vanish": null, + }, + "style": null, + }, + "runProperty": Object { + "bold": null, + "boldCs": null, + "color": null, + "fonts": null, + "highlight": null, + "italic": null, + "italicCs": null, + "spacing": null, + "sz": null, + "szCs": null, + "textBorder": null, + "underline": null, + "vanish": null, + }, + "styleId": "a3", + "styleType": "table", + "tableProperty": Object { + "borders": Object { + "bottom": Object { + "borderType": "single", + "color": "auto", + "position": "bottom", + "size": 4, + "space": 0, + }, + "insideH": Object { + "borderType": "single", + "color": "auto", + "position": "insideH", + "size": 4, + "space": 0, + }, + "insideV": Object { + "borderType": "single", + "color": "auto", + "position": "insideV", + "size": 4, + "space": 0, + }, + "left": Object { + "borderType": "single", + "color": "auto", + "position": "left", + "size": 4, + "space": 0, + }, + "right": Object { + "borderType": "single", + "color": "auto", + "position": "right", + "size": 4, + "space": 0, + }, + "top": Object { + "borderType": "single", + "color": "auto", + "position": "top", + "size": 4, + "space": 0, + }, + }, + "indent": null, + "justification": "left", + "margins": Object { + "bottom": 55, + "left": 54, + "right": 55, + "top": 55, + }, + "style": null, + "width": Object { + "width": 0, + "widthType": "Auto", + }, + }, + }, + ], + }, +} +`; + exports[`writer should write cell shading 1`] = ` " diff --git a/docx-wasm/test/index.test.js b/docx-wasm/test/index.test.js index f5f15fe..acf97c9 100644 --- a/docx-wasm/test/index.test.js +++ b/docx-wasm/test/index.test.js @@ -15,6 +15,13 @@ describe("reader", () => { expect(json).toMatchSnapshot(); }); + test("should read tr2bl docx", () => { + const buffer = readFileSync("../fixtures/tr2bl/tr2bl.docx"); + const json = w.readDocx(buffer); + writeFileSync("../output/tr2bl.json", JSON.stringify(json, null, 2)); + expect(json).toMatchSnapshot(); + }); + test("should read table style docx", () => { const buffer = readFileSync("../fixtures/table_style/table_style.docx"); const json = w.readDocx(buffer); diff --git a/fixtures/tr2bl/tr2bl.docx b/fixtures/tr2bl/tr2bl.docx new file mode 100644 index 0000000..38f1305 Binary files /dev/null and b/fixtures/tr2bl/tr2bl.docx differ