From 59a6ddc8938915f17fb4df4d6ff27451af79c6ad Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 20 Mar 2024 18:55:13 +0000 Subject: Handle numbering level definitions without an explicit format --- NEWS | 4 ++++ lib/docx/numbering-xml.js | 2 +- test/docx/numbering-xml.tests.js | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 1567786..cb1ab7d 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +# 1.7.1 + +* Handle numbering level definitions without an explicit format. + # 1.7.0 * Support attributes in HTML paths in style mappings. diff --git a/lib/docx/numbering-xml.js b/lib/docx/numbering-xml.js index 832e414..7e368ac 100644 --- a/lib/docx/numbering-xml.js +++ b/lib/docx/numbering-xml.js @@ -66,7 +66,7 @@ function readAbstractNum(element) { var levels = {}; element.getElementsByTagName("w:lvl").forEach(function(levelElement) { var levelIndex = levelElement.attributes["w:ilvl"]; - var numFmt = levelElement.first("w:numFmt").attributes["w:val"]; + var numFmt = levelElement.firstOrEmpty("w:numFmt").attributes["w:val"]; var paragraphStyleId = levelElement.firstOrEmpty("w:pStyle").attributes["w:val"]; levels[levelIndex] = { diff --git a/test/docx/numbering-xml.tests.js b/test/docx/numbering-xml.tests.js index 1a20ab0..a648349 100644 --- a/test/docx/numbering-xml.tests.js +++ b/test/docx/numbering-xml.tests.js @@ -45,6 +45,23 @@ test('w:num element referencing non-existent w:abstractNumId is ignored', functi duck.assertThat(numbering.findLevel("47", "0"), duck.equalTo(null)); }); +test('when level is missing w:numFmt then level is ordered', function() { + var numbering = readNumberingXml( + new XmlElement("w:numbering", {}, [ + new XmlElement("w:abstractNum", {"w:abstractNumId": "42"}, [ + new XmlElement("w:lvl", {"w:ilvl": "0"}) + ]), + new XmlElement("w:num", {"w:numId": "47"}, [ + new XmlElement("w:abstractNumId", {"w:val": "42"}) + ]) + ]), + {styles: stylesReader.defaultStyles} + ); + duck.assertThat(numbering.findLevel("47", "0"), duck.hasProperties({ + isOrdered: true + })); +}); + test('when w:abstractNum has w:numStyleLink then style is used to find w:num', function() { var numbering = readNumberingXml( -- cgit v1.2.3