From d6dd33620c7bea3720361d51ab04668a0c913cce Mon Sep 17 00:00:00 2001 From: Sheogorath Date: Mon, 19 Nov 2018 18:29:50 +0100 Subject: 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 --- public/js/extra.js | 6 ++++-- public/js/index.js | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'public/js') 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 98c3b6d2..a7f4df94 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -2786,6 +2786,7 @@ function updateViewInner () { renderTOC(ui.area.markdown) generateToc('ui-toc') generateToc('ui-toc-affix') + autoLinkify(ui.area.markdown) generateScrollspy() updateScrollspy() smoothHashScroll() -- cgit v1.2.3