diff options
| author | Michael Williamson <mike@zwobble.org> | 2013-05-03 21:30:16 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2013-05-03 21:30:16 +0100 |
| commit | 29152fa7def7c9c46a0aa3c74e67d1a03878a9f5 (patch) | |
| tree | a2483e6b3847ee02b687d5cfc060ffe77905383f /lib | |
| parent | ce01e3ec266ca3cbd96832766174e49337db98f8 (diff) | |
Remove runStyleMap in favour of general styleMap
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/document-to-html.js | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js index 896053f..930e869 100644 --- a/lib/document-to-html.js +++ b/lib/document-to-html.js @@ -13,7 +13,6 @@ function DocumentConverter(options) { var defaultParagraphStyle = options.defaultParagraphStyle || htmlPaths.topLevelElement("p"); var styleMap = options.styleMap || []; - var runStyleMap = options.runStyleMap || {}; function convertToHtml(document) { var messages = []; @@ -47,24 +46,24 @@ function DocumentConverter(options) { } function styleForParagraph(element, messages) { - for (var i = 0; i < styleMap.length; i++) { - if (styleMap[i].from(element)) { - return styleMap[i].to; - } - } + var style = findStyle(element); - if (element.styleName) { - messages.push(results.warning("Unrecognised paragraph style: " + element.styleName)); + if (style) { + return style.to; + } else { + if (element.styleName) { + messages.push(results.warning("Unrecognised paragraph style: " + element.styleName)); + } + return defaultParagraphStyle; } - return defaultParagraphStyle; } function convertRun(run, html, messages, callback) { var runHtml = new HtmlGenerator(); if (run.styleName) { - var style = runStyleMap[run.styleName]; + var style = findStyle(run); if (style) { - runHtml.satisfyPath(style); + runHtml.satisfyPath(style.to); } else { messages.push(results.warning("Unrecognised run style: " + run.styleName)); } @@ -86,6 +85,14 @@ function DocumentConverter(options) { }); } + function findStyle(element) { + for (var i = 0; i < styleMap.length; i++) { + if (styleMap[i].from(element)) { + return styleMap[i]; + } + } + } + function defaultConvertImage(element, html, messages, callback) { element.read("base64").then(function(imageBuffer) { var src = "data:" + element.contentType + ";base64," + imageBuffer; |
