@depup/mammoth 1.12.0-depup.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +75 -0
- package/.github/ISSUE_TEMPLATE.md +12 -0
- package/.github/pull_request_template.md +3 -0
- package/.github/workflows/tests.yml +26 -0
- package/LICENSE +22 -0
- package/NEWS +530 -0
- package/README.md +37 -0
- package/bin/mammoth +38 -0
- package/browser/docx/files.js +14 -0
- package/browser/unzip.js +12 -0
- package/changes.json +34 -0
- package/lib/document-to-html.js +469 -0
- package/lib/documents.js +254 -0
- package/lib/docx/body-reader.js +798 -0
- package/lib/docx/comments-reader.js +31 -0
- package/lib/docx/content-types-reader.js +58 -0
- package/lib/docx/document-xml-reader.js +30 -0
- package/lib/docx/docx-reader.js +226 -0
- package/lib/docx/files.js +80 -0
- package/lib/docx/notes-reader.js +28 -0
- package/lib/docx/numbering-xml.js +111 -0
- package/lib/docx/office-xml-reader.js +73 -0
- package/lib/docx/relationships-reader.js +43 -0
- package/lib/docx/style-map.js +75 -0
- package/lib/docx/styles-reader.js +90 -0
- package/lib/docx/uris.js +21 -0
- package/lib/html/ast.js +51 -0
- package/lib/html/index.js +41 -0
- package/lib/html/simplify.js +88 -0
- package/lib/images.js +31 -0
- package/lib/index.d.ts +86 -0
- package/lib/index.js +111 -0
- package/lib/main.js +63 -0
- package/lib/options-reader.js +107 -0
- package/lib/promises.js +42 -0
- package/lib/raw-text.js +14 -0
- package/lib/results.js +72 -0
- package/lib/style-reader.js +365 -0
- package/lib/styles/document-matchers.js +100 -0
- package/lib/styles/html-paths.js +75 -0
- package/lib/styles/parser/tokeniser.js +30 -0
- package/lib/transforms.js +62 -0
- package/lib/underline.js +11 -0
- package/lib/unzip.js +20 -0
- package/lib/writers/html-writer.js +159 -0
- package/lib/writers/index.js +14 -0
- package/lib/writers/markdown-writer.js +163 -0
- package/lib/xml/index.js +8 -0
- package/lib/xml/nodes.js +70 -0
- package/lib/xml/reader.js +69 -0
- package/lib/xml/writer.js +61 -0
- package/lib/xml/xmldom.js +23 -0
- package/lib/zipfile.js +72 -0
- package/mammoth.browser.js +22096 -0
- package/mammoth.browser.min.js +20 -0
- package/package.json +106 -0
- package/test/.eslintrc.json +7 -0
- package/test/document-to-html.tests.js +892 -0
- package/test/docx/body-reader.tests.js +2037 -0
- package/test/docx/comments-reader.tests.js +53 -0
- package/test/docx/content-types-reader.tests.js +45 -0
- package/test/docx/document-matchers.js +42 -0
- package/test/docx/document-xml-reader.tests.js +41 -0
- package/test/docx/docx-reader.tests.js +179 -0
- package/test/docx/files.tests.js +107 -0
- package/test/docx/notes-reader.tests.js +36 -0
- package/test/docx/numbering-xml.tests.js +183 -0
- package/test/docx/office-xml-reader.tests.js +41 -0
- package/test/docx/relationships-reader.tests.js +65 -0
- package/test/docx/style-map.tests.js +113 -0
- package/test/docx/styles-reader.tests.js +143 -0
- package/test/docx/testing.js +12 -0
- package/test/docx/uris.tests.js +22 -0
- package/test/html/simplify.tests.js +141 -0
- package/test/html/write.tests.js +42 -0
- package/test/images.tests.js +112 -0
- package/test/main.tests.js +89 -0
- package/test/mammoth.tests.js +523 -0
- package/test/mocha.opts +1 -0
- package/test/options-reader.tests.js +63 -0
- package/test/raw-text.tests.js +61 -0
- package/test/results.tests.js +15 -0
- package/test/style-reader.tests.js +291 -0
- package/test/styles/document-matchers.tests.js +91 -0
- package/test/styles/html-paths.tests.js +20 -0
- package/test/styles/parser/tokeniser.tests.js +104 -0
- package/test/test-data/comments.docx +0 -0
- package/test/test-data/embedded-style-map.docx +0 -0
- package/test/test-data/empty.docx +0 -0
- package/test/test-data/empty.zip +0 -0
- package/test/test-data/endnotes.docx +0 -0
- package/test/test-data/external-picture.docx +0 -0
- package/test/test-data/footnote-hyperlink.docx +0 -0
- package/test/test-data/footnotes.docx +0 -0
- package/test/test-data/hello.zip +0 -0
- package/test/test-data/hyperlinks/word/_rels/document.xml.rels +10 -0
- package/test/test-data/hyperlinks/word/document.xml +18 -0
- package/test/test-data/simple/word/document.xml +18 -0
- package/test/test-data/simple-list.docx +0 -0
- package/test/test-data/single-paragraph.docx +0 -0
- package/test/test-data/strict-format.docx +0 -0
- package/test/test-data/strikethrough.docx +0 -0
- package/test/test-data/tables.docx +0 -0
- package/test/test-data/text-box.docx +0 -0
- package/test/test-data/tiny-picture-target-base-relative.docx +0 -0
- package/test/test-data/tiny-picture.docx +0 -0
- package/test/test-data/tiny-picture.png +0 -0
- package/test/test-data/underline.docx +0 -0
- package/test/test-data/utf8-bom.docx +0 -0
- package/test/test.js +11 -0
- package/test/testing.js +55 -0
- package/test/transforms.tests.js +125 -0
- package/test/unzip.tests.js +38 -0
- package/test/writers/html-writer.tests.js +133 -0
- package/test/writers/markdown-writer.tests.js +304 -0
- package/test/xml/reader.tests.js +85 -0
- package/test/xml/writer.tests.js +81 -0
- package/test/zipfile.tests.js +61 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
var assert = require("assert");
|
|
2
|
+
|
|
3
|
+
var _ = require("underscore");
|
|
4
|
+
|
|
5
|
+
var test = require("../test")(module);
|
|
6
|
+
var html = require("../../lib/html");
|
|
7
|
+
var htmlPaths = require("../../lib/styles/html-paths");
|
|
8
|
+
|
|
9
|
+
var nonFreshElement = html.nonFreshElement;
|
|
10
|
+
var text = html.text;
|
|
11
|
+
|
|
12
|
+
test("empty text nodes are removed", function() {
|
|
13
|
+
assert.deepEqual(
|
|
14
|
+
simplifyNode(text("")),
|
|
15
|
+
[]
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("elements with no children are removed", function() {
|
|
20
|
+
assert.deepEqual(
|
|
21
|
+
simplifyNode(nonFreshElement("p", {}, [])),
|
|
22
|
+
[]
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("elements only containing empty nodes are removed", function() {
|
|
27
|
+
assert.deepEqual(
|
|
28
|
+
simplifyNode(nonFreshElement("p", {}, [text("")])),
|
|
29
|
+
[]
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("empty children of element are removed", function() {
|
|
34
|
+
assert.deepEqual(
|
|
35
|
+
simplifyNode(nonFreshElement("p", {}, [text("Hello"), text("")])),
|
|
36
|
+
[nonFreshElement("p", {}, [text("Hello")])]
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("empty void elements are not removed", function() {
|
|
41
|
+
assert.deepEqual(
|
|
42
|
+
simplifyNode(nonFreshElement("br", {}, [])),
|
|
43
|
+
[nonFreshElement("br", {}, [])]
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("successive fresh elements are not collapsed", function() {
|
|
48
|
+
var path = htmlPaths.elements([
|
|
49
|
+
htmlPaths.element("p", {}, {fresh: true})
|
|
50
|
+
]);
|
|
51
|
+
var original = concat(
|
|
52
|
+
pathToNodes(path, [text("Hello")]),
|
|
53
|
+
pathToNodes(path, [text(" there")])
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
assert.deepEqual(
|
|
57
|
+
html.simplify(original),
|
|
58
|
+
original);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("successive plain non-fresh elements are collapsed if they have the same tag name", function() {
|
|
62
|
+
var path = htmlPaths.elements([
|
|
63
|
+
htmlPaths.element("p", {}, {fresh: false})
|
|
64
|
+
]);
|
|
65
|
+
assert.deepEqual(
|
|
66
|
+
html.simplify(concat(
|
|
67
|
+
pathToNodes(path, [text("Hello")]),
|
|
68
|
+
pathToNodes(path, [text(" there")])
|
|
69
|
+
)),
|
|
70
|
+
pathToNodes(path, [text("Hello"), text(" there")])
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("non-fresh can collapse into preceding fresh element", function() {
|
|
75
|
+
var freshPath = htmlPaths.elements([
|
|
76
|
+
htmlPaths.element("p", {}, {fresh: true})]);
|
|
77
|
+
var nonFreshPath = htmlPaths.elements([
|
|
78
|
+
htmlPaths.element("p", {}, {fresh: false})]);
|
|
79
|
+
assert.deepEqual(
|
|
80
|
+
html.simplify(concat(
|
|
81
|
+
pathToNodes(freshPath, [text("Hello")]),
|
|
82
|
+
pathToNodes(nonFreshPath, [text(" there")])
|
|
83
|
+
)),
|
|
84
|
+
pathToNodes(freshPath, [text("Hello"), text(" there")])
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("children of collapsed element can collapse with children of another collapsed element", function() {
|
|
89
|
+
assert.deepEqual(
|
|
90
|
+
html.simplify([
|
|
91
|
+
nonFreshElement("blockquote", {}, [nonFreshElement("p", {}, [text("Hello")])]),
|
|
92
|
+
nonFreshElement("blockquote", {}, [nonFreshElement("p", {}, [text("there")])])
|
|
93
|
+
]),
|
|
94
|
+
[nonFreshElement("blockquote", {}, [nonFreshElement("p", {}, [text("Hello"), text("there")])])]
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("empty elements are removed before collapsing", function() {
|
|
99
|
+
var freshPath = htmlPaths.elements([
|
|
100
|
+
htmlPaths.element("p", {}, {fresh: true})]);
|
|
101
|
+
var nonFreshPath = htmlPaths.elements([
|
|
102
|
+
htmlPaths.element("p", {}, {fresh: false})]);
|
|
103
|
+
assert.deepEqual(
|
|
104
|
+
html.simplify(concat(
|
|
105
|
+
pathToNodes(nonFreshPath, [text("Hello")]),
|
|
106
|
+
pathToNodes(freshPath, []),
|
|
107
|
+
pathToNodes(nonFreshPath, [text(" there")])
|
|
108
|
+
)),
|
|
109
|
+
pathToNodes(nonFreshPath, [text("Hello"), text(" there")])
|
|
110
|
+
);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("when separator is present then separator is prepended to collapsed element", function() {
|
|
114
|
+
var unseparatedPath = htmlPaths.elements([
|
|
115
|
+
htmlPaths.element("pre", {}, {fresh: false})
|
|
116
|
+
]);
|
|
117
|
+
var separatedPath = htmlPaths.elements([
|
|
118
|
+
htmlPaths.element("pre", {}, {fresh: false, separator: "\n"})
|
|
119
|
+
]);
|
|
120
|
+
assert.deepEqual(
|
|
121
|
+
html.simplify(concat(
|
|
122
|
+
pathToNodes(unseparatedPath, [text("Hello")]),
|
|
123
|
+
pathToNodes(separatedPath, [text(" the"), text("re")])
|
|
124
|
+
)),
|
|
125
|
+
pathToNodes(unseparatedPath, [text("Hello"), text("\n"), text(" the"), text("re")])
|
|
126
|
+
);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
function simplifyNode(node) {
|
|
130
|
+
return html.simplify([node]);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function concat() {
|
|
134
|
+
return _.flatten(arguments, true);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function pathToNodes(path, nodes) {
|
|
138
|
+
return path.wrap(function() {
|
|
139
|
+
return nodes;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var assert = require("assert");
|
|
2
|
+
|
|
3
|
+
var test = require("../test")(module);
|
|
4
|
+
var html = require("../../lib/html");
|
|
5
|
+
var writers = require("../../lib/writers");
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
test("text is HTML escaped", function() {
|
|
9
|
+
assert.equal(
|
|
10
|
+
generateString(html.text("<>&")),
|
|
11
|
+
"<>&");
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test("double quotes outside of attributes are not escaped", function() {
|
|
15
|
+
assert.equal(
|
|
16
|
+
generateString(html.text('"')),
|
|
17
|
+
'"');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("element attributes are HTML escaped", function() {
|
|
21
|
+
assert.equal(
|
|
22
|
+
generateString(html.freshElement("p", {"x": "<"})),
|
|
23
|
+
'<p x="<"></p>');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("double quotes inside attributes are escaped", function() {
|
|
27
|
+
assert.equal(
|
|
28
|
+
generateString(html.freshElement("p", {"x": '"'})),
|
|
29
|
+
'<p x="""></p>');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("element children are written", function() {
|
|
33
|
+
assert.equal(
|
|
34
|
+
generateString(html.freshElement("p", {}, [html.text("Hello")])),
|
|
35
|
+
'<p>Hello</p>');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
function generateString(node) {
|
|
39
|
+
var writer = writers.writer();
|
|
40
|
+
html.write(writer, [node]);
|
|
41
|
+
return writer.asString();
|
|
42
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
var assert = require("assert");
|
|
2
|
+
|
|
3
|
+
var hamjest = require("hamjest");
|
|
4
|
+
var assertThat = hamjest.assertThat;
|
|
5
|
+
var contains = hamjest.contains;
|
|
6
|
+
var equalTo = hamjest.equalTo;
|
|
7
|
+
var hasProperties = hamjest.hasProperties;
|
|
8
|
+
|
|
9
|
+
var mammoth = require("../");
|
|
10
|
+
var documents = require("../lib/documents");
|
|
11
|
+
var promises = require("../lib/promises");
|
|
12
|
+
|
|
13
|
+
var test = require("./test")(module);
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
test('mammoth.images.inline() should be an alias of mammoth.images.imgElement()', function() {
|
|
17
|
+
assert.ok(mammoth.images.inline === mammoth.images.imgElement);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
test('mammoth.images.dataUri() encodes images in base64', function() {
|
|
22
|
+
var imageBuffer = new Buffer("abc");
|
|
23
|
+
var image = new documents.Image({
|
|
24
|
+
readImage: function(encoding) {
|
|
25
|
+
return promises.when(imageBuffer.toString(encoding));
|
|
26
|
+
},
|
|
27
|
+
contentType: "image/jpeg"
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return mammoth.images.dataUri(image).then(function(result) {
|
|
31
|
+
assertThat(result, contains(
|
|
32
|
+
hasProperties({tag: hasProperties({attributes: {"src": "data:image/jpeg;base64,YWJj"}})})
|
|
33
|
+
));
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
test('mammoth.images.imgElement()', {
|
|
39
|
+
'when element does not have alt text then alt attribute is not set': function() {
|
|
40
|
+
var imageBuffer = new Buffer("abc");
|
|
41
|
+
var image = new documents.Image({
|
|
42
|
+
readImage: function(encoding) {
|
|
43
|
+
return promises.when(imageBuffer.toString(encoding));
|
|
44
|
+
},
|
|
45
|
+
contentType: "image/jpeg"
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
var result = mammoth.images.imgElement(function(image) {
|
|
49
|
+
return {src: "<src>"};
|
|
50
|
+
})(image);
|
|
51
|
+
|
|
52
|
+
return result.then(function(result) {
|
|
53
|
+
assertThat(result, contains(
|
|
54
|
+
hasProperties({
|
|
55
|
+
tag: hasProperties({
|
|
56
|
+
attributes: equalTo({src: "<src>"})
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
));
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
'when element has alt text then alt attribute is set': function() {
|
|
64
|
+
var imageBuffer = new Buffer("abc");
|
|
65
|
+
var image = new documents.Image({
|
|
66
|
+
readImage: function(encoding) {
|
|
67
|
+
return promises.when(imageBuffer.toString(encoding));
|
|
68
|
+
},
|
|
69
|
+
contentType: "image/jpeg",
|
|
70
|
+
altText: "<alt>"
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
var result = mammoth.images.imgElement(function(image) {
|
|
74
|
+
return {src: "<src>"};
|
|
75
|
+
})(image);
|
|
76
|
+
|
|
77
|
+
return result.then(function(result) {
|
|
78
|
+
assertThat(result, contains(
|
|
79
|
+
hasProperties({
|
|
80
|
+
tag: hasProperties({
|
|
81
|
+
attributes: equalTo({alt: "<alt>", src: "<src>"})
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
));
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
'image alt text can be overridden by alt attribute returned from function': function() {
|
|
89
|
+
var imageBuffer = new Buffer("abc");
|
|
90
|
+
var image = new documents.Image({
|
|
91
|
+
readImage: function(encoding) {
|
|
92
|
+
return promises.when(imageBuffer.toString(encoding));
|
|
93
|
+
},
|
|
94
|
+
contentType: "image/jpeg",
|
|
95
|
+
altText: "<alt>"
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
var result = mammoth.images.imgElement(function(image) {
|
|
99
|
+
return {alt: "<alt override>", src: "<src>"};
|
|
100
|
+
})(image);
|
|
101
|
+
|
|
102
|
+
return result.then(function(result) {
|
|
103
|
+
assertThat(result, contains(
|
|
104
|
+
hasProperties({
|
|
105
|
+
tag: hasProperties({
|
|
106
|
+
attributes: equalTo({alt: "<alt override>", src: "<src>"})
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
));
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
var assert = require("assert");
|
|
2
|
+
var child_process = require("child_process"); // eslint-disable-line camelcase
|
|
3
|
+
var path = require("path");
|
|
4
|
+
var fs = require("fs");
|
|
5
|
+
|
|
6
|
+
var temp = require('temp').track();
|
|
7
|
+
|
|
8
|
+
var promises = require("../lib/promises");
|
|
9
|
+
var test = require("./test")(module);
|
|
10
|
+
var testPath = require("./testing").testPath;
|
|
11
|
+
|
|
12
|
+
test("HTML is printed to stdout if output file is not set", function() {
|
|
13
|
+
return runMammoth(testPath("single-paragraph.docx")).then(function(result) {
|
|
14
|
+
assert.equal(result.stderrOutput, "");
|
|
15
|
+
assert.equal(result.output, "<p>Walking on imported air</p>");
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("HTML is written to file if output file is set", function() {
|
|
20
|
+
return createTempDir().then(function(tempDir) {
|
|
21
|
+
var outputPath = path.join(tempDir, "output.html");
|
|
22
|
+
return runMammoth(testPath("single-paragraph.docx"), outputPath).then(function(result) {
|
|
23
|
+
assert.equal(result.stderrOutput, "");
|
|
24
|
+
assert.equal(result.output, "");
|
|
25
|
+
assert.equal(fs.readFileSync(outputPath, "utf8"), "<p>Walking on imported air</p>");
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
var imageBase64 = "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAOvgAADr4B6kKxwAAAABNJREFUKFNj/M+ADzDhlWUYqdIAQSwBE8U+X40AAAAASUVORK5CYII=";
|
|
31
|
+
|
|
32
|
+
test("inline images are included in output if writing to single file", function() {
|
|
33
|
+
return runMammoth(testPath("tiny-picture.docx")).then(function(result) {
|
|
34
|
+
assert.equal(result.stderrOutput, "");
|
|
35
|
+
assert.equal(result.output, '<p><img src="data:image/png;base64,' + imageBase64 + '" /></p>');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("images are written to separate files if output dir is set", function() {
|
|
40
|
+
return createTempDir().then(function(tempDir) {
|
|
41
|
+
var outputPath = path.join(tempDir, "tiny-picture.html");
|
|
42
|
+
var imagePath = path.join(tempDir, "1.png");
|
|
43
|
+
return runMammoth(testPath("tiny-picture.docx"), "--output-dir", tempDir).then(function(result) {
|
|
44
|
+
assert.equal(result.stderrOutput, "");
|
|
45
|
+
assert.equal(result.output, "");
|
|
46
|
+
assert.equal(fs.readFileSync(outputPath, "utf8"), '<p><img src="1.png" /></p>');
|
|
47
|
+
assert.equal(fs.readFileSync(imagePath, "base64"), imageBase64);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("style map is used if set", function() {
|
|
53
|
+
return createTempDir().then(function(tempDir) {
|
|
54
|
+
var styleMapPath = path.join(tempDir, "style-map");
|
|
55
|
+
fs.writeFileSync(styleMapPath, "p => span:fresh");
|
|
56
|
+
return runMammoth(testPath("single-paragraph.docx"), "--style-map", styleMapPath).then(function(result) {
|
|
57
|
+
assert.equal(result.stderrOutput, "");
|
|
58
|
+
assert.equal(result.output, "<span>Walking on imported air</span>");
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("--output-format=markdown option generate markdown output", function() {
|
|
64
|
+
return runMammoth(testPath("single-paragraph.docx"), "--output-format=markdown").then(function(result) {
|
|
65
|
+
assert.equal(result.stderrOutput, "");
|
|
66
|
+
assert.equal(result.output, "Walking on imported air\n\n");
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
function runMammoth() {
|
|
72
|
+
var args = Array.prototype.slice.call(arguments, 0);
|
|
73
|
+
var deferred = promises.defer();
|
|
74
|
+
|
|
75
|
+
var processArgs = ["node", "bin/mammoth"].concat(args);
|
|
76
|
+
// TODO: proper escaping of args
|
|
77
|
+
var command = processArgs.join(" ");
|
|
78
|
+
child_process.exec(command, function(error, stdout, stderr) { // eslint-disable-line camelcase
|
|
79
|
+
console.log(stderr); // eslint-disable-line no-console
|
|
80
|
+
assert.equal(error, null);
|
|
81
|
+
deferred.resolve({output: stdout, stderrOutput: stderr});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return deferred.promise;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function createTempDir() {
|
|
88
|
+
return promises.nfcall(temp.mkdir, null);
|
|
89
|
+
}
|