diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-02-04 18:53:02 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-02-04 18:53:02 +0000 |
| commit | 65244218366555756c068b1b8edb37515f6f4e9b (patch) | |
| tree | 57ea7166eaa35c4d3e4b86204d556c0348b5699e | |
| parent | 21ab7c6d791e68e2c3e2884bc5c3ab2455f398d9 (diff) | |
Add CLI argument --output-format
| -rwxr-xr-x | bin/mammoth | 7 | ||||
| -rw-r--r-- | lib/document-to-html.js | 2 | ||||
| -rw-r--r-- | lib/index.js | 3 | ||||
| -rw-r--r-- | lib/main.js | 6 | ||||
| -rw-r--r-- | lib/writers/index.js | 2 | ||||
| -rw-r--r-- | tests/main.tests.js | 7 |
6 files changed, 21 insertions, 6 deletions
diff --git a/bin/mammoth b/bin/mammoth index 1bc0c27..72d2af0 100755 --- a/bin/mammoth +++ b/bin/mammoth @@ -10,12 +10,17 @@ var args = require("nomnom") .option("output-path", { position: 1, type: "string", - help: "Output path for the generated HTML. Images will be stored inline in the HTML. Output is written to stdout if not set." + help: "Output path for the generated document. Images will be stored inline in the output document. Output is written to stdout if not set." }) .option("output-dir", { type: "string", help: "Output directory for generated HTML and images. Images will be stored in separate files. Takes precedence over output-path." }) + .option("output-format", { + default: "html", + choices: ["html", "markdown"], + help: "Output format." + }) .option("style-map", { type: "string", help: "File containg a style map." diff --git a/lib/document-to-html.js b/lib/document-to-html.js index 2b1c227..c068fba 100644 --- a/lib/document-to-html.js +++ b/lib/document-to-html.js @@ -44,7 +44,7 @@ function DocumentConversion(options) { function createHtmlGenerator() { return new HtmlGenerator({ prettyPrint: options.prettyPrint, - markdown: options.markdown + outputFormat: options.outputFormat }); } diff --git a/lib/index.js b/lib/index.js index 29a207a..74f42d0 100644 --- a/lib/index.js +++ b/lib/index.js @@ -5,6 +5,7 @@ var readOptions = require("./options-reader").readOptions; exports.convertToHtml = convertToHtml; exports.convertToMarkdown = convertToMarkdown; +exports.convert = convert; exports.extractRawText = extractRawText; exports.images = require("./images"); exports.transforms = require("./transforms"); @@ -16,7 +17,7 @@ function convertToHtml(input, options) { function convertToMarkdown(input, options) { var markdownOptions = Object.create(options || {}); - markdownOptions.markdown = true; + markdownOptions.outputFormat = "markdown"; return convert(input, markdownOptions); } diff --git a/lib/main.js b/lib/main.js index a9ca14d..4e79747 100644 --- a/lib/main.js +++ b/lib/main.js @@ -9,11 +9,13 @@ function main(argv) { var docxPath = argv["docx-path"]; var outputPath = argv["output-path"]; var outputDir = argv["output-dir"]; + var outputFormat = argv["output-format"]; var styleMapPath = argv["style-map"]; readStyleMap(styleMapPath).then(function(styleMap) { var options = { - styleMap: styleMap + styleMap: styleMap, + outputFormat: outputFormat }; if (outputDir) { @@ -34,7 +36,7 @@ function main(argv) { }); } - return mammoth.convertToHtml({path: docxPath}, options) + return mammoth.convert({path: docxPath}, options) .then(function(result) { var outputStream = outputPath ? fs.createWriteStream(outputPath) : process.stdout; diff --git a/lib/writers/index.js b/lib/writers/index.js index b34d28f..bbc2923 100644 --- a/lib/writers/index.js +++ b/lib/writers/index.js @@ -6,7 +6,7 @@ exports.writer = writer; function writer(options) { options = options || {}; - if (options.markdown) { + if (options.outputFormat === "markdown") { return markdownWriter.writer(); } else { return htmlWriter.writer(options); diff --git a/tests/main.tests.js b/tests/main.tests.js index 633f0bd..8041fbd 100644 --- a/tests/main.tests.js +++ b/tests/main.tests.js @@ -60,6 +60,13 @@ describe("CLI", function() { }); }); }); + + test("--output-format=markdown option generate markdown output", function() { + return runMammoth(testPath("single-paragraph.docx"), "--output-format=markdown").then(function(result) { + assert.equal(result.stderrOutput, ""); + assert.equal(result.output, "Walking on imported air\n\n"); + }); + }); }); |
