diff options
| author | Michael Williamson <mike@zwobble.org> | 2014-07-05 19:45:24 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2014-07-05 19:45:24 +0100 |
| commit | 377e08477c8dce941b2d1504899123274e0c3e80 (patch) | |
| tree | 2a0381fc7e499aa1a5d3a6eab52448a25913716a /lib/document-to-html.js | |
| parent | 936b74f2d0415dd73fa6471eea4daf6b32b07051 (diff) | |
Add conversion of tables to HTML
Diffstat (limited to 'lib/document-to-html.js')
| -rw-r--r-- | lib/document-to-html.js | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js index fe601bd..6c954e6 100644 --- a/lib/document-to-html.js +++ b/lib/document-to-html.js @@ -213,7 +213,55 @@ function DocumentConversion(options) { } }); }, - "image": options.convertImage || defaultConvertImage + "image": options.convertImage || defaultConvertImage, + "table": function(element, html, messages, callback) { + html.closeAll(); + html.open(htmlPaths.element("table")); + convertElements(element.children, html, messages, function(err) { + if (err) { + callback(err); + } else { + html.close(); + callback(); + } + }); + }, + "tableRow": function(element, html, messages, callback) { + html.open(htmlPaths.element("tr")); + convertElements(element.children, html, messages, function(err) { + if (err) { + callback(err); + } else { + html.close(); + callback(); + } + }); + }, + "tableCell": function(element, html, messages, callback) { + html.open(htmlPaths.element("td")); + + async.map(element.children, function(child, callback) { + var cellHtml = new HtmlGenerator(); + elementToHtml(child, cellHtml, messages, function(error) { + if (error) { + callback(error); + } else { + cellHtml.closeAll(); + callback(null, cellHtml); + } + }); + }, function(error, childrenHtml) { + if (error) { + callback(error); + } else { + childrenHtml.forEach(function(childHtml) { + html.append(childHtml); + }); + html.close(); + callback(); + } + }); + } }; return { convertToHtml: convertToHtml |
