diff options
| author | Michael Williamson <mike@zwobble.org> | 2025-08-03 07:43:36 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2025-08-03 07:43:36 +0100 |
| commit | 67761754e4333fcb0ddccf06508a8631ce016c09 (patch) | |
| tree | 98e417bc133602e9521f092e11c8ce7c83d22d64 | |
| parent | 21174c07e3f829a149eba684b9bd56a7f0606613 (diff) | |
Unify flow for storing styles
| -rw-r--r-- | lib/docx/styles-reader.js | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/lib/docx/styles-reader.js b/lib/docx/styles-reader.js index d99dbb7..bff859f 100644 --- a/lib/docx/styles-reader.js +++ b/lib/docx/styles-reader.js @@ -30,18 +30,15 @@ function readStylesXml(root) { var styles = { "paragraph": paragraphStyles, "character": characterStyles, - "table": tableStyles + "table": tableStyles, + "numbering": numberingStyles }; root.getElementsByTagName("w:style").forEach(function(styleElement) { var style = readStyleElement(styleElement); - if (style.type === "numbering") { - numberingStyles[style.styleId] = readNumberingStyleElement(styleElement); - } else { - var styleSet = styles[style.type]; - if (styleSet) { - styleSet[style.styleId] = style; - } + var styleSet = styles[style.type]; + if (styleSet) { + styleSet[style.styleId] = style; } }); @@ -50,9 +47,14 @@ function readStylesXml(root) { function readStyleElement(styleElement) { var type = styleElement.attributes["w:type"]; - var styleId = styleElement.attributes["w:styleId"]; - var name = styleName(styleElement); - return {type: type, styleId: styleId, name: name}; + + if (type === "numbering") { + return readNumberingStyleElement(type, styleElement); + } else { + var styleId = readStyleId(styleElement); + var name = styleName(styleElement); + return {type: type, styleId: styleId, name: name}; + } } function styleName(styleElement) { @@ -60,11 +62,18 @@ function styleName(styleElement) { return nameElement ? nameElement.attributes["w:val"] : null; } -function readNumberingStyleElement(styleElement) { +function readNumberingStyleElement(type, styleElement) { + var styleId = readStyleId(styleElement); + var numId = styleElement .firstOrEmpty("w:pPr") .firstOrEmpty("w:numPr") .firstOrEmpty("w:numId") .attributes["w:val"]; - return {numId: numId}; + + return {type: type, numId: numId, styleId: styleId}; +} + +function readStyleId(styleElement) { + return styleElement.attributes["w:styleId"]; } |
