summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-08-03 07:47:58 +0100
committerMichael Williamson <mike@zwobble.org>2025-08-03 07:47:58 +0100
commit033466fcb57ba2f4c0f876ed8dec705de5c68333 (patch)
tree60522f1c52d017eb9451d9be12eab357fceace45 /lib
parent67761754e4333fcb0ddccf06508a8631ce016c09 (diff)
Ignore style definitions using a style ID that has already been used
Diffstat (limited to 'lib')
-rw-r--r--lib/docx/styles-reader.js13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/docx/styles-reader.js b/lib/docx/styles-reader.js
index bff859f..28c809b 100644
--- a/lib/docx/styles-reader.js
+++ b/lib/docx/styles-reader.js
@@ -37,7 +37,18 @@ function readStylesXml(root) {
root.getElementsByTagName("w:style").forEach(function(styleElement) {
var style = readStyleElement(styleElement);
var styleSet = styles[style.type];
- if (styleSet) {
+
+ // Per 17.7.4.17 style (Style Definition) of ECMA-376 4th edition Part 1:
+ //
+ // > If multiple style definitions each declare the same value for their
+ // > styleId, then the first such instance shall keep its current
+ // > identifier with all other instances being reassigned in any manner
+ // > desired.
+ //
+ // For the purpose of conversion, there's no point holding onto styles
+ // with reassigned style IDs, so we ignore such style definitions.
+
+ if (styleSet && styleSet[style.styleId] === undefined) {
styleSet[style.styleId] = style;
}
});