aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-04-18 20:12:51 +0100
committerMichael Williamson <mike@zwobble.org>2013-04-18 20:12:51 +0100
commitf5e1cbb69b1aae679f8629fe13d0c49778b181d0 (patch)
tree97e918bcec20cabb94f050a924578c0f2ea582d0 /lib
parent554e939ed6f3ce697fca925a333cb9fc14ccbe5a (diff)
Emit warnings if paragraph style is not recognised
Diffstat (limited to 'lib')
-rw-r--r--lib/document-to-html.js43
1 files changed, 24 insertions, 19 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js
index ef39da8..3eefee9 100644
--- a/lib/document-to-html.js
+++ b/lib/document-to-html.js
@@ -16,40 +16,45 @@ function DocumentConverter(options) {
var runStyleMap = options.runStyleMap || {};
function convertToHtml(document) {
+ var messages = [];
var html = new HtmlGenerator();
- return q.nfcall(elementToHtml, document, html).then(function() {
+ return q.nfcall(elementToHtml, document, html, messages).then(function() {
html.closeAll();
- return new results.Result(html.asString(), []);
+ return new results.Result(html.asString(), messages);
});
}
- function convertElements(elements, html, callback) {
+ function convertElements(elements, html, messages, callback) {
async.eachSeries(elements, function(element, callback) {
- return elementToHtml(element, html, callback);
+ return elementToHtml(element, html, messages, callback);
}, callback);
}
- function elementToHtml(element, html, callback) {
+ function elementToHtml(element, html, messages, callback) {
var handler = elementConverters[element.type];
if (handler) {
- handler(element, html, callback);
+ handler(element, html, messages, callback);
} else {
callback();
}
}
- function convertParagraph(element, html, callback) {
- html.satisfyPath(styleForParagraph(element));
- convertElements(element.children, html, callback);
+ function convertParagraph(element, html, messages, callback) {
+ html.satisfyPath(styleForParagraph(element, messages));
+ convertElements(element.children, html, messages, callback);
}
- function styleForParagraph(element) {
- return paragraphStyleMap[element.styleName] || defaultParagraphStyle;
+ function styleForParagraph(element, messages) {
+ var htmlPath = paragraphStyleMap[element.styleName];
+ if (element.styleName && !htmlPath) {
+ messages.push(results.warning("Unrecognised paragraph style: " + element.styleName));
+ }
+ return htmlPath || defaultParagraphStyle;
}
- function convertRun(run, html, callback) {
+ function convertRun(run, html, messages, callback) {
var runHtml = new HtmlGenerator();
if (run.styleName) {
var style = runStyleMap[run.styleName];
@@ -63,7 +68,7 @@ function DocumentConverter(options) {
if (run.isItalic) {
runHtml.open(htmlPaths.element("em"));
}
- convertElements(run.children, runHtml, function(err) {
+ convertElements(run.children, runHtml, messages, function(err) {
if (err) {
callback(err);
} else {
@@ -75,18 +80,18 @@ function DocumentConverter(options) {
}
var elementConverters = {
- "document": function(document, html, callback) {
- convertElements(document.children, html, callback);
+ "document": function(document, html, messages, callback) {
+ convertElements(document.children, html, messages, callback);
},
"paragraph": convertParagraph,
"run": convertRun,
- "text": function(element, html, callback) {
+ "text": function(element, html, messages, callback) {
html.text(element.value);
callback();
},
- "hyperlink": function(element, html, callback) {
+ "hyperlink": function(element, html, messages, callback) {
html.open(htmlPaths.element("a", {href: element.href}));
- convertElements(element.children, html, function(err) {
+ convertElements(element.children, html, messages, function(err) {
if (err) {
callback(err);
} else {
@@ -95,7 +100,7 @@ function DocumentConverter(options) {
}
});
},
- "image": function(element, html, callback) {
+ "image": function(element, html, messages, callback) {
element.read("base64").then(function(imageBuffer) {
// TODO: set alt attribute to wp:inline/wp:docPr/@descr
var src = "data:image/png;base64," + imageBuffer;