summaryrefslogtreecommitdiff
path: root/public/js/extra.js
diff options
context:
space:
mode:
authorSheogorath2018-11-19 18:29:50 +0100
committerSheogorath2018-11-19 20:20:56 +0100
commitd6dd33620c7bea3720361d51ab04668a0c913cce (patch)
treef6ee47043216417b8aa21c234e7bc5b18dd8ea6c /public/js/extra.js
parent9951b7df7c6523838b413700d51930956c467d6a (diff)
Fix wrong anchors
While experimenting with the ToC changes, it became obvious that anchors for those unnamed headers don't work. This patch fixes those links by running the autolinkify twice and make sure linkify only adds links to non-empty ids. Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
Diffstat (limited to 'public/js/extra.js')
-rw-r--r--public/js/extra.js6
1 files changed, 4 insertions, 2 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)
+ }
}
}
}