diff options
| author | Michael Williamson <mike@zwobble.org> | 2014-07-05 19:56:43 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2014-07-05 19:56:43 +0100 |
| commit | c0654e048359aa7dfbc9d4be4527b9bed3a4447a (patch) | |
| tree | 5f39e6a15c54b1ba99a25fb391202414287adbeb | |
| parent | 91a7928116c5157b451892e586b684744dbe4174 (diff) | |
Always write out table cells, even when empty
| -rw-r--r-- | lib/document-to-html.js | 2 | ||||
| -rw-r--r-- | lib/html-generator.js | 5 | ||||
| -rw-r--r-- | tests/document-to-html.tests.js | 18 |
3 files changed, 22 insertions, 3 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js index 6c954e6..ad76eff 100644 --- a/lib/document-to-html.js +++ b/lib/document-to-html.js @@ -238,7 +238,7 @@ function DocumentConversion(options) { }); }, "tableCell": function(element, html, messages, callback) { - html.open(htmlPaths.element("td")); + html.open(htmlPaths.element("td"), {alwaysWrite: true}); async.map(element.children, function(child, callback) { var cellHtml = new HtmlGenerator(); diff --git a/lib/html-generator.js b/lib/html-generator.js index de0749c..ef0c544 100644 --- a/lib/html-generator.js +++ b/lib/html-generator.js @@ -49,10 +49,13 @@ function HtmlGenerator(options) { return stackElement && stylePart.matchesElement(stackElement); } - function open(htmlPathElement) { + function open(htmlPathElement, options) { var stackElement = Object.create(htmlPathElement); stackElement.written = false; stack.push(stackElement); + if (options && options.alwaysWrite) { + writeAll(); + } } function close() { diff --git a/tests/document-to-html.tests.js b/tests/document-to-html.tests.js index e3f5532..3b3bd9b 100644 --- a/tests/document-to-html.tests.js +++ b/tests/document-to-html.tests.js @@ -198,7 +198,6 @@ describe('DocumentConverter', function() { }); test('docx table is converted to table in HTML', function() { - // TODO: test that empty cells are preserved var table = new documents.Table([ new documents.TableRow([ new documents.TableCell([paragraphOfText("Top left")]), @@ -220,6 +219,23 @@ describe('DocumentConverter', function() { }); }); + test('empty cells are preserved in table', function() { + var table = new documents.Table([ + new documents.TableRow([ + new documents.TableCell([paragraphOfText("")]), + new documents.TableCell([paragraphOfText("Top right")]) + ]) + ]); + var converter = new DocumentConverter(); + + return converter.convertToHtml(table).then(function(result) { + var expectedHtml = "<table>" + + "<tr><td></td><td><p>Top right</p></td></tr>" + + "</table>"; + assert.equal(result.value, expectedHtml); + }); + }); + test('footnote reference is converted to superscript intra-page link', function() { var footnoteReference = new documents.FootnoteReference({ footnoteId: "4", |
