aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-01-07 22:32:52 +0000
committerMichael Williamson <mike@zwobble.org>2014-01-07 22:32:52 +0000
commit4510e66c6426c88868f74a948123eb48a302d487 (patch)
tree48bbc31862b581e594351e7acb0793dafc42e506
parentbfc33eec2b0a22e4bb0ee2412ec22df636134330 (diff)
Allow default style map to be disabled
-rw-r--r--README.md31
-rw-r--r--lib/options-reader.js6
-rw-r--r--tests/options-reader.tests.js8
3 files changed, 21 insertions, 24 deletions
diff --git a/README.md b/README.md
index 135c7bf..d353e26 100644
--- a/README.md
+++ b/README.md
@@ -67,32 +67,19 @@ var options = {
mammoth.convertToHtml({path: "path/to/document.docx"}, options);
```
-To more easily support style mappings stored in text files,
-`styleMap` can also be a string.
-Each non-blank line is treated as a separate style mapping:
+User-defined style mappings are used in preference to the default style mappings.
+To stop using the default style mappings altogether,
+set `options.includeDefaultStyleMap` to `false`:
```javascript
var options = {
- styleMap: "p.SectionTitle => h1:fresh\n" +
- "p.SubSectionTitle => h2:fresh"
-};
-```
-
-To extend the standard style map:
-
-```javascript
-var mammoth = require("mammoth");
-var style = mammoth.style;
-
-var customStyles = [
- style("p.AsideHeading => div.aside > h2:fresh"),
- style("p.AsideText => div.aside > p:fresh")
-];
-
-var options = {
- styleMap: customStyles.concat(mammoth.standardOptions.styleMap)
+ styleMap: [
+ style("p.SectionTitle => h1:fresh"),
+ style("p.SubSectionTitle => h2:fresh")
+ ],
+ includeDefaultStyleMap: false
+
};
-mammoth.convertToHtml({path: "path/to/document.docx"}, options);
```
### API
diff --git a/lib/options-reader.js b/lib/options-reader.js
index fa215f4..687eb92 100644
--- a/lib/options-reader.js
+++ b/lib/options-reader.js
@@ -23,14 +23,16 @@ var standardOptions = exports._standardOptions = {
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
+ transformDocument: identity,
+ includeDefaultStyleMap: true
};
function readOptions(options) {
options = options || {};
var fullOptions = extend(standardOptions, options);
- fullOptions.styleMap = readStyleMap(options).concat(standardOptions.styleMap);
+ fullOptions.styleMap = readStyleMap(options)
+ .concat(fullOptions.includeDefaultStyleMap ? standardOptions.styleMap : []);
return fullOptions;
}
diff --git a/tests/options-reader.tests.js b/tests/options-reader.tests.js
index 073b3a5..ea2728d 100644
--- a/tests/options-reader.tests.js
+++ b/tests/options-reader.tests.js
@@ -22,6 +22,14 @@ describe('readOptions', function() {
assert.deepEqual(style("p.SectionTitle => h2"), options.styleMap[0]);
assert.deepEqual(standardOptions.styleMap, options.styleMap.slice(1));
});
+
+ it('custom style mappings are ignored if includeDefaultStyleMap is false', function() {
+ var options = readOptions({
+ styleMap: "p.SectionTitle => h2",
+ includeDefaultStyleMap: false
+ });
+ assert.deepEqual([style("p.SectionTitle => h2")], options.styleMap);
+ });
});
function last(array) {