aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-04-27 15:58:59 +0100
committerMichael Williamson <mike@zwobble.org>2014-04-27 15:58:59 +0100
commit869d5b2a725db8e41dc447227468c173d5292c18 (patch)
tree176267563f49df0d6804437c19dbbf62134569d2 /lib
parente9d9ab3c03b6018ba8b63335e6aa2b1809a188a5 (diff)
Remove mammoth.styleMapping
Diffstat (limited to 'lib')
-rw-r--r--lib/index.js7
-rw-r--r--lib/options-reader.js48
2 files changed, 27 insertions, 28 deletions
diff --git a/lib/index.js b/lib/index.js
index 6ccfd85..baae852 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,10 +1,9 @@
var docxReader = require("./docx/docx-reader");
var DocumentConverter = require("./document-to-html").DocumentConverter;
-var styleMapping = require("./style-reader").readStyle;
+var readStyle = require("./style-reader").readStyle;
var readOptions = require("./options-reader").readOptions;
exports.convertToHtml = convertToHtml;
-exports.styleMapping = styleMapping;
function convertToHtml(input, options) {
var fullOptions = readOptions(options);
@@ -19,7 +18,9 @@ function convertToHtml(input, options) {
}
function convertDocumentToHtml(documentResult, options) {
- var documentConverter = new DocumentConverter(options);
+ var parsedOptions = Object.create(options);
+ parsedOptions.styleMap = (options.styleMap || []).map(readStyle);
+ var documentConverter = new DocumentConverter(parsedOptions);
return documentResult.flatMapThen(function(document) {
return documentConverter.convertToHtml(document);
});
diff --git a/lib/options-reader.js b/lib/options-reader.js
index 0f7e38e..2c6ad4f 100644
--- a/lib/options-reader.js
+++ b/lib/options-reader.js
@@ -2,29 +2,28 @@ exports.readOptions = readOptions;
var _ = require("underscore");
-var style = require("./style-reader").readStyle;
var standardOptions = exports._standardOptions = {
styleMap: [
- style("p.Heading1 => h1:fresh"),
- style("p.Heading2 => h2:fresh"),
- style("p.Heading3 => h3:fresh"),
- style("p.Heading4 => h4:fresh"),
- style("p[style-name='Heading 1'] => h1:fresh"),
- style("p[style-name='Heading 2'] => h2:fresh"),
- style("p[style-name='Heading 3'] => h3:fresh"),
- style("p[style-name='Heading 4'] => 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")
+ "p.Heading1 => h1:fresh",
+ "p.Heading2 => h2:fresh",
+ "p.Heading3 => h3:fresh",
+ "p.Heading4 => h4:fresh",
+ "p[style-name='Heading 1'] => h1:fresh",
+ "p[style-name='Heading 2'] => h2:fresh",
+ "p[style-name='Heading 3'] => h3:fresh",
+ "p[style-name='Heading 4'] => h4:fresh",
+ "p:unordered-list(1) => ul > li:fresh",
+ "p:unordered-list(2) => ul|ol > li > ul > li:fresh",
+ "p:unordered-list(3) => ul|ol > li > ul|ol > li > ul > li:fresh",
+ "p:unordered-list(4) => ul|ol > li > ul|ol > li > ul|ol > li > ul > li:fresh",
+ "p:unordered-list(5) => ul|ol > li > ul|ol > li > ul|ol > li > ul|ol > li > ul > li:fresh",
+ "p:ordered-list(1) => ol > li:fresh",
+ "p:ordered-list(2) => ul|ol > li > ol > li:fresh",
+ "p:ordered-list(3) => ul|ol > li > ul|ol > li > ol > li:fresh",
+ "p:ordered-list(4) => ul|ol > li > ul|ol > li > ul|ol > li > ol > li:fresh",
+ "p:ordered-list(5) => ul|ol > li > ul|ol > li > ul|ol > li > ul|ol > li > ol > li:fresh"
],
transformDocument: identity,
includeDefaultStyleMap: true
@@ -35,15 +34,14 @@ function readOptions(options) {
var fullOptions = {};
_.extend(fullOptions, standardOptions, options);
- fullOptions.styleMap = readStyleMap(options)
- .concat(fullOptions.includeDefaultStyleMap ? standardOptions.styleMap : []);
+ fullOptions.styleMap = readStyleMap(options.styleMap, fullOptions);
return fullOptions;
}
-function readStyleMap(options) {
- var customStyleMap = readCustomStyleMap(options.styleMap);
- return customStyleMap;
+function readStyleMap(styleMap, options) {
+ var customStyleMap = readCustomStyleMap(styleMap);
+ return customStyleMap.concat(options.includeDefaultStyleMap ? standardOptions.styleMap : []);
}
function readCustomStyleMap(styleMap) {
@@ -51,7 +49,7 @@ function readCustomStyleMap(styleMap) {
return [];
} else if (_.isString(styleMap)) {
return styleMap.split("\n").map(function(line) {
- return style(line.trim());
+ return line.trim();
});
} else {
return styleMap;