Skip to content

Commit

Permalink
Handle numbering level definitions without an explicit format
Browse files Browse the repository at this point in the history
  • Loading branch information
mwilliamson committed Mar 20, 2024
1 parent 00c2a1f commit 59a6ddc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/docx/numbering-xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down
17 changes: 17 additions & 0 deletions test/docx/numbering-xml.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 59a6ddc

Please sign in to comment.