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>
This commit is contained in:
Sheogorath 2018-11-19 18:29:50 +01:00
parent 9951b7df7c
commit d6dd33620c
No known key found for this signature in database
GPG key ID: 1F05CC3635CDDFFD
2 changed files with 5 additions and 2 deletions

View file

@ -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)
}
}
}
}

View file

@ -2786,6 +2786,7 @@ function updateViewInner () {
renderTOC(ui.area.markdown)
generateToc('ui-toc')
generateToc('ui-toc-affix')
autoLinkify(ui.area.markdown)
generateScrollspy()
updateScrollspy()
smoothHashScroll()