fix(htmlUtil): removeEmptyParagraphs移除逻辑修正

移除空段落时,应当考虑仅包含图片的情况
This commit is contained in:
maonianyou 2025-01-11 16:39:26 +08:00
parent 8d3c5bbb0e
commit c67fce2659
1 changed files with 2 additions and 1 deletions

View File

@ -125,7 +125,8 @@ export const isExcelDocument = (document: Document) => {
export const removeEmptyParagraphs = (html: string) => {
const tempDiv = document.createElement('div');
tempDiv.innerHTML = html;
const paragraphs = tempDiv.querySelectorAll('p');
// `<p><img src="src" /></p>`的情况文字内容为空但不应该被清除
const paragraphs = tempDiv.querySelectorAll('p:not(:has(img))');
paragraphs.forEach(paragraph => {
if (!paragraph.textContent || paragraph.textContent.trim() === '') {