aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-02-04 18:30:12 +0000
committerMichael Williamson <mike@zwobble.org>2015-02-04 18:30:12 +0000
commit7b1aff9a83f5ca6fcee2e14073f3b0b61fe4733d (patch)
tree4be1e76e2852ae25731d856891a669f0a5efcc50 /lib
parente6ebb8bb83127695084ce7e0fc78047fa0d76de0 (diff)
Create a single function for instantiating HtmlGenerator
Diffstat (limited to 'lib')
-rw-r--r--lib/document-to-html.js15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js
index 695b34c..2b1c227 100644
--- a/lib/document-to-html.js
+++ b/lib/document-to-html.js
@@ -41,9 +41,16 @@ function DocumentConversion(options) {
var styleMap = options.styleMap || [];
+ function createHtmlGenerator() {
+ return new HtmlGenerator({
+ prettyPrint: options.prettyPrint,
+ markdown: options.markdown
+ });
+ }
+
function convertToHtml(document) {
var messages = [];
- var html = new HtmlGenerator({prettyPrint: options.prettyPrint, markdown: options.markdown});
+ var html = createHtmlGenerator();
return promises.nfcall(elementToHtml, document, html, messages).then(function() {
html.closeAll();
@@ -88,7 +95,7 @@ function DocumentConversion(options) {
}
function convertRun(run, html, messages, callback) {
- var runHtml = new HtmlGenerator({ markdown: options.markdown });
+ var runHtml = createHtmlGenerator();
if (run.styleId) {
var style = findStyle(run);
if (style) {
@@ -160,7 +167,7 @@ function DocumentConversion(options) {
html.open(htmlPaths.element("td"), {alwaysWrite: true});
async.map(element.children, function(child, callback) {
- var cellHtml = new HtmlGenerator({ markdown: options.markdown });
+ var cellHtml = createHtmlGenerator();
elementToHtml(child, cellHtml, messages, function(error) {
if (error) {
callback(error);
@@ -251,7 +258,7 @@ function DocumentConversion(options) {
},
"note": function(element, html, messages, callback) {
html.open(htmlPaths.element("li", {id: noteHtmlId(element)}));
- var footnoteHtml = new HtmlGenerator({ markdown: options.markdown });
+ var footnoteHtml = createHtmlGenerator();
convertElements(element.body, footnoteHtml, messages, function(err) {
if (err) {
callback(err);