summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
authorChristoph (Sheogorath) Kern2018-11-19 21:33:34 +0100
committerGitHub2018-11-19 21:33:34 +0100
commit271dff3808618d0422a52ff5da8cf187bf350b3d (patch)
tree9c106cf0dc1ac23d166fa0367ec19408dccd1d54 /public
parentf46a84ab5490733b5c28f14ef904176a7354464a (diff)
parentd6dd33620c7bea3720361d51ab04668a0c913cce (diff)
Merge pull request #1043 from SISheogorath/fix/tocEmptyHead
Fix ToC breaking documents with empty h* elements
Diffstat (limited to 'public')
-rw-r--r--public/js/extra.js6
-rw-r--r--public/js/index.js1
-rw-r--r--public/vendor/md-toc.js8
3 files changed, 9 insertions, 6 deletions
diff --git a/public/js/extra.js b/public/js/extra.js
index ed1470be..76e95635 100644
--- a/public/js/extra.js
+++ b/public/js/extra.js
@@ -846,11 +846,13 @@ const linkifyAnchors = (level, containingElement) => {
let header = headers[i]
if (header.getElementsByClassName('anchor').length === 0) {
if (typeof header.id === 'undefined' || header.id === '') {
- // to escape characters not allow in css and humanize
+ // to escape characters not allow in css and humanize
const id = slugifyWithUTF8(getHeaderContent(header))
header.id = id
}
- header.insertBefore(anchorForId(header.id), header.firstChild)
+ if (!(typeof header.id === 'undefined' || header.id === '')) {
+ header.insertBefore(anchorForId(header.id), header.firstChild)
+ }
}
}
}
diff --git a/public/js/index.js b/public/js/index.js
index 0c575961..c2969e92 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -2788,6 +2788,7 @@ function updateViewInner () {
renderTOC(ui.area.markdown)
generateToc('ui-toc')
generateToc('ui-toc-affix')
+ autoLinkify(ui.area.markdown)
generateScrollspy()
updateScrollspy()
smoothHashScroll()
diff --git a/public/vendor/md-toc.js b/public/vendor/md-toc.js
index 876978f7..59e75aed 100644
--- a/public/vendor/md-toc.js
+++ b/public/vendor/md-toc.js
@@ -44,7 +44,7 @@
}
}
- Toc.prototype._createTocContent = function recursiveToc(level = 0, titleElements = [], titleNames = [], ulClass = undefined) {
+ Toc.prototype._createTocContent = function recursiveToc(level = 0, titleElements = [], titleNames = [], ulClass = undefined, index = 0) {
// Inititalize our elements from the toc object
// which is only available on level 0
if (level === 0) {
@@ -74,8 +74,8 @@
var elementText = (typeof this.process === 'function' ? this.process(element) : element.innerHTML).replace(/<(?:.|\n)*?>/gm, '')
var id = element.getAttribute('id')
if (!id) {
- element.setAttribute('id', 'tip' + i)
- id = '#tip' + i
+ element.setAttribute('id', 'tip' + ++index)
+ id = '#tip' + index
} else {
id = '#' + id
}
@@ -97,7 +97,7 @@
// This element is for the lower lever, we have to re-add it before we send the list down there.
titleElements.unshift(element)
// Let's call ourself and get to the next level
- content += recursiveToc(level + 1, titleElements, titleNames, ulClass)
+ content += recursiveToc(level + 1, titleElements, titleNames, ulClass, index)
} else {
// When we end up here, met a higher level element
// This is not our business so back into the list with the element and let's end this loop