diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-05-12 21:43:09 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-05-12 21:43:09 +0100 |
| commit | 9ecffea916f3117ad4d2484c1674d81862ef726f (patch) | |
| tree | 2cc8dcbf508364ddd1d0c0b628a7a95757ac9727 | |
| parent | 95fbf5b6967671758abe87bdf1559f22474786bf (diff) | |
Actually add support for table cells spanning multiple rows
| -rw-r--r-- | NEWS | 4 | ||||
| -rw-r--r-- | lib/document-to-html.js | 8 | ||||
| -rw-r--r-- | tests/document-to-html.tests.js | 16 |
3 files changed, 27 insertions, 1 deletions
@@ -1,3 +1,7 @@ +# 1.0.3 + +* Actually add support for table cells spanning multiple rows. + # 1.0.2 * Add support for table cells spanning multiple rows. diff --git a/lib/document-to-html.js b/lib/document-to-html.js index 81a887e..e3cb169 100644 --- a/lib/document-to-html.js +++ b/lib/document-to-html.js @@ -202,7 +202,13 @@ function DocumentConversion(options) { function convertTableCell(element, messages, callback) { convertElements(element.children, messages, function(error, children) { - var attributes = element.colSpan === 1 ? {} : {colspan: element.colSpan.toString()}; + var attributes = {}; + if (element.colSpan !== 1) { + attributes.colspan = element.colSpan.toString(); + } + if (element.rowSpan !== 1) { + attributes.rowspan = element.rowSpan.toString(); + } callback(null, Html.freshElement("td", attributes, [ Html.forceWrite, diff --git a/tests/document-to-html.tests.js b/tests/document-to-html.tests.js index 3fcb49e..103b921 100644 --- a/tests/document-to-html.tests.js +++ b/tests/document-to-html.tests.js @@ -417,6 +417,22 @@ describe('DocumentConverter', function() { }); }); + test('table cells are written with rowSpan if not equal to one', function() { + var table = new documents.Table([ + new documents.TableRow([ + new documents.TableCell([], {rowSpan: 2}) + ]) + ]); + var converter = new DocumentConverter(); + + return converter.convertToHtml(table).then(function(result) { + var expectedHtml = "<table>" + + "<tr><td rowspan=\"2\"></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(); |
