优化页面、修复BUG
This commit is contained in:
@@ -47,6 +47,16 @@ export type PptSlide = PptTitleSlide | PptSectionSlide
|
|||||||
const PPT_SLIDE_BOTTOM = 5.1
|
const PPT_SLIDE_BOTTOM = 5.1
|
||||||
const SECTION_HEADER_HEIGHT = 0.85
|
const SECTION_HEADER_HEIGHT = 0.85
|
||||||
const IMAGE_PLACEHOLDER_GLOBAL_RE = /\[图片(?::[^\]]*)?\]/g
|
const IMAGE_PLACEHOLDER_GLOBAL_RE = /\[图片(?::[^\]]*)?\]/g
|
||||||
|
const IMAGE_FILENAME_SUFFIX_RE =
|
||||||
|
/\s+[\w\u4e00-\u9fa5.-]+\.(jpg|jpeg|png|gif|webp|svg|bmp)\s*$/i
|
||||||
|
|
||||||
|
function stripTrailingImageFilenames(text: string): string {
|
||||||
|
let result = text
|
||||||
|
while (IMAGE_FILENAME_SUFFIX_RE.test(result)) {
|
||||||
|
result = result.replace(IMAGE_FILENAME_SUFFIX_RE, '')
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
let markdownParser: MarkdownIt | null = null
|
let markdownParser: MarkdownIt | null = null
|
||||||
|
|
||||||
@@ -82,9 +92,11 @@ function renderInlineText(inlineToken: Token): string {
|
|||||||
return renderTokenChildren(inlineToken.children)
|
return renderTokenChildren(inlineToken.children)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 移除 inline 渲染产生的 [图片: ...] 占位片段 */
|
/** 移除 inline 渲染产生的 [图片: ...] 占位片段与段尾图片文件名 */
|
||||||
export function stripImagePlaceholders(text: string): string {
|
export function stripImagePlaceholders(text: string): string {
|
||||||
return text.replace(IMAGE_PLACEHOLDER_GLOBAL_RE, '').replace(/\s+/g, ' ').trim()
|
let result = text.replace(IMAGE_PLACEHOLDER_GLOBAL_RE, '')
|
||||||
|
result = stripTrailingImageFilenames(result)
|
||||||
|
return result.replace(/\s+/g, ' ').trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
function getImgSrc(el: Element): string {
|
function getImgSrc(el: Element): string {
|
||||||
@@ -454,7 +466,9 @@ export function dedupeImageCaptionBlocks(blocks: ContentBlock[]): ContentBlock[]
|
|||||||
const prev = result[result.length - 1]
|
const prev = result[result.length - 1]
|
||||||
|
|
||||||
if (block.type === 'paragraph') {
|
if (block.type === 'paragraph') {
|
||||||
const text = block.text.trim()
|
const text = stripImagePlaceholders(block.text)
|
||||||
|
if (!text) continue
|
||||||
|
|
||||||
const next = blocks[i + 1]
|
const next = blocks[i + 1]
|
||||||
|
|
||||||
if (prev?.type === 'image' && isImageCaptionLike(text, prev)) {
|
if (prev?.type === 'image' && isImageCaptionLike(text, prev)) {
|
||||||
@@ -463,12 +477,15 @@ export function dedupeImageCaptionBlocks(blocks: ContentBlock[]): ContentBlock[]
|
|||||||
if (next?.type === 'image' && isImageCaptionLike(text, next)) {
|
if (next?.type === 'image' && isImageCaptionLike(text, next)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
result.push(block)
|
result.push(text === block.text ? block : { ...block, text })
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block.type === 'list' && prev?.type === 'image') {
|
if (block.type === 'list') {
|
||||||
const items = block.items.filter((item) => !isImageCaptionLike(item, prev))
|
const items = block.items
|
||||||
|
.map((item) => stripImagePlaceholders(item))
|
||||||
|
.filter(Boolean)
|
||||||
|
.filter((item) => !(prev?.type === 'image' && isImageCaptionLike(item, prev)))
|
||||||
if (items.length) {
|
if (items.length) {
|
||||||
result.push({ ...block, items })
|
result.push({ ...block, items })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user