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:
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user