Skip to content

Commit d6dd336

Browse files
committed
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>
1 parent 9951b7d commit d6dd336

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

public/js/extra.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,11 +846,13 @@ const linkifyAnchors = (level, containingElement) => {
846846
let header = headers[i]
847847
if (header.getElementsByClassName('anchor').length === 0) {
848848
if (typeof header.id === 'undefined' || header.id === '') {
849-
// to escape characters not allow in css and humanize
849+
// to escape characters not allow in css and humanize
850850
const id = slugifyWithUTF8(getHeaderContent(header))
851851
header.id = id
852852
}
853-
header.insertBefore(anchorForId(header.id), header.firstChild)
853+
if (!(typeof header.id === 'undefined' || header.id === '')) {
854+
header.insertBefore(anchorForId(header.id), header.firstChild)
855+
}
854856
}
855857
}
856858
}

public/js/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2786,6 +2786,7 @@ function updateViewInner () {
27862786
renderTOC(ui.area.markdown)
27872787
generateToc('ui-toc')
27882788
generateToc('ui-toc-affix')
2789+
autoLinkify(ui.area.markdown)
27892790
generateScrollspy()
27902791
updateScrollspy()
27912792
smoothHashScroll()

0 commit comments

Comments
 (0)