diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/docx/style-map.js | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/lib/docx/style-map.js b/lib/docx/style-map.js index 76f6903..04597a2 100644 --- a/lib/docx/style-map.js +++ b/lib/docx/style-map.js @@ -1,3 +1,5 @@ +var _ = require("underscore"); + var promises = require("../promises"); var officeXml = require("./office-xml-reader"); var xml = require("../xml"); @@ -6,6 +8,7 @@ exports.writeStyleMap = writeStyleMap; exports.readStyleMap = readStyleMap; +var schema = "http://schemas.zwobble.org/mammoth/style-map"; var styleMapPath = "mammoth/style-map"; function writeStyleMap(docxFile, styleMap) { @@ -18,14 +21,25 @@ function updateRelationships(docxFile) { 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", + var relationshipsContainer = relationshipsDocument.root; + var relationships = relationshipsContainer.children; + var relationshipId = "rMammothStyleMap"; + var attributes = { + "Id": relationshipId, + "Type": schema, "Target": "/" + styleMapPath - })); + }; + + var existingRelationship = _.find(relationships, function(relationship) { + return relationship.attributes.Id === relationshipId; + }); + if (existingRelationship) { + existingRelationship.attributes = attributes; + } else { + relationships.push(xml.element("{" + relationshipsUri + "}Relationship", attributes)); + } var namespaces = {"": relationshipsUri}; - return docxFile.write(path, xml.writeString(relationships, namespaces)); + return docxFile.write(path, xml.writeString(relationshipsContainer, namespaces)); }); } |
