Merge pull request #282 from filippomuscolino/fix/table-width

Fix: table width in percentage should include '%'
This commit is contained in:
Dolan
2019-03-06 13:52:49 +00:00
committed by GitHub
2 changed files with 3 additions and 2 deletions

View File

@ -15,6 +15,7 @@ class TableWidthAttributes extends XmlAttributeComponent<ITableWidth> {
export class PreferredTableWidth extends XmlComponent { export class PreferredTableWidth extends XmlComponent {
constructor(type: WidthType, w: number) { constructor(type: WidthType, w: number) {
super("w:tblW"); super("w:tblW");
this.root.push(new TableWidthAttributes({ type, w })); const width: number | string = type === WidthType.PERCENTAGE ? `${w}%` : w;
this.root.push(new TableWidthAttributes({ type: type, w: width }));
} }
} }

View File

@ -200,7 +200,7 @@ describe("Table", () => {
.which.is.an("array") .which.is.an("array")
.with.has.length.at.least(1); .with.has.length.at.least(1);
expect(tree["w:tbl"][0]).to.deep.equal({ expect(tree["w:tbl"][0]).to.deep.equal({
"w:tblPr": [DEFAULT_TABLE_PROPERTIES, { "w:tblW": [{ _attr: { "w:type": "pct", "w:w": 1000 } }] }], "w:tblPr": [DEFAULT_TABLE_PROPERTIES, { "w:tblW": [{ _attr: { "w:type": "pct", "w:w": "1000%" } }] }],
}); });
}); });