|
@@ -514,9 +514,18 @@ function getTocBullet(level) {
|
|
|
return bullets[Math.min(level - 1, bullets.length - 1)]
|
|
return bullets[Math.min(level - 1, bullets.length - 1)]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// 规范化文本用于比较
|
|
|
|
|
+function normalizeForCompare(text) {
|
|
|
|
|
+ if (!text) return ''
|
|
|
|
|
+ return text
|
|
|
|
|
+ .replace(/\s+/g, ' ') // 多个空格合并
|
|
|
|
|
+ .replace(/[\u00A0\u202F\u2009]/g, ' ') // 特殊空格转普通空格
|
|
|
|
|
+ .trim()
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// 滚动到指定章节(只匹配 h1-h6 标题元素)
|
|
// 滚动到指定章节(只匹配 h1-h6 标题元素)
|
|
|
function scrollToHeading(item) {
|
|
function scrollToHeading(item) {
|
|
|
- const titleText = (item.title || item.text || '').trim()
|
|
|
|
|
|
|
+ const titleText = normalizeForCompare(item.title || item.text)
|
|
|
if (!titleText) return
|
|
if (!titleText) return
|
|
|
|
|
|
|
|
// 在文档内容区域中查找标题元素
|
|
// 在文档内容区域中查找标题元素
|
|
@@ -527,7 +536,7 @@ function scrollToHeading(item) {
|
|
|
const headings = editorContent.querySelectorAll('h1, h2, h3, h4, h5, h6')
|
|
const headings = editorContent.querySelectorAll('h1, h2, h3, h4, h5, h6')
|
|
|
|
|
|
|
|
for (const heading of headings) {
|
|
for (const heading of headings) {
|
|
|
- const headingText = heading.textContent?.trim()
|
|
|
|
|
|
|
+ const headingText = normalizeForCompare(heading.textContent)
|
|
|
if (headingText === titleText) {
|
|
if (headingText === titleText) {
|
|
|
heading.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
|
heading.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
|
|
highlightElement(heading)
|
|
highlightElement(heading)
|