diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-05-02 11:41:09 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-05-02 11:41:09 +0100 |
| commit | 245082a0c52ffcab818823ef4e33b89841fbf46d (patch) | |
| tree | f45cde8ba2be07495831c85021c57480440f15fb | |
| parent | 1b54156c52caf3f2e9fe7eef29ba5ce6bd098ded (diff) | |
Add support for table cells spanning multiple columns
| -rw-r--r-- | lib/document-to-html.js | 8 | ||||
| -rw-r--r-- | tests/document-to-html.tests.js | 17 |
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js index c084403..81a887e 100644 --- a/lib/document-to-html.js +++ b/lib/document-to-html.js @@ -201,7 +201,13 @@ function DocumentConversion(options) { } function convertTableCell(element, messages, callback) { - wrapChildrenInFreshElement(element, "td", messages, callback); + convertElements(element.children, messages, function(error, children) { + var attributes = element.colSpan === 1 ? {} : {colspan: element.colSpan.toString()}; + + callback(null, Html.freshElement("td", attributes, [ + Html.forceWrite, + Html.fragment(children)])); + }); } function wrapChildrenInFreshElement(element, wrapElementName, messages, callback) { diff --git a/tests/document-to-html.tests.js b/tests/document-to-html.tests.js index 7760b17..3fcb49e 100644 --- a/tests/document-to-html.tests.js +++ b/tests/document-to-html.tests.js @@ -400,6 +400,23 @@ describe('DocumentConverter', function() { }); }); + test('table cells are written with colSpan if not equal to one', function() { + var table = new documents.Table([ + new documents.TableRow([ + new documents.TableCell([paragraphOfText("Top left")], {colSpan: 2}), + new documents.TableCell([paragraphOfText("Top right")]) + ]) + ]); + var converter = new DocumentConverter(); + + return converter.convertToHtml(table).then(function(result) { + var expectedHtml = "<table>" + + "<tr><td colspan=\"2\"><p>Top left</p></td><td><p>Top right</p></td></tr>" + + "</table>"; + assert.equal(result.value, expectedHtml); + }); + }); + test('line break is converted to <br>', function() { var lineBreak = new documents.LineBreak(); var converter = new DocumentConverter(); |
