aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorCraig Leinoff <leinoff@un.org>2014-01-07 11:51:29 -0500
committerCraig Leinoff <leinoff@un.org>2014-01-07 11:51:29 -0500
commitb688f825e40c4bd20d645a9f145e4e445a4f66f0 (patch)
tree3b2aaab0ebb576fed0985bd85e95474bd43e89c8 /lib
parentb3cc8c0c5ce2aa2e556e995d587da5a00c6a3185 (diff)
Renaming heuristics processing code to style applicator code.
Diffstat (limited to 'lib')
-rw-r--r--lib/index.js24
-rw-r--r--lib/style-applicator.js20
2 files changed, 29 insertions, 15 deletions
diff --git a/lib/index.js b/lib/index.js
index 65ec467..bf12eb0 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,5 +1,5 @@
var docxReader = require("./docx-reader");
-var HeuristicsProcessor = require("./heuristics-processor").HeuristicsProcessor;
+var StyleApplicator = require("./style-applicator").StyleApplicator;
var DocumentConverter = require("./document-to-html").DocumentConverter;
var htmlPaths = require("./html-paths");
var documentMatchers = require("./document-matchers");
@@ -17,7 +17,6 @@ var standardOptions = exports.standardOptions = {
style("p.Heading2 => h2:fresh"),
style("p.Heading3 => h3:fresh"),
style("p.Heading4 => h4:fresh"),
- style("p.CenteredHeading => h2.centered:fresh"),
style("p:unordered-list(1) => ul > li:fresh"),
style("p:unordered-list(2) => ul|ol > li > ul > li:fresh"),
style("p:unordered-list(3) => ul|ol > li > ul|ol > li > ul > li:fresh"),
@@ -28,7 +27,10 @@ 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) {
@@ -39,7 +41,15 @@ Converter.prototype.convertToHtml = function(inputOptions) {
var options = this._options;
return read(inputOptions)
.then(function(documentResult) {
- return processHeuristics(documentResult);
+ var styleApplicatorEnabled = false;
+ for (var optionName in options.styleApplicator) {
+ if (options.styleApplicator[optionName] == true) {
+ styleApplicatorEnabled = true;
+ }
+ }
+ if (styleApplicatorEnabled == true) {
+ return applyStyles(documentResult, options);
+ }
})
.then(function(documentResult) {
return convertDocumentToHtml(documentResult, options);
@@ -55,9 +65,9 @@ function read(inputOptions) {
return docxReader.read(inputOptions);
}
-function processHeuristics(documentResult) {
- var heuristicsProcessor = new HeuristicsProcessor();
- return heuristicsProcessor.processHeuristics(documentResult);
+function applyStyles(documentResult, options) {
+ var styleApplicator = new StyleApplicator(options);
+ return styleApplicator.processDocumentStyles(documentResult);
}
function convertDocumentToHtml(documentResult, options) {
diff --git a/lib/style-applicator.js b/lib/style-applicator.js
index 0e3c97d..d6d909d 100644
--- a/lib/style-applicator.js
+++ b/lib/style-applicator.js
@@ -1,26 +1,30 @@
-exports.HeuristicsProcessor = HeuristicsProcessor;
+exports.StyleApplicator = StyleApplicator;
-function HeuristicsProcessor() {
- function processHeuristics(document) {
+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] = processParagraph(document.value.children[i]);
+ document.value.children[i] = processParagraphStyles(document.value.children[i]);
break;
}
}
return document;
}
- function processParagraph(element) {
- if (element.alignment == 'center' && !element.styleName) {
- element.styleName = "CenteredHeading";
+ function processParagraphStyles(element) {
+ if (!element.styleName) {
+ if (styleApplicatorOptions.alignment && element.alignment) {
+ element.styleName = element.alignment+"Aligned";
+ }
}
return element;
}
return {
- processHeuristics: processHeuristics
+ processDocumentStyles: processDocumentStyles
}
} \ No newline at end of file