aboutsummaryrefslogtreecommitdiff
path: root/lib/documents.js
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-04-01 15:24:41 +0100
committerMichael Williamson <mike@zwobble.org>2013-04-01 15:25:53 +0100
commit6fdee5a4b57832682e1c43156b2e075a5552f595 (patch)
treea10d7fd5c2a74102a5314678e55f906af8e0c0f5 /lib/documents.js
parent5c7aa27a92265e0890f3b970ca8102751e0d7e01 (diff)
Move document conversion into document-to-html module
Diffstat (limited to 'lib/documents.js')
-rw-r--r--lib/documents.js78
1 files changed, 0 insertions, 78 deletions
diff --git a/lib/documents.js b/lib/documents.js
index 88f95ba..27190aa 100644
--- a/lib/documents.js
+++ b/lib/documents.js
@@ -1,86 +1,8 @@
-var q = require("q");
-
-var styles = require("./styles");
-var HtmlGenerator = require("./html-generator").HtmlGenerator;
-
-exports.DocumentConverter = DocumentConverter;
exports.Document = Document;
exports.Paragraph = Paragraph;
exports.Run = Run;
exports.Text = Text;
-function DocumentConverter(options) {
- options = options || {};
- var defaultParagraphStyle = options.defaultParagraphStyle || styles.topLevelElement("p");
-
- var paragraphStyleMap = options.paragraphStyleMap || {};
- var runStyleMap = options.runStyleMap || {};
-
- function convertToHtml(document) {
- var html = new HtmlGenerator();
- elementToHtml(document, html);
- html.closeAll();
-
- return q.when({
- html: html.asString()
- });
- }
-
- function convertElements(elements, html) {
- elements.forEach(function(element) {
- elementToHtml(element, html);
- });
- }
-
- function elementToHtml(element, html) {
- var handler = elementConverters[element.type];
- if (handler) {
- handler(element, html);
- }
- }
-
- function convertParagraph(element, html) {
- html.style(styleForParagraph(element));
- convertElements(element.children, html);
- }
-
- function styleForParagraph(element) {
- return paragraphStyleMap[element.properties.styleName] || defaultParagraphStyle;
- }
-
- function convertRun(run, html) {
- var runHtml = new HtmlGenerator();
- if (run.properties.styleName) {
- var style = runStyleMap[run.properties.styleName];
- if (style) {
- runHtml.style(style);
- }
- }
- if (run.properties.isBold) {
- runHtml.push(styles.element("strong"));
- }
- if (run.properties.isItalic) {
- runHtml.push(styles.element("em"));
- }
- convertElements(run.children, runHtml);
- runHtml.closeAll();
- html.append(runHtml);
- }
-
- var elementConverters = {
- "document": function(document, html) {
- convertElements(document.children, html);
- },
- "paragraph": convertParagraph,
- "run": convertRun,
- "text": function(element, html) {
- html.text(element.value);
- }
- };
- return {
- convertToHtml: convertToHtml
- }
-}
function Document(children) {
return {