Skip to content

Commit 1659317

Browse files
committed
Fixing an issue when handling out-of-order heading levels
1 parent 6a4c83c commit 1659317

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

jquery.toc.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@
5656
));
5757
} else {
5858
// Truncate the stack to the current level by chopping off the 'top' of the stack.
59-
stack.splice(0, currentLevel - level);
59+
// if there are more than two elements on the stack, preserve those - the first is
60+
// the containing element, and the second is the 'root' list (ul/ol).
61+
stack.splice(0, Math.min(currentLevel - level, Math.max(stack.length - 2, 0)));
6062
}
6163

6264
// Add the list item

0 commit comments

Comments
 (0)