aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorCraig Leinoff <leinoff@un.org>2014-01-06 18:11:33 -0500
committerCraig Leinoff <leinoff@un.org>2014-01-06 18:11:33 -0500
commitd9fbde9f0b200da41888df0189e0b83f983ed46a (patch)
treea7a1c0fa4e0836f4599c3f04641853d3a548eb45 /lib
parent24b0789dfacffd38fc16724ea1b2b8a14b49b29d (diff)
Adding heuristicis processing as separate step.
Diffstat (limited to 'lib')
-rw-r--r--lib/document-xml-reader.js3
-rw-r--r--lib/heuristics-processor.js28
-rw-r--r--lib/index.js9
3 files changed, 37 insertions, 3 deletions
diff --git a/lib/document-xml-reader.js b/lib/document-xml-reader.js
index 1f32597..0dcd624 100644
--- a/lib/document-xml-reader.js
+++ b/lib/document-xml-reader.js
@@ -68,9 +68,6 @@ function DocumentXmlReader(relationships, contentTypes, docxFile, numbering) {
var alignElement = element.first("w:jc");
if (alignElement) {
properties.alignment = alignElement.attributes["w:val"];
- if (properties.alignment == 'center' && !properties.styleName) {
- properties.styleName = "CenteredHeading";
- }
}
var numberingPropertiesElement = element.first("w:numPr");
if (numberingPropertiesElement) {
diff --git a/lib/heuristics-processor.js b/lib/heuristics-processor.js
new file mode 100644
index 0000000..1c49f9d
--- /dev/null
+++ b/lib/heuristics-processor.js
@@ -0,0 +1,28 @@
+exports.HeuristicsProcessor = HeuristicsProcessor;
+
+var q = require("q");
+
+function HeuristicsProcessor() {
+ function processHeuristics(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]);
+ break;
+ }
+ }
+ return document;
+ }
+
+ function processParagraph(element) {
+ if (element.alignment == 'center' && !element.styleName) {
+ element.styleName = "CenteredHeading";
+ }
+ return element;
+ }
+
+ return {
+ processHeuristics: processHeuristics
+ }
+} \ No newline at end of file
diff --git a/lib/index.js b/lib/index.js
index 4c35f31..65ec467 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,4 +1,5 @@
var docxReader = require("./docx-reader");
+var HeuristicsProcessor = require("./heuristics-processor").HeuristicsProcessor;
var DocumentConverter = require("./document-to-html").DocumentConverter;
var htmlPaths = require("./html-paths");
var documentMatchers = require("./document-matchers");
@@ -38,6 +39,9 @@ Converter.prototype.convertToHtml = function(inputOptions) {
var options = this._options;
return read(inputOptions)
.then(function(documentResult) {
+ return processHeuristics(documentResult);
+ })
+ .then(function(documentResult) {
return convertDocumentToHtml(documentResult, options);
});
}
@@ -51,6 +55,11 @@ function read(inputOptions) {
return docxReader.read(inputOptions);
}
+function processHeuristics(documentResult) {
+ var heuristicsProcessor = new HeuristicsProcessor();
+ return heuristicsProcessor.processHeuristics(documentResult);
+}
+
function convertDocumentToHtml(documentResult, options) {
var documentConverter = new DocumentConverter(options);
return documentResult.flatMapThen(function(document) {