upd: 移除标题链接中的 h-

This commit is contained in:
purocean
2021-09-06 15:20:43 +08:00
parent 2b7e0a41a8
commit 5803fdaa56
2 changed files with 7 additions and 4 deletions
+6 -3
View File
@@ -50,14 +50,17 @@ const handleLink = (link: HTMLAnchorElement) => {
if (hash) {
await sleep(50)
const el = document.getElementById(hash) ||
document.getElementById(encodeURIComponent(hash))
document.getElementById(encodeURIComponent(hash)) ||
document.getElementById(hash.replace(/^h-/, '')) ||
document.getElementById(encodeURIComponent(hash.replace(/^h-/, '')))
if (el) {
el.scrollIntoView()
// 如果是标题的话,也顺便将编辑器滚动到可视区域
if (hash.startsWith('h-')) {
if (['H1', 'H2', 'H3', 'H4', 'H5', 'H6'].includes(el.tagName)) {
el.click()
}
el.scrollIntoView()
}
}
})
+1 -1
View File
@@ -7,7 +7,7 @@ import { Plugin } from '@fe/context/plugin'
import { injectLineNumbers } from './markdown-source-line'
const slugify = (s: string) => 'h-' + encodeURIComponent(String(s).trim().toLowerCase().replace(/\s+/g, '-'))
const slugify = (s: string) => encodeURIComponent(String(s).trim().toLowerCase().replace(/\s+/g, '-'))
const defaults = {
level: [2, 3],