Sfoglia il codice sorgente

fix: 修正目录提取逻辑,匹配后端 heading1/heading2 类型格式

何文松 4 settimane fa
parent
commit
3ab859a2f5
1 ha cambiato i file con 12 aggiunte e 8 eliminazioni
  1. 12 8
      frontend/vue-demo/src/views/Editor.vue

+ 12 - 8
frontend/vue-demo/src/views/Editor.vue

@@ -512,16 +512,20 @@ const tocItems = computed(() => {
         })
       }
     }
-    // 检查是否是标题块
-    else if (block.type === 'heading' || (block.style && block.style.headingLevel)) {
-      const level = block.style?.headingLevel || 1
+    // 检查是否是标题块 (type: heading1, heading2, heading3...)
+    else if (block.type && block.type.startsWith('heading')) {
+      const levelMatch = block.type.match(/heading(\d+)/)
+      const level = levelMatch ? parseInt(levelMatch[1]) : 1
       // 只提取1-3级标题
       if (level <= 3) {
-        items.push({
-          level: level,
-          text: getBlockPlainText(block),
-          blockId: block.id
-        })
+        const text = block.plainText || getBlockPlainText(block)
+        if (text && text.trim()) {
+          items.push({
+            level: level,
+            text: text.trim(),
+            blockId: block.id
+          })
+        }
       }
     }
   }