aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-01-07 22:15:00 +0000
committerMichael Williamson <mike@zwobble.org>2014-01-07 22:15:00 +0000
commitb0bc37e59cb521890be25015a66a1ae5d4f5c6f7 (patch)
treed9b07722ae3551da7f87939a0bc90ae1220610a0 /lib
parentceb3e9770eaf466710a93c0a66daa11f2721c9df (diff)
Move options reading to separate module
Diffstat (limited to 'lib')
-rw-r--r--lib/index.js36
-rw-r--r--lib/options-reader.js42
2 files changed, 44 insertions, 34 deletions
diff --git a/lib/index.js b/lib/index.js
index db77d99..b7ee6c3 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,41 +1,13 @@
-var extend = require("xtend");
-var _ = require("underscore");
-
var docxReader = require("./docx-reader");
var DocumentConverter = require("./document-to-html").DocumentConverter;
var style = require("./style-reader").readStyle;
+var readOptions = require("./options-reader").readOptions;
exports.convertToHtml = convertToHtml;
exports.style = style;
-var standardOptions = {
- styleMap: [
- style("p.Heading1 => h1:fresh"),
- style("p.Heading2 => h2:fresh"),
- style("p.Heading3 => h3:fresh"),
- style("p.Heading4 => h4: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"),
- style("p:unordered-list(4) => ul|ol > li > ul|ol > li > ul|ol > li > ul > li:fresh"),
- style("p:unordered-list(5) => ul|ol > li > ul|ol > li > ul|ol > li > ul|ol > li > ul > li:fresh"),
- style("p:ordered-list(1) => ol > li:fresh"),
- style("p:ordered-list(2) => ul|ol > li > ol > li:fresh"),
- 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")
- ],
- transformDocument: identity
-};
function convertToHtml(input, options) {
- options = options || {};
- if (options.styleMap && _.isString(options.styleMap)) {
- options.styleMap = options.styleMap.split("\n").map(function(line) {
- return style(line.trim());
- });
- }
-
- var fullOptions = extend(standardOptions, options);
+ var fullOptions = readOptions(options);
return docxReader.read(input)
.then(function(documentResult) {
@@ -52,7 +24,3 @@ function convertDocumentToHtml(documentResult, options) {
return documentConverter.convertToHtml(document);
});
}
-
-function identity(value) {
- return value;
-}
diff --git a/lib/options-reader.js b/lib/options-reader.js
new file mode 100644
index 0000000..caf4fe5
--- /dev/null
+++ b/lib/options-reader.js
@@ -0,0 +1,42 @@
+exports.readOptions = readOptions;
+
+var extend = require("xtend");
+var _ = require("underscore");
+var style = require("./style-reader").readStyle;
+
+
+var standardOptions = {
+ styleMap: [
+ style("p.Heading1 => h1:fresh"),
+ style("p.Heading2 => h2:fresh"),
+ style("p.Heading3 => h3:fresh"),
+ style("p.Heading4 => h4: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"),
+ style("p:unordered-list(4) => ul|ol > li > ul|ol > li > ul|ol > li > ul > li:fresh"),
+ style("p:unordered-list(5) => ul|ol > li > ul|ol > li > ul|ol > li > ul|ol > li > ul > li:fresh"),
+ style("p:ordered-list(1) => ol > li:fresh"),
+ style("p:ordered-list(2) => ul|ol > li > ol > li:fresh"),
+ 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")
+ ],
+ transformDocument: identity
+};
+
+function readOptions(options) {
+ options = options || {};
+ if (options.styleMap && _.isString(options.styleMap)) {
+ options.styleMap = options.styleMap.split("\n").map(function(line) {
+ return style(line.trim());
+ });
+ }
+
+ return extend(standardOptions, options);
+}
+
+
+function identity(value) {
+ return value;
+}