Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: fix https://github.com/siyuan-note/siyuan/issues/6764

Vanessa84c65c564afd
diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts
index f8b8f0d4c1..a1ee8e9d4f 100644
--- a/app/src/protyle/toolbar/index.ts
+++ b/app/src/protyle/toolbar/index.ts
@@ -1019,7 +1019,14 @@ export class Toolbar {
}
let inlineLastNode: Element;
if (types.includes("NodeHTMLBlock")) {
- renderElement.querySelector("protyle-html").setAttribute("data-content", Lute.EscapeHTMLStr(textElement.value));
+ // 需 div 包裹,否则行内元素会解析错误 https://github.com/siyuan-note/siyuan/issues/6764
+ let html = textElement.value;
+ if (!html.startsWith("<div>\n")) {
+ html = `<div>
+${html}
+</div>`;
+ }
+ renderElement.querySelector("protyle-html").setAttribute("data-content", Lute.EscapeHTMLStr(html));
} else if (isInlineMemo) {
let inlineMemoElements;
if (updateElements) {
diff --git a/app/stage/protyle/js/protyle-html.js b/app/stage/protyle/js/protyle-html.js
index 6ba4edd53c..972ddeae28 100644
--- a/app/stage/protyle/js/protyle-html.js
+++ b/app/stage/protyle/js/protyle-html.js
@@ -15,11 +15,7 @@ class ProtyleHtml extends HTMLElement {
if (name === 'data-content') {
const dataContent = Lute.UnEscapeHTMLStr(
this.getAttribute('data-content'))
- if (dataContent.startsWith('<div')) {
- this.display.innerHTML = dataContent
- } else {
- this.display.innerHTML = `<div>${dataContent}</div>`
- }
+ this.display.innerHTML = dataContent
const el = document.createElement('div')
el.innerHTML = dataContent