diff --git a/CHANGELOG.md b/CHANGELOG.md index 9621113c3..1de96a68d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - Fixes and validates input values headerRows and keepWithHeaderRows +- Fixed numbering nested ordered lists ## 0.2.10 - 2024-03-07 diff --git a/src/docMeasure.js b/src/docMeasure.js index 9b35bf3dc..e163a3b92 100644 --- a/src/docMeasure.js +++ b/src/docMeasure.js @@ -509,16 +509,16 @@ DocMeasure.prototype.measureOrderedList = function (node) { if (item.listMarker._inlines) { node._gapSize.width = Math.max(node._gapSize.width, item.listMarker._inlines[0].width); } - } // TODO: else - nested lists numbering + + if (node.reversed) { + counter--; + } else { + counter++; + } + } node._minWidth = Math.max(node._minWidth, items[i]._minWidth); node._maxWidth = Math.max(node._maxWidth, items[i]._maxWidth); - - if (node.reversed) { - counter--; - } else { - counter++; - } } node._minWidth += node._gapSize.width; diff --git a/tests/docMeasure.js b/tests/docMeasure.js index 3052f4298..34513818f 100644 --- a/tests/docMeasure.js +++ b/tests/docMeasure.js @@ -181,6 +181,14 @@ describe('DocMeasure', function () { assert(result._gapSize); }); + it('should not increase listMarker when list item is a nested list', function () { + var node = { ol: ['parent item 1', { ol: ['nested item 1', 'nested item 2']}, 'parent item 2'] }; + docPreprocessor.preprocessList(node); + var result = docMeasure.measureOrderedList(node); + + assert.equal(result.ol[2].listMarker._inlines[0].text, '2. '); + }); + it('should calculate _minWidth and _maxWidth of all elements', function () { var node = { ol: ['this is a test', 'another one'] }; docPreprocessor.preprocessList(node);