diff options
| author | Craig Leinoff <leinoff@un.org> | 2014-01-07 14:10:38 -0500 |
|---|---|---|
| committer | Craig Leinoff <leinoff@un.org> | 2014-01-07 14:10:38 -0500 |
| commit | 05e67a227cabe6e2b0ddefae13570465b5de7ce4 (patch) | |
| tree | 8ec8e138ee4f33fca390171050d3b8f7cb2d559b /lib | |
| parent | 3a875e79c03731cb761e040e0647348a8df0a67f (diff) | |
Factoring out style-applicator.js to enduser.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/index.js | 22 | ||||
| -rw-r--r-- | lib/style-applicator.js | 30 |
2 files changed, 5 insertions, 47 deletions
diff --git a/lib/index.js b/lib/index.js index bf12eb0..f32844f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,5 +1,4 @@ var docxReader = require("./docx-reader"); -var StyleApplicator = require("./style-applicator").StyleApplicator; var DocumentConverter = require("./document-to-html").DocumentConverter; var htmlPaths = require("./html-paths"); var documentMatchers = require("./document-matchers"); @@ -27,10 +26,7 @@ var standardOptions = exports.standardOptions = { style("p:ordered-list(3) => ul|ol > li > ul|ol > li > ol > li:fresh"), style("p:ordered-list(4) => ul|ol > li > ul|ol > li > ul|ol > li > ol > li:fresh"), style("p:ordered-list(5) => ul|ol > li > ul|ol > li > ul|ol > li > ul|ol > li > ol > li:fresh") - ], - styleApplicator: { - alignment: true - } + ] }; function Converter(options) { @@ -41,14 +37,11 @@ Converter.prototype.convertToHtml = function(inputOptions) { var options = this._options; return read(inputOptions) .then(function(documentResult) { - var styleApplicatorEnabled = false; - for (var optionName in options.styleApplicator) { - if (options.styleApplicator[optionName] == true) { - styleApplicatorEnabled = true; - } + if (options.transformDocument) { + return options.transformDocument(documentResult); } - if (styleApplicatorEnabled == true) { - return applyStyles(documentResult, options); + else { + return documentResult; } }) .then(function(documentResult) { @@ -65,11 +58,6 @@ function read(inputOptions) { return docxReader.read(inputOptions); } -function applyStyles(documentResult, options) { - var styleApplicator = new StyleApplicator(options); - return styleApplicator.processDocumentStyles(documentResult); -} - function convertDocumentToHtml(documentResult, options) { var documentConverter = new DocumentConverter(options); return documentResult.flatMapThen(function(document) { diff --git a/lib/style-applicator.js b/lib/style-applicator.js deleted file mode 100644 index d6d909d..0000000 --- a/lib/style-applicator.js +++ /dev/null @@ -1,30 +0,0 @@ -exports.StyleApplicator = StyleApplicator; - -function StyleApplicator(options) { - styleApplicatorOptions = options.styleApplicator || {}; - - function processDocumentStyles(document) { - for (var i = 0; i < document.value.children.length; i++) { - var element = document.value.children[i]; - switch (element.type) { - case 'paragraph': - document.value.children[i] = processParagraphStyles(document.value.children[i]); - break; - } - } - return document; - } - - function processParagraphStyles(element) { - if (!element.styleName) { - if (styleApplicatorOptions.alignment && element.alignment) { - element.styleName = element.alignment+"Aligned"; - } - } - return element; - } - - return { - processDocumentStyles: processDocumentStyles - } -}
\ No newline at end of file |
