diff options
| author | Michael Williamson <mike@zwobble.org> | 2014-07-06 17:21:21 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2014-07-06 17:21:21 +0100 |
| commit | b134d4dce2bb663091d8fbe14969e046069726e9 (patch) | |
| tree | 300a77c0d7e59e0cf8cff2dddd857a195e2b6dc1 | |
| parent | bb1022a7040e943c7393a9a9d9c79bc2ff8b3925 (diff) | |
Move table conversion functions out of object literal
| -rw-r--r-- | lib/document-to-html.js | 102 |
1 files changed, 54 insertions, 48 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js index ad76eff..d5b46e2 100644 --- a/lib/document-to-html.js +++ b/lib/document-to-html.js @@ -136,6 +136,57 @@ function DocumentConversion(options) { function footnoteUid(id) { return uniquifier + "-" + id; } + + function convertTable(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(); + } + }); + } + + function convertTableRow(element, html, messages, callback) { + html.open(htmlPaths.element("tr")); + convertElements(element.children, html, messages, function(err) { + if (err) { + callback(err); + } else { + html.close(); + callback(); + } + }); + } + + function convertTableCell(element, html, messages, callback) { + html.open(htmlPaths.element("td"), {alwaysWrite: true}); + + 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(); + } + }); + } var elementConverters = { "document": function(document, html, messages, callback) { @@ -214,54 +265,9 @@ function DocumentConversion(options) { }); }, "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"), {alwaysWrite: true}); - - 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(); - } - }); - } + "table": convertTable, + "tableRow": convertTableRow, + "tableCell": convertTableCell }; return { convertToHtml: convertToHtml |
