aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-05-06 13:41:20 +0100
committerMichael Williamson <mike@zwobble.org>2013-05-06 13:41:20 +0100
commit4ef34968c720c58c419ee18f0897645049175d7c (patch)
tree88001251a8af6c5f92673a9d64af5742adb9c774
parentb28c1b2fb503e6bd2120c9c665084eb1bbecef32 (diff)
Add mammoth.convertToHtml
-rw-r--r--lib/index.js6
-rw-r--r--tests/mammoth.tests.js14
2 files changed, 19 insertions, 1 deletions
diff --git a/lib/index.js b/lib/index.js
index 097e9ce..8496c4c 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -5,6 +5,7 @@ var documentMatchers = require("./document-matchers");
var style = require("./style-reader").readStyle;
exports.Converter = Converter;
+exports.convertToHtml = convertToHtml;
exports.read = read;
exports.convertDocumentToHtml = convertDocumentToHtml;
exports.htmlPaths = htmlPaths;
@@ -39,6 +40,11 @@ Converter.prototype.convertToHtml = function(inputOptions) {
});
}
+function convertToHtml(input, options) {
+ var converter = new Converter(options);
+ return converter.convertToHtml(input);
+}
+
function read(inputOptions) {
return docxReader.read(inputOptions);
}
diff --git a/tests/mammoth.tests.js b/tests/mammoth.tests.js
index 01afdb9..6f348c2 100644
--- a/tests/mammoth.tests.js
+++ b/tests/mammoth.tests.js
@@ -38,7 +38,7 @@ describe('mammoth', function() {
});
});
- test('options are passed to document converter', function() {
+ test('options are passed to document converter when creating Converter', function() {
var docxFile = createFakeDocxFile({
"word/document.xml": testData("simple/word/document.xml")
});
@@ -50,6 +50,18 @@ describe('mammoth', function() {
});
});
+ test('options are passed to document converter when calling mammoth.convertToHtml', function() {
+ var docxFile = createFakeDocxFile({
+ "word/document.xml": testData("simple/word/document.xml")
+ });
+ var options = {
+ defaultParagraphStyle: htmlPaths.topLevelElement("h1")
+ };
+ return mammoth.convertToHtml({file: docxFile}, options).then(function(result) {
+ assert.equal("<h1>Hello.</h1>", result.value);
+ });
+ });
+
test('inline images are included in output', function() {
var converter = new mammoth.Converter();
var docxPath = path.join(__dirname, "test-data/tiny-picture.docx");