Skip to content

Commit 9951b7d

Browse files
committed
Fix ToC breaking documents with empty h* elements
Right now, the ToC has an undefined variable i that was an index in the original ToC code. Since the major rewrite in 4fe0620 it's a recursive function without this index. The variable `i` was wrongly copied into its current place from the old code. This patch replaces the variable `i` with the index of the header element. Fix the undefined variable problem. Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
1 parent 4e5e7df commit 9951b7d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

public/vendor/md-toc.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
}
4545
}
4646

47-
Toc.prototype._createTocContent = function recursiveToc(level = 0, titleElements = [], titleNames = [], ulClass = undefined) {
47+
Toc.prototype._createTocContent = function recursiveToc(level = 0, titleElements = [], titleNames = [], ulClass = undefined, index = 0) {
4848
// Inititalize our elements from the toc object
4949
// which is only available on level 0
5050
if (level === 0) {
@@ -74,8 +74,8 @@
7474
var elementText = (typeof this.process === 'function' ? this.process(element) : element.innerHTML).replace(/<(?:.|\n)*?>/gm, '')
7575
var id = element.getAttribute('id')
7676
if (!id) {
77-
element.setAttribute('id', 'tip' + i)
78-
id = '#tip' + i
77+
element.setAttribute('id', 'tip' + ++index)
78+
id = '#tip' + index
7979
} else {
8080
id = '#' + id
8181
}
@@ -97,7 +97,7 @@
9797
// This element is for the lower lever, we have to re-add it before we send the list down there.
9898
titleElements.unshift(element)
9999
// Let's call ourself and get to the next level
100-
content += recursiveToc(level + 1, titleElements, titleNames, ulClass)
100+
content += recursiveToc(level + 1, titleElements, titleNames, ulClass, index)
101101
} else {
102102
// When we end up here, met a higher level element
103103
// This is not our business so back into the list with the element and let's end this loop

0 commit comments

Comments
 (0)