summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2018-01-16 21:44:36 +0000
committerMichael Williamson <mike@zwobble.org>2018-01-16 21:44:36 +0000
commit062eb4ff3fea9c49cfce841327d01ddd0099264e (patch)
tree352c5bded69b8da7ac397679f8372ac04a077a0b /lib
parent3318d28bf94b2415548891d8c845828003426bb6 (diff)
Pass full filename to readXmlFileWithBody
Diffstat (limited to 'lib')
-rw-r--r--lib/docx/docx-reader.js20
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/docx/docx-reader.js b/lib/docx/docx-reader.js
index 5aa95ca..db15b95 100644
--- a/lib/docx/docx-reader.js
+++ b/lib/docx/docx-reader.js
@@ -28,21 +28,21 @@ function read(docxFile, input) {
files: new Files(input.path ? path.dirname(input.path) : null)
}).also(function(result) {
return {
- footnotes: readXmlFileWithBody("footnotes", result, function(bodyReader, xml) {
+ footnotes: readXmlFileWithBody("word/footnotes.xml", result, function(bodyReader, xml) {
if (xml) {
return notesReader.createFootnotesReader(bodyReader)(xml);
} else {
return new Result([]);
}
}),
- endnotes: readXmlFileWithBody("endnotes", result, function(bodyReader, xml) {
+ endnotes: readXmlFileWithBody("word/endnotes.xml", result, function(bodyReader, xml) {
if (xml) {
return notesReader.createEndnotesReader(bodyReader)(xml);
} else {
return new Result([]);
}
}),
- comments: readXmlFileWithBody("comments", result, function(bodyReader, xml) {
+ comments: readXmlFileWithBody("word/comments.xml", result, function(bodyReader, xml) {
if (xml) {
return commentsReader.createCommentsReader(bodyReader)(xml);
} else {
@@ -59,7 +59,7 @@ function read(docxFile, input) {
})
};
}).then(function(result) {
- return readXmlFileWithBody("document", result, function(bodyReader, xml) {
+ return readXmlFileWithBody("word/document.xml", result, function(bodyReader, xml) {
if (xml) {
return result.notes.flatMap(function(notes) {
return result.comments.flatMap(function(comments) {
@@ -87,9 +87,9 @@ function xmlFileReader(options) {
};
}
-function readXmlFileWithBody(name, options, func) {
+function readXmlFileWithBody(filename, options, func) {
var readRelationshipsFromZipFile = xmlFileReader({
- filename: "word/_rels/" + name + ".xml.rels",
+ filename: relationshipsFilename(filename),
readElement: relationshipsReader.readRelationships,
defaultValue: {}
});
@@ -103,13 +103,19 @@ function readXmlFileWithBody(name, options, func) {
styles: options.styles,
files: options.files
});
- return readXmlFromZipFile(options.docxFile, "word/" + name + ".xml")
+ return readXmlFromZipFile(options.docxFile, filename)
.then(function(xml) {
return func(bodyReader, xml);
});
});
}
+function relationshipsFilename(filename) {
+ var parts = filename.split("/");
+ return parts.slice(0, parts.length - 1).join("/") +
+ "/_rels/" + parts[parts.length - 1] + ".rels";
+}
+
var readContentTypesFromZipFile = xmlFileReader({
filename: "[Content_Types].xml",
readElement: contentTypesReader.readContentTypesFromXml,