aboutsummaryrefslogtreecommitdiff
path: root/lib/options-reader.js
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-11-19 14:53:45 +0000
committerMichael Williamson <mike@zwobble.org>2016-11-19 14:53:45 +0000
commita7146d18d1183fbe0203025f5e0e6aee5cd3775c (patch)
tree0742a812f4488265ca33ff7221bd97b78c500e53 /lib/options-reader.js
parent599b3f17555a9d0c03ff040df6dca232b152a6f0 (diff)
Include embedded style map when explicit style map is set
Diffstat (limited to 'lib/options-reader.js')
-rw-r--r--lib/options-reader.js131
1 files changed, 66 insertions, 65 deletions
diff --git a/lib/options-reader.js b/lib/options-reader.js
index 4a7db9d..e7e94fd 100644
--- a/lib/options-reader.js
+++ b/lib/options-reader.js
@@ -3,79 +3,81 @@ exports.readOptions = readOptions;
var _ = require("underscore");
+var defaultStyleMap = exports._defaultStyleMap = [
+ "p.Heading1 => h1:fresh",
+ "p.Heading2 => h2:fresh",
+ "p.Heading3 => h3:fresh",
+ "p.Heading4 => h4:fresh",
+ "p.Heading5 => h5:fresh",
+ "p.Heading6 => h6: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[style-name='Heading 5'] => h5:fresh",
+ "p[style-name='Heading 6'] => h6: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[style-name='heading 5'] => h5:fresh",
+ "p[style-name='heading 6'] => h6:fresh",
+
+ "r[style-name='Strong'] => strong",
+
+ "p[style-name='footnote text'] => p",
+ "r[style-name='footnote reference'] =>",
+ "p[style-name='endnote text'] => p",
+ "r[style-name='endnote reference'] =>",
+ "p[style-name='annotation text'] => p",
+ "r[style-name='annotation reference'] =>",
+
+ // LibreOffice
+ "p[style-name='Footnote'] => p",
+ "r[style-name='Footnote anchor'] =>",
+ "p[style-name='Endnote'] => p",
+ "r[style-name='Endnote anchor'] =>",
+
+ "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",
+
+ "r[style-name='Hyperlink'] =>",
+
+ "p[style-name='Normal'] => p:fresh"
+];
var standardOptions = exports._standardOptions = {
- styleMap: [
- "p.Heading1 => h1:fresh",
- "p.Heading2 => h2:fresh",
- "p.Heading3 => h3:fresh",
- "p.Heading4 => h4:fresh",
- "p.Heading5 => h5:fresh",
- "p.Heading6 => h6: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[style-name='Heading 5'] => h5:fresh",
- "p[style-name='Heading 6'] => h6: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[style-name='heading 5'] => h5:fresh",
- "p[style-name='heading 6'] => h6:fresh",
-
- "r[style-name='Strong'] => strong",
-
- "p[style-name='footnote text'] => p",
- "r[style-name='footnote reference'] =>",
- "p[style-name='endnote text'] => p",
- "r[style-name='endnote reference'] =>",
- "p[style-name='annotation text'] => p",
- "r[style-name='annotation reference'] =>",
-
- // LibreOffice
- "p[style-name='Footnote'] => p",
- "r[style-name='Footnote anchor'] =>",
- "p[style-name='Endnote'] => p",
- "r[style-name='Endnote anchor'] =>",
-
- "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",
-
- "r[style-name='Hyperlink'] =>",
-
- "p[style-name='Normal'] => p:fresh"
-
- ],
transformDocument: identity,
- includeDefaultStyleMap: true
+ includeDefaultStyleMap: true,
+ includeEmbeddedStyleMap: true
};
function readOptions(options) {
options = options || {};
- var fullOptions = {};
- _.extend(fullOptions, standardOptions, options);
-
- fullOptions.styleMap = readStyleMap(options.styleMap, fullOptions);
-
- return fullOptions;
+ return _.extend({}, standardOptions, options, {
+ customStyleMap: readStyleMap(options.styleMap),
+ readStyleMap: function() {
+ var styleMap = this.customStyleMap;
+ if (this.includeEmbeddedStyleMap) {
+ styleMap = styleMap.concat(readStyleMap(this.embeddedStyleMap));
+ }
+ if (this.includeDefaultStyleMap) {
+ styleMap = styleMap.concat(defaultStyleMap);
+ }
+ return styleMap;
+ }
+ });
}
-function readStyleMap(styleMap, options) {
- var customStyleMap = readCustomStyleMap(styleMap);
- return customStyleMap.concat(options.includeDefaultStyleMap ? standardOptions.styleMap : []);
-}
-
-function readCustomStyleMap(styleMap) {
+function readStyleMap(styleMap) {
if (!styleMap) {
return [];
} else if (_.isString(styleMap)) {
@@ -91,7 +93,6 @@ function readCustomStyleMap(styleMap) {
}
}
-
function identity(value) {
return value;
}