diff options
| author | Michael Williamson <mike@zwobble.org> | 2019-03-17 20:42:08 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2019-03-17 20:42:08 +0000 |
| commit | 82f8b03022950069c4ee2239e9fa4368fbecd661 (patch) | |
| tree | 3dc42ac0e7ef034cd96d1f2e49dac91deaa757e1 /lib/docx/docx-reader.js | |
| parent | 5738d470f9997ae7037748e739bc936ca48ee71e (diff) | |
Pass styles into readNumberingXml
Diffstat (limited to 'lib/docx/docx-reader.js')
| -rw-r--r-- | lib/docx/docx-reader.js | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/docx/docx-reader.js b/lib/docx/docx-reader.js index e0d4a13..5f0fd05 100644 --- a/lib/docx/docx-reader.js +++ b/lib/docx/docx-reader.js @@ -22,7 +22,7 @@ var Files = require("./files").Files; function read(docxFile, input) { input = input || {}; - + return promises.props({ contentTypes: readContentTypesFromZipFile(docxFile), partPaths: findPartPaths(docxFile), @@ -30,11 +30,14 @@ function read(docxFile, input) { files: new Files(input.path ? path.dirname(input.path) : null) }).also(function(result) { return { - numbering: readNumberingFromZipFile(docxFile, result.partPaths.numbering), styles: readStylesFromZipFile(docxFile, result.partPaths.styles) }; }).also(function(result) { return { + numbering: readNumberingFromZipFile(docxFile, result.partPaths.numbering, result.styles) + }; + }).also(function(result) { + return { footnotes: readXmlFileWithBody(result.partPaths.footnotes, result, function(bodyReader, xml) { if (xml) { return notesReader.createFootnotesReader(bodyReader)(xml); @@ -90,11 +93,11 @@ function findPartPaths(docxFile) { basePath: "", fallbackPath: "word/document.xml" }); - + if (!docxFile.exists(mainDocumentPath)) { throw new Error("Could not find main document part. Are you sure this is a valid .docx file?"); } - + return xmlFileReader({ filename: relationshipsFilename(mainDocumentPath), readElement: relationshipsReader.readRelationships, @@ -109,7 +112,7 @@ function findPartPaths(docxFile) { fallbackPath: "word/" + name + ".xml" }); } - + return { mainDocument: mainDocumentPath, comments: findPartRelatedToMainDocument("comments"), @@ -128,7 +131,7 @@ function findPartPath(options) { var relationshipType = options.relationshipType; var basePath = options.basePath; var fallbackPath = options.fallbackPath; - + var targets = relationships.findTargetsByType(relationshipType); var normalisedTargets = targets.map(function(target) { return stripPrefix(zipfile.joinPath(basePath, target), "/"); @@ -166,7 +169,7 @@ function readXmlFileWithBody(filename, options, func) { readElement: relationshipsReader.readRelationships, defaultValue: relationshipsReader.defaultValue }); - + return readRelationshipsFromZipFile(options.docxFile).then(function(relationships) { var bodyReader = new createBodyReader({ relationships: relationships, @@ -194,10 +197,12 @@ var readContentTypesFromZipFile = xmlFileReader({ defaultValue: contentTypesReader.defaultContentTypes }); -function readNumberingFromZipFile(zipFile, path) { +function readNumberingFromZipFile(zipFile, path, styles) { return xmlFileReader({ filename: path, - readElement: numberingXml.readNumberingXml, + readElement: function(element) { + return numberingXml.readNumberingXml(element, {styles: styles}); + }, defaultValue: numberingXml.defaultNumbering })(zipFile); } |
