Browse Source

:art: https://github.com/siyuan-note/siyuan/pull/13271

Vanessa 8 months ago
parent
commit
7feba07e35
1 changed files with 4 additions and 0 deletions
  1. 4 0
      app/src/protyle/util/insertHTML.ts

+ 4 - 0
app/src/protyle/util/insertHTML.ts

@@ -298,6 +298,10 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false,
     if (!isBlock &&
     if (!isBlock &&
         (isNodeCodeBlock || protyle.toolbar.getCurrentType(range).includes("code"))) {
         (isNodeCodeBlock || protyle.toolbar.getCurrentType(range).includes("code"))) {
         range.deleteContents();
         range.deleteContents();
+        // 代码块需保持至少一个 \n https://github.com/siyuan-note/siyuan/pull/13271#issuecomment-2502672155
+        if (isNodeCodeBlock && getContenteditableElement(blockElement).textContent === "") {
+            html += "\n";
+        }
         range.insertNode(document.createTextNode(html.replace(/\r\n|\r|\u2028|\u2029/g, "\n")));
         range.insertNode(document.createTextNode(html.replace(/\r\n|\r|\u2028|\u2029/g, "\n")));
         range.collapse(false);
         range.collapse(false);
         range.insertNode(document.createElement("wbr"));
         range.insertNode(document.createElement("wbr"));