|
@@ -480,12 +480,21 @@ function renderStructuredDocument(structuredDoc) {
|
|
|
// 将所有元素合并
|
|
// 将所有元素合并
|
|
|
const allElements = []
|
|
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 => {
|
|
blocks.forEach(block => {
|
|
|
if (block.type === 'page') return // 跳过根节点
|
|
if (block.type === 'page') return // 跳过根节点
|
|
|
allElements.push({
|
|
allElements.push({
|
|
@@ -494,15 +503,6 @@ function renderStructuredDocument(structuredDoc) {
|
|
|
html: block.markedHtml || block.html || block.plainText || ''
|
|
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)
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 添加图片(保持原始尺寸,不显示说明文字)
|
|
// 添加图片(保持原始尺寸,不显示说明文字)
|