fix: 章节内容存在多张图片和文本时,web服务书架中读书无法正确渲染图片(兼容版) (#5126)

* fix: 章节内容存在多张图片和文本时,web服务书架中读书无法正确渲染图片

* fix: 章节内容存在多张图片和文本时,web服务书架中读书无法正确渲染图片(兼容版)

* fix: 修改String.prototype.replaceAll为String.prototype.replace

---------

Co-authored-by: 17683954109@163.com <17683954109@163.com>
This commit is contained in:
PanicNotPanic
2025-06-05 22:42:56 +08:00
committed by GitHub
parent dfc9ff9b31
commit 70333d1aca
2 changed files with 2 additions and 2 deletions

View File

@@ -59,7 +59,7 @@ const calculateWordCount = (paragraph: string) => {
const imgPattern = /<img[^>]*src="[^"]*(?:"[^>]+\})?"[^>]*>/g
//内嵌图片文字为1
const imagePlaceHolder = ' '
return paragraph.replaceAll(imgPattern, imagePlaceHolder).length
return paragraph.replace(imgPattern, imagePlaceHolder).length
}
const chapterPos = computed(() => {
let pos = -1

View File

@@ -307,7 +307,7 @@ const getContent = (index: number, reloadChapter = true, chapterPos = 0) => {
const content = data.split(/\n+/)
for (let i = 0; i < content.length; i++) {
if (!/^\s*<img[^>]*src[^>]+>$/.test(content[i])) {
content[i] = content[i].replaceAll('img src="', `img src="/image?url=${bookUrl}&path=`);
content[i] = content[i].replace(new RegExp('img src="', 'g'), `img src="/image?url=${bookUrl}&path=`);
}
}
chapterData.value.push({ index, content, title })