diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-08-16 15:55:58 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-08-16 15:55:58 +0100 |
| commit | 26eb141ff6f0167a2506ffb5bf6a65cf2773f409 (patch) | |
| tree | 2c369c08f36a78d080c7dca79f3191d8da10bf51 /lib | |
| parent | 0363f064b05698eed9826570aad6985ef47a6322 (diff) | |
Add style map to relationships for document
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/docx/style-map.js | 20 | ||||
| -rw-r--r-- | lib/xml/index.js | 1 |
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/docx/style-map.js b/lib/docx/style-map.js index 5020a87..bd770bd 100644 --- a/lib/docx/style-map.js +++ b/lib/docx/style-map.js @@ -1,4 +1,6 @@ var promises = require("../promises"); +var officeXml = require("./office-xml-reader"); +var xml = require("../xml"); exports.writeStyleMap = writeStyleMap; exports.readStyleMap = readStyleMap; @@ -8,6 +10,24 @@ var styleMapPath = "mammoth/style-map"; function writeStyleMap(docxFile, styleMap) { docxFile.write(styleMapPath, styleMap); + return updateRelationships(docxFile); +} + +function updateRelationships(docxFile) { + var path = "word/_rels/document.xml.rels"; + var relationshipsUri = "http://schemas.openxmlformats.org/package/2006/relationships"; + return officeXml.readXmlFromZipFile(docxFile, path) + .then(function(relationshipsDocument) { + var relationships = relationshipsDocument.root; + relationships.children.push(xml.element("{" + relationshipsUri + "}:Relationship", { + "Id": "rMammothStyleMap", + "Type": "http://schemas.zwobble.org/mammoth/style-map", + "Target": "/" + styleMapPath + })); + var namespaces = {"": relationshipsUri}; + return docxFile.write(path, xml.writeString(relationships, namespaces)); + }); + } function readStyleMap(docxFile) { diff --git a/lib/xml/index.js b/lib/xml/index.js index 0320bc2..a2f572e 100644 --- a/lib/xml/index.js +++ b/lib/xml/index.js @@ -4,3 +4,4 @@ exports.Element = nodes.Element; exports.element = nodes.element; exports.text = nodes.text; exports.readString = require("./reader").readString; +exports.writeString = require("./writer").writeString; |
