diff --git a/src/renderer/plugins/markdown-link.ts b/src/renderer/plugins/markdown-link.ts index bc781ab8..deb7cdd0 100644 --- a/src/renderer/plugins/markdown-link.ts +++ b/src/renderer/plugins/markdown-link.ts @@ -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() } } }) diff --git a/src/renderer/plugins/markdown-toc.ts b/src/renderer/plugins/markdown-toc.ts index 0278b61a..4283bbbb 100644 --- a/src/renderer/plugins/markdown-toc.ts +++ b/src/renderer/plugins/markdown-toc.ts @@ -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],