diff --git a/.nycrc b/.nycrc index 25c38c14ad..c06a0f3774 100644 --- a/.nycrc +++ b/.nycrc @@ -1,9 +1,9 @@ { "check-coverage": true, - "lines": 96.81, - "functions": 93.80, - "branches": 92.63, - "statements": 96.80, + "lines": 97.77, + "functions": 93.89, + "branches": 94.55, + "statements": 97.75, "include": [ "src/**/*.ts" ], diff --git a/demo/22-right-to-left-text.ts b/demo/22-right-to-left-text.ts index 2c3984fb46..4ee344391c 100644 --- a/demo/22-right-to-left-text.ts +++ b/demo/22-right-to-left-text.ts @@ -1,7 +1,7 @@ // This demo shows right to left for special languages // Import from 'docx' rather than '../build' if you install from npm import * as fs from "fs"; -import { Document, Packer, Paragraph, TextRun } from "../build"; +import { Document, Packer, Paragraph, Table, TableCell, TableRow, TextRun } from "../build"; const doc = new Document(); @@ -36,6 +36,31 @@ doc.addSection({ }), ], }), + new Table({ + visuallyRightToLeft: true, + rows: [ + new TableRow({ + children: [ + new TableCell({ + children: [new Paragraph("שלום עולם")], + }), + new TableCell({ + children: [], + }), + ], + }), + new TableRow({ + children: [ + new TableCell({ + children: [], + }), + new TableCell({ + children: [new Paragraph("שלום עולם")], + }), + ], + }), + ], + }), ], }); diff --git a/src/file/paragraph/formatting/bidirectional.spec.ts b/src/file/paragraph/formatting/bidirectional.spec.ts new file mode 100644 index 0000000000..a197ada54e --- /dev/null +++ b/src/file/paragraph/formatting/bidirectional.spec.ts @@ -0,0 +1,15 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { Bidirectional } from "./bidirectional"; + +describe("Bidirectional", () => { + it("should create", () => { + const bidirectional = new Bidirectional(); + const tree = new Formatter().format(bidirectional); + expect(tree).to.deep.equal({ + "w:bidi": {}, + }); + }); +}); diff --git a/src/file/table/table-properties/table-properties.spec.ts b/src/file/table/table-properties/table-properties.spec.ts index b06aadbe4b..77205e70db 100644 --- a/src/file/table/table-properties/table-properties.spec.ts +++ b/src/file/table/table-properties/table-properties.spec.ts @@ -141,4 +141,20 @@ describe("TableProperties", () => { }); }); }); + + describe("#Set Virtual Right to Left", () => { + it("sets the alignment of the table", () => { + const tp = new TableProperties({ + visuallyRightToLeft: true, + }); + const tree = new Formatter().format(tp); + expect(tree).to.deep.equal({ + "w:tblPr": [ + { + "w:bidiVisual": {}, + }, + ], + }); + }); + }); }); diff --git a/src/file/table/table-properties/table-properties.ts b/src/file/table/table-properties/table-properties.ts index 7682c29cb0..de210a90ae 100644 --- a/src/file/table/table-properties/table-properties.ts +++ b/src/file/table/table-properties/table-properties.ts @@ -9,6 +9,7 @@ import { ITableCellMarginOptions, TableCellMargin } from "./table-cell-margin"; import { ITableFloatOptions, TableFloatProperties } from "./table-float-properties"; import { TableLayout, TableLayoutType } from "./table-layout"; import { PreferredTableWidth } from "./table-width"; +import { VisuallyRightToLeft } from "./visually-right-to-left"; export interface ITablePropertiesOptions { readonly width?: { @@ -21,6 +22,7 @@ export interface ITablePropertiesOptions { readonly shading?: ITableShadingAttributesProperties; readonly alignment?: AlignmentType; readonly cellMargin?: ITableCellMarginOptions; + readonly visuallyRightToLeft?: boolean; } export class TableProperties extends IgnoreIfEmptyXmlComponent { @@ -52,5 +54,9 @@ export class TableProperties extends IgnoreIfEmptyXmlComponent { if (options.shading) { this.root.push(new TableShading(options.shading)); } + + if (options.visuallyRightToLeft) { + this.root.push(new VisuallyRightToLeft()); + } } } diff --git a/src/file/table/table-properties/visually-right-to-left.spec.ts b/src/file/table/table-properties/visually-right-to-left.spec.ts new file mode 100644 index 0000000000..792c90194b --- /dev/null +++ b/src/file/table/table-properties/visually-right-to-left.spec.ts @@ -0,0 +1,14 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; +import { VisuallyRightToLeft } from "./visually-right-to-left"; + +describe("VisuallyRightToLeft", () => { + it("should create", () => { + const visuallyRightToLeft = new VisuallyRightToLeft(); + const tree = new Formatter().format(visuallyRightToLeft); + expect(tree).to.deep.equal({ + "w:bidiVisual": {}, + }); + }); +}); diff --git a/src/file/table/table-properties/visually-right-to-left.ts b/src/file/table/table-properties/visually-right-to-left.ts new file mode 100644 index 0000000000..c0598a5a26 --- /dev/null +++ b/src/file/table/table-properties/visually-right-to-left.ts @@ -0,0 +1,8 @@ +// https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_bidiVisual_topic_ID0EOXIQ.html +import { XmlComponent } from "file/xml-components"; + +export class VisuallyRightToLeft extends XmlComponent { + constructor() { + super("w:bidiVisual"); + } +} diff --git a/src/file/table/table.ts b/src/file/table/table.ts index 74928f5c18..3aadf0b28e 100644 --- a/src/file/table/table.ts +++ b/src/file/table/table.ts @@ -36,6 +36,7 @@ export interface ITableOptions { readonly layout?: TableLayoutType; readonly borders?: ITableBordersOptions; readonly alignment?: AlignmentType; + readonly visuallyRightToLeft?: boolean; } export class Table extends XmlComponent { @@ -48,6 +49,7 @@ export class Table extends XmlComponent { layout, borders, alignment, + visuallyRightToLeft, }: ITableOptions) { super("w:tbl"); @@ -76,6 +78,7 @@ export class Table extends XmlComponent { type: marginUnitType, }, }, + visuallyRightToLeft, }), );