From e7296cfd4baded13fce6360e3539a13722eac634 Mon Sep 17 00:00:00 2001 From: purocean Date: Fri, 22 Feb 2019 15:09:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=94=9A=E7=82=B9=E9=93=BE?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/View.vue | 10 ++++++++++ frontend/src/plugins/TocPlugin.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/View.vue b/frontend/src/components/View.vue index c0cf8bb3..7894ef81 100644 --- a/frontend/src/components/View.vue +++ b/frontend/src/components/View.vue @@ -117,6 +117,16 @@ export default { for (let ele of document.querySelectorAll('code[class^="language-"]')) { HighlightLineNumber.lineNumbersBlock(ele) } + + for (let ele of document.getElementsByTagName('a')) { + const href = ele.getAttribute('href') + if (href && href.startsWith('#')) { + ele.onclick = () => { + document.getElementById(href.replace(/^#/, '')).scrollIntoView() + return false + } + } + } }, 500, {leading: true}) this.render() diff --git a/frontend/src/plugins/TocPlugin.js b/frontend/src/plugins/TocPlugin.js index 5d7af9dd..6de66eed 100644 --- a/frontend/src/plugins/TocPlugin.js +++ b/frontend/src/plugins/TocPlugin.js @@ -166,7 +166,7 @@ export default (md, o) => { header.attrSet('id', slug) } - buffer = `
  • ` + buffer = `
  • ` buffer += typeof options.format === 'function' ? options.format(heading.content) : heading.content buffer += `` i++