Jelajahi Sumber

fix: 恢复 paragraphs 优先渲染,保留字体格式

优先使用 paragraphs(带 runs 格式信息),
仅当无 runs 时才回退到 blocks(带实体标记)
何文松 1 bulan lalu
induk
melakukan
823628b640
1 mengubah file dengan 14 tambahan dan 14 penghapusan
  1. 14 14
      frontend/vue-demo/src/views/Editor.vue

+ 14 - 14
frontend/vue-demo/src/views/Editor.vue

@@ -480,12 +480,21 @@ function renderStructuredDocument(structuredDoc) {
   // 将所有元素合并
   const allElements = []
   
-  // 检查 blocks 是否有有效内容(markedHtml 不为空
-  const hasBlocksWithContent = blocks.some(b => b.markedHtml || b.html || b.plainText)
+  // 检查 paragraphs 是否有 runs(带格式信息
+  const hasParagraphsWithRuns = paragraphs.some(p => p.runs && p.runs.length > 0)
   
-  // 优先使用 blocks(带实体高亮标记),如果有内容的话
-  if (hasBlocksWithContent) {
-    // 使用 blocks 渲染(带实体标记)
+  // 优先使用 paragraphs(带格式),如果有 runs 的话
+  if (hasParagraphsWithRuns) {
+    // 使用 paragraphs 渲染(保留格式)
+    paragraphs.forEach(para => {
+      allElements.push({
+        type: 'paragraph',
+        index: para.index,
+        html: renderParagraphWithRuns(para)
+      })
+    })
+  } else if (blocks.length > 0) {
+    // 回退到 blocks 渲染(带实体标记,但无格式)
     blocks.forEach(block => {
       if (block.type === 'page') return // 跳过根节点
       allElements.push({
@@ -494,15 +503,6 @@ function renderStructuredDocument(structuredDoc) {
         html: block.markedHtml || block.html || block.plainText || ''
       })
     })
-  } else if (paragraphs.length > 0) {
-    // 回退到 paragraphs 渲染(保留格式,但无实体标记)
-    paragraphs.forEach(para => {
-      allElements.push({
-        type: 'paragraph',
-        index: para.index,
-        html: renderParagraphWithRuns(para)
-      })
-    })
   }
   
   // 添加图片(保持原始尺寸,不显示说明文字)