|
|
@@ -477,44 +477,46 @@ function renderStructuredDocument(structuredDoc) {
|
|
|
const images = structuredDoc.images || []
|
|
|
const paragraphs = structuredDoc.paragraphs || []
|
|
|
|
|
|
- // 优先使用 paragraphs(包含格式信息),如果存在的话
|
|
|
- const hasParagraphsWithRuns = paragraphs.some(p => p.runs && p.runs.length > 0)
|
|
|
-
|
|
|
// 将所有元素合并
|
|
|
const allElements = []
|
|
|
|
|
|
- // 添加 blocks(带实体标记)或 paragraphs(带格式)
|
|
|
- if (hasParagraphsWithRuns) {
|
|
|
- // 使用 paragraphs 渲染(保留格式)
|
|
|
- paragraphs.forEach(para => {
|
|
|
- allElements.push({
|
|
|
- type: 'paragraph',
|
|
|
- index: para.index,
|
|
|
- html: renderParagraphWithRuns(para)
|
|
|
- })
|
|
|
- })
|
|
|
- } else {
|
|
|
+ // 检查 blocks 是否有有效内容(markedHtml 不为空)
|
|
|
+ const hasBlocksWithContent = blocks.some(b => b.markedHtml || b.html || b.plainText)
|
|
|
+
|
|
|
+ // 优先使用 blocks(带实体高亮标记),如果有内容的话
|
|
|
+ if (hasBlocksWithContent) {
|
|
|
// 使用 blocks 渲染(带实体标记)
|
|
|
blocks.forEach(block => {
|
|
|
+ if (block.type === 'page') return // 跳过根节点
|
|
|
allElements.push({
|
|
|
type: 'block',
|
|
|
index: block.index,
|
|
|
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)
|
|
|
+ })
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
- // 添加图片
|
|
|
+ // 添加图片(保持原始尺寸,不显示说明文字)
|
|
|
images.forEach(img => {
|
|
|
+ // 图片样式:保持原始尺寸,不强制居中
|
|
|
+ const imgStyle = img.width && img.height
|
|
|
+ ? `width:${img.width}px; height:${img.height}px;`
|
|
|
+ : 'max-width: 100%; height: auto;'
|
|
|
+
|
|
|
allElements.push({
|
|
|
type: 'image',
|
|
|
index: img.index,
|
|
|
- html: `<div class="doc-image" style="text-align: center; margin: 16px 0;">
|
|
|
- <img src="${img.url}" alt="${img.alt || '图片'}"
|
|
|
- style="max-width: 100%; height: auto;"
|
|
|
- ${img.width ? `width="${img.width}"` : ''}
|
|
|
- ${img.height ? `height="${img.height}"` : ''} />
|
|
|
- ${img.alt ? `<p class="image-caption" style="color: #666; font-size: 12px; margin-top: 8px;">${img.alt}</p>` : ''}
|
|
|
+ html: `<div class="doc-image" style="margin: 8px 0;">
|
|
|
+ <img src="${img.url}" alt="${img.alt || '图片'}" style="${imgStyle}" />
|
|
|
</div>`
|
|
|
})
|
|
|
})
|