aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-01-06 22:42:12 +0000
committerMichael Williamson <mike@zwobble.org>2014-01-06 22:42:12 +0000
commit53e9f9200a781e488830c3c01ff58f50d667a812 (patch)
tree9781557e2fb37cccf7c4a8477bc871c5ade425c3
parent9dc130b258c8320a3cd12e2afb002ebbe2155e9a (diff)
Allow style map to be an array of styles
-rw-r--r--lib/index.js4
-rw-r--r--tests/mammoth.tests.js14
2 files changed, 16 insertions, 2 deletions
diff --git a/lib/index.js b/lib/index.js
index 0f45501..bec626c 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,10 +1,12 @@
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;
exports.convertToHtml = convertToHtml;
+exports.style = style;
var standardOptions = {
styleMap: [
style("p.Heading1 => h1:fresh"),
@@ -26,7 +28,7 @@ var standardOptions = {
function convertToHtml(input, options) {
options = options || {};
- if (options.styleMap) {
+ if (options.styleMap && _.isString(options.styleMap)) {
options.styleMap = options.styleMap.split("\n").map(function(line) {
return style(line.trim());
});
diff --git a/tests/mammoth.tests.js b/tests/mammoth.tests.js
index 67b95f3..f0d87c8 100644
--- a/tests/mammoth.tests.js
+++ b/tests/mammoth.tests.js
@@ -23,7 +23,7 @@ describe('mammoth', function() {
});
});
- test('options are passed to document converter when creating Converter', function() {
+ test('style map can be expressed as string', function() {
var docxFile = createFakeDocxFile({
"word/document.xml": testData("simple/word/document.xml")
});
@@ -35,6 +35,18 @@ describe('mammoth', function() {
});
});
+ test('style map can be expressed as array of styles', function() {
+ var docxFile = createFakeDocxFile({
+ "word/document.xml": testData("simple/word/document.xml")
+ });
+ var options = {
+ styleMap: [mammoth.style("p => h1")]
+ };
+ return mammoth.convertToHtml({file: docxFile}, options).then(function(result) {
+ assert.equal("<h1>Hello.</h1>", result.value);
+ });
+ });
+
test('options are passed to document converter when calling mammoth.convertToHtml', function() {
var docxFile = createFakeDocxFile({
"word/document.xml": testData("simple/word/document.xml")