Ver Fonte

refactor: 移除标题块提取逻辑,目录仅从 toc_item 元素提取

何文松 há 4 semanas atrás
pai
commit
9225eb1cb9
1 ficheiros alterados com 1 adições e 35 exclusões
  1. 1 35
      frontend/vue-demo/src/views/Editor.vue

+ 1 - 35
frontend/vue-demo/src/views/Editor.vue

@@ -495,7 +495,7 @@ const newSourceFile = reactive({
 // 文档结构块(用于生成目录等)
 const blocks = ref([])
 
-// 目录数据(从文档结构中提取)
+// 目录数据(从文档结构中提取 toc_item 元素
 const tocItems = computed(() => {
   const items = []
   if (!blocks.value || blocks.value.length === 0) return items
@@ -519,26 +519,6 @@ const tocItems = computed(() => {
         }
       }
     }
-    
-    // 也检查标题块作为备用 (type: heading1, heading2, heading3...)
-    if (block.type && block.type.startsWith('heading')) {
-      const levelMatch = block.type.match(/heading(\d+)/)
-      const level = levelMatch ? parseInt(levelMatch[1]) : 1
-      if (level <= 3) {
-        const text = block.plainText || getBlockPlainText(block)
-        if (text && text.trim()) {
-          // 避免重复添加(如果已经从 toc_item 中添加过)
-          const exists = items.some(item => item.text === text.trim())
-          if (!exists) {
-            items.push({
-              level: level,
-              text: text.trim(),
-              blockId: block.id
-            })
-          }
-        }
-      }
-    }
   }
   return items
 })
@@ -561,20 +541,6 @@ function detectTocLevel(text) {
   return 1
 }
 
-// 获取块的纯文本内容
-function getBlockPlainText(block) {
-  if (!block.elements) return ''
-  return block.elements
-    .filter(el => el.type === 'text')
-    .map(el => {
-      if (el.runs) {
-        return el.runs.map(r => r.text).join('')
-      }
-      return el.text || ''
-    })
-    .join('')
-}
-
 // 获取目录项的项目符号
 function getTocBullet(level) {
   const bullets = ['●', '○', '◦']