mirror of
https://github.com/purocean/yn.git
synced 2026-10-13 07:38:54 +08:00
支持锚点链接
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -166,7 +166,7 @@ export default (md, o) => {
|
||||
header.attrSet('id', slug)
|
||||
}
|
||||
|
||||
buffer = `<li><a href="#${slug}" onclick="document.getElementById('${slug}').scrollIntoView(); return false;">`
|
||||
buffer = `<li><a href="#${slug}">`
|
||||
buffer += typeof options.format === 'function' ? options.format(heading.content) : heading.content
|
||||
buffer += `</a>`
|
||||
i++
|
||||
|
||||
Reference in New Issue
Block a user