Skip to content

Commit

Permalink
fix: fix parse init html error if the content is text only
Browse files Browse the repository at this point in the history
  • Loading branch information
yangfuhai committed Dec 21, 2024
1 parent 1d4f065 commit 405f4d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
6 changes: 2 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ window.aiEditor = new AiEditor({
// pasteAsText: true,
// draggable:false,
// editable:false,
content: '# AiEditor 是一个 **面向 AI 的** 下一代富文本编辑器。 \n **提示:** \n- 1、输入 空格 + "/" 可以快速弹出 AI 菜单 \n- 2、输入 空格 + "@" 可以提及某人 ' +
'\n\n haha ![图片alt](https://aieditor.com.cn/logo.png)' +
'\n ',
contentIsMarkdown: true,
content: 'AiEditor 是一个面向 AI 的下一代富文本编辑器。',
// contentIsMarkdown: true,
textSelectionBubbleMenu: {
// enable:false
//[AI, Bold, Italic, Underline, Strike, Code]
Expand Down
25 changes: 14 additions & 11 deletions src/util/htmlUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,23 @@ export const organizeHTMLContent = (originalHtml: string) => {
}

let html = '';
for (let i = 0; i < doc.body.children.length; i++) {
const element = doc.body.children[i];
if (i == 0 && element.tagName === "P") {
html += element.innerHTML;
} else {
// https://gitee.com/aieditor-team/aieditor/pulls/10
if (element.querySelector("img") && element.tagName !== "A") {
//return image element
doc.body.childNodes.forEach(node => {
if (node.nodeType === Node.TEXT_NODE) {
html += node.textContent;
} else if (node.nodeType === Node.ELEMENT_NODE) {
const element = node as HTMLElement;
if (element === doc.body.firstChild && element.tagName === "P") {
html += element.innerHTML;
} else {
html += element.outerHTML;
// https://gitee.com/aieditor-team/aieditor/pulls/10
if (element.querySelector("img") && element.tagName !== "A") {
//return image element
html += element.innerHTML;
} else {
html += element.outerHTML;
}
}
}
}
// debugger
})
return html;
}

0 comments on commit 405f4d9

Please sign in to comment.