move the cell-paragraph validation into prepForXml

Instead of forcing table cells to only have a single paragraph as
their content, we now check whether they end in a paragraph (and
insert one if necessary) during #prepForXml
This commit is contained in:
felipe
2017-03-11 10:22:30 +01:00
parent c10b576a3a
commit bd3eb3e214
2 changed files with 78 additions and 13 deletions

View File

@ -86,17 +86,28 @@ class TableRowProperties extends XmlComponent {
}
class TableCell extends XmlComponent {
public content: Paragraph;
private properties: TableCellProperties;
constructor() {
super("w:tc");
this.properties = new TableCellProperties();
this.root.push(this.properties);
// Table cells can have any block-level content, but for now
// we only allow a single paragraph:
this.content = new Paragraph();
this.root.push(this.content);
}
public push(content: Paragraph | Table): TableCell {
this.root.push(content);
return this
}
public prepForXml(): object {
// Cells must end with a paragraph
const retval = super.prepForXml();
const content = retval["w:tc"];
if (!content[content.length - 1]["w:p"]) {
content.push(new Paragraph().prepForXml());
}
return retval
}
}
}