@hyperlex/mammoth 1.4.9-beta → 1.4.21
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 +0 -1
- package/.idea/compiler.xml +6 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/mammoth.js.iml +1 -5
- package/.idea/vcs.xml +1 -1
- package/.idea/workspace.xml +173 -0
- package/NEWS +55 -0
- package/README.md +39 -18
- package/lib/document-to-html.js +3 -0
- package/lib/documents.js +2 -0
- package/lib/docx/body-reader.js +74 -17
- package/lib/docx/numbering-xml.js +27 -4
- package/lib/index.d.ts +78 -0
- package/lib/index.js +7 -10
- package/lib/raw-text.js +14 -0
- package/lib/style-reader.js +15 -13
- package/lib/styles/document-matchers.js +1 -0
- package/lib/zipfile.js +26 -26
- package/mammoth.browser.js +10436 -19087
- package/mammoth.browser.min.js +21 -18
- package/package-lock.json +2654 -0
- package/package.json +11 -12
- package/test/document-to-html.tests.js +24 -0
- package/test/docx/body-reader.tests.js +170 -13
- package/test/docx/numbering-xml.tests.js +38 -0
- package/test/docx/style-map.tests.js +45 -44
- package/test/raw-text.tests.js +61 -0
- package/test/style-reader.tests.js +32 -25
- package/test/test-data/comments.docx +0 -0
- package/test/test-data/footnote-hyperlink.docx +0 -0
- package/test/test-data/footnotes.docx +0 -0
- package/test/test-data/simple-list.docx +0 -0
- package/test/test-data/single-paragraph.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.docx +0 -0
- package/test/test-data/underline.docx +0 -0
- package/test/zipfile.tests.js +12 -10
- package/.github/ISSUE_TEMPLATE.md +0 -12
- package/.travis.yml +0 -10
|
@@ -15,11 +15,11 @@ test('styleReader.readHtmlPath', {
|
|
|
15
15
|
'reads empty path': function() {
|
|
16
16
|
assertHtmlPath("", htmlPaths.empty);
|
|
17
17
|
},
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
'reads single element': function() {
|
|
20
20
|
assertHtmlPath("p", htmlPaths.elements(["p"]));
|
|
21
21
|
},
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
'reads choice of elements': function() {
|
|
24
24
|
assertHtmlPath(
|
|
25
25
|
"ul|ol",
|
|
@@ -28,18 +28,18 @@ test('styleReader.readHtmlPath', {
|
|
|
28
28
|
])
|
|
29
29
|
);
|
|
30
30
|
},
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
'reads nested elements': function() {
|
|
33
33
|
assertHtmlPath("ul > li", htmlPaths.elements(["ul", "li"]));
|
|
34
34
|
},
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
'reads class on element': function() {
|
|
37
37
|
var expected = htmlPaths.elements([
|
|
38
38
|
htmlPaths.element("p", {"class": "tip"})
|
|
39
39
|
]);
|
|
40
40
|
assertHtmlPath("p.tip", expected);
|
|
41
41
|
},
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
'reads class with escaped colon': function() {
|
|
44
44
|
var expected = htmlPaths.elements([
|
|
45
45
|
htmlPaths.element("p", {"class": "a:b"})
|
|
@@ -53,21 +53,21 @@ test('styleReader.readHtmlPath', {
|
|
|
53
53
|
]);
|
|
54
54
|
assertHtmlPath("p.tip.help", expected);
|
|
55
55
|
},
|
|
56
|
-
|
|
56
|
+
|
|
57
57
|
'reads when element must be fresh': function() {
|
|
58
58
|
var expected = htmlPaths.elements([
|
|
59
59
|
htmlPaths.element("p", {}, {"fresh": true})
|
|
60
60
|
]);
|
|
61
61
|
assertHtmlPath("p:fresh", expected);
|
|
62
62
|
},
|
|
63
|
-
|
|
63
|
+
|
|
64
64
|
'reads separator for elements': function() {
|
|
65
65
|
var expected = htmlPaths.elements([
|
|
66
66
|
htmlPaths.element("p", {}, {separator: "x"})
|
|
67
67
|
]);
|
|
68
68
|
assertHtmlPath("p:separator('x')", expected);
|
|
69
69
|
},
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
'reads separator with escape sequence': function() {
|
|
72
72
|
var expected = htmlPaths.elements([
|
|
73
73
|
htmlPaths.element("p", {}, {separator: "\r\n\t\'\\"})
|
|
@@ -88,21 +88,21 @@ test("styleReader.readDocumentMatcher", {
|
|
|
88
88
|
"reads plain paragraph": function() {
|
|
89
89
|
assertDocumentMatcher("p", documentMatchers.paragraph());
|
|
90
90
|
},
|
|
91
|
-
|
|
91
|
+
|
|
92
92
|
"reads paragraph with style ID": function() {
|
|
93
93
|
assertDocumentMatcher(
|
|
94
94
|
"p.Heading1",
|
|
95
95
|
documentMatchers.paragraph({styleId: "Heading1"})
|
|
96
96
|
);
|
|
97
97
|
},
|
|
98
|
-
|
|
98
|
+
|
|
99
99
|
"reads paragraph with exact style name": function() {
|
|
100
100
|
assertDocumentMatcher(
|
|
101
101
|
"p[style-name='Heading 1']",
|
|
102
102
|
documentMatchers.paragraph({styleName: documentMatchers.equalTo("Heading 1")})
|
|
103
103
|
);
|
|
104
104
|
},
|
|
105
|
-
|
|
105
|
+
|
|
106
106
|
"reads paragraph with style name prefix": function() {
|
|
107
107
|
assertDocumentMatcher(
|
|
108
108
|
"p[style-name^='Heading']",
|
|
@@ -116,14 +116,14 @@ test("styleReader.readDocumentMatcher", {
|
|
|
116
116
|
documentMatchers.paragraph({list: {isOrdered: true, levelIndex: 0}})
|
|
117
117
|
);
|
|
118
118
|
},
|
|
119
|
-
|
|
119
|
+
|
|
120
120
|
"reads p:unordered-list(1) as unordered list with index of 0": function() {
|
|
121
121
|
assertDocumentMatcher(
|
|
122
122
|
"p:unordered-list(1)",
|
|
123
123
|
documentMatchers.paragraph({list: {isOrdered: false, levelIndex: 0}})
|
|
124
124
|
);
|
|
125
125
|
},
|
|
126
|
-
|
|
126
|
+
|
|
127
127
|
"reads plain run": function() {
|
|
128
128
|
assertDocumentMatcher(
|
|
129
129
|
"r",
|
|
@@ -152,36 +152,43 @@ test("styleReader.readDocumentMatcher", {
|
|
|
152
152
|
})
|
|
153
153
|
);
|
|
154
154
|
},
|
|
155
|
-
|
|
155
|
+
|
|
156
156
|
"reads bold": function() {
|
|
157
157
|
assertDocumentMatcher(
|
|
158
158
|
"b",
|
|
159
159
|
documentMatchers.bold
|
|
160
160
|
);
|
|
161
161
|
},
|
|
162
|
-
|
|
162
|
+
|
|
163
163
|
"reads italic": function() {
|
|
164
164
|
assertDocumentMatcher(
|
|
165
165
|
"i",
|
|
166
166
|
documentMatchers.italic
|
|
167
167
|
);
|
|
168
168
|
},
|
|
169
|
-
|
|
169
|
+
|
|
170
170
|
"reads underline": function() {
|
|
171
171
|
assertDocumentMatcher(
|
|
172
172
|
"u",
|
|
173
173
|
documentMatchers.underline
|
|
174
174
|
);
|
|
175
175
|
},
|
|
176
|
-
|
|
176
|
+
|
|
177
177
|
"reads strikethrough": function() {
|
|
178
178
|
assertDocumentMatcher(
|
|
179
179
|
"strike",
|
|
180
180
|
documentMatchers.strikethrough
|
|
181
181
|
);
|
|
182
182
|
},
|
|
183
|
-
|
|
184
|
-
"reads
|
|
183
|
+
|
|
184
|
+
"reads all-caps": function() {
|
|
185
|
+
assertDocumentMatcher(
|
|
186
|
+
"all-caps",
|
|
187
|
+
documentMatchers.allCaps
|
|
188
|
+
);
|
|
189
|
+
},
|
|
190
|
+
|
|
191
|
+
"reads small-caps": function() {
|
|
185
192
|
assertDocumentMatcher(
|
|
186
193
|
"small-caps",
|
|
187
194
|
documentMatchers.smallCaps
|
|
@@ -194,21 +201,21 @@ test("styleReader.readDocumentMatcher", {
|
|
|
194
201
|
documentMatchers.commentReference
|
|
195
202
|
);
|
|
196
203
|
},
|
|
197
|
-
|
|
204
|
+
|
|
198
205
|
"reads line breaks": function() {
|
|
199
206
|
assertDocumentMatcher(
|
|
200
207
|
"br[type='line']",
|
|
201
208
|
documentMatchers.lineBreak
|
|
202
209
|
);
|
|
203
210
|
},
|
|
204
|
-
|
|
211
|
+
|
|
205
212
|
"reads page breaks": function() {
|
|
206
213
|
assertDocumentMatcher(
|
|
207
214
|
"br[type='page']",
|
|
208
215
|
documentMatchers.pageBreak
|
|
209
216
|
);
|
|
210
217
|
},
|
|
211
|
-
|
|
218
|
+
|
|
212
219
|
"reads column breaks": function() {
|
|
213
220
|
assertDocumentMatcher(
|
|
214
221
|
"br[type='column']",
|
|
@@ -217,7 +224,7 @@ test("styleReader.readDocumentMatcher", {
|
|
|
217
224
|
}
|
|
218
225
|
|
|
219
226
|
});
|
|
220
|
-
|
|
227
|
+
|
|
221
228
|
function assertDocumentMatcher(input, expected) {
|
|
222
229
|
assert.deepEqual(readDocumentMatcher(input), results.success(expected));
|
|
223
230
|
}
|
|
@@ -232,7 +239,7 @@ test("styleReader.read", {
|
|
|
232
239
|
}
|
|
233
240
|
);
|
|
234
241
|
},
|
|
235
|
-
|
|
242
|
+
|
|
236
243
|
"reads style mapping with no HTML path": function() {
|
|
237
244
|
assertStyleMapping(
|
|
238
245
|
"r =>",
|
|
@@ -242,7 +249,7 @@ test("styleReader.read", {
|
|
|
242
249
|
}
|
|
243
250
|
);
|
|
244
251
|
},
|
|
245
|
-
|
|
252
|
+
|
|
246
253
|
"error when not all input is consumed": function() {
|
|
247
254
|
assert.deepEqual(
|
|
248
255
|
readStyle("r => span a"),
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/test/zipfile.tests.js
CHANGED
|
@@ -6,21 +6,23 @@ var zipfile = require("../lib/zipfile");
|
|
|
6
6
|
var test = require("./test")(module);
|
|
7
7
|
|
|
8
8
|
test('file in zip can be read after being written', function() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
return emptyZipFile().then(function(zip) {
|
|
10
|
+
assert(!zip.exists("song/title"));
|
|
11
|
+
|
|
12
|
+
zip.write("song/title", "Dark Blue");
|
|
13
|
+
|
|
14
|
+
assert(zip.exists("song/title"));
|
|
15
|
+
return zip.read("song/title", "utf8").then(function(contents) {
|
|
16
|
+
assert.equal(contents, "Dark Blue");
|
|
17
|
+
});
|
|
17
18
|
});
|
|
18
19
|
});
|
|
19
20
|
|
|
20
21
|
function emptyZipFile() {
|
|
21
22
|
var zip = new JSZip();
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
return zip.generateAsync({type: "arraybuffer"}).then(function(arrayBuffer) {
|
|
24
|
+
return zipfile.openArrayBuffer(arrayBuffer);
|
|
25
|
+
});
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
If you're reporting a bug or requesting a feature, it's handy to have:
|
|
2
|
-
* a minimal example document
|
|
3
|
-
* the HTML output that you'd expect
|
|
4
|
-
|
|
5
|
-
If you're reporting a bug, it's also useful to know what platform you're
|
|
6
|
-
running on, including:
|
|
7
|
-
|
|
8
|
-
* the operating system and version
|
|
9
|
-
* if running in the browser:
|
|
10
|
-
* the browser and version
|
|
11
|
-
* whether you get the same issue in other browsers
|
|
12
|
-
* if running on node.js, the version you're using
|