Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Mar 26, 2024
1 parent 139eb44 commit 3777453
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions app/src/protyle/wysiwyg/enter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,22 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
const id = blockElement.getAttribute("data-node-id");
const newElement = document.createElement("div");
newElement.appendChild(genEmptyElement(false, false));
newElement.querySelector('[contenteditable="true"]').appendChild(range.extractContents());
const newEditableElement = newElement.querySelector('[contenteditable="true"]');
newEditableElement.appendChild(range.extractContents());
const newHTML = newEditableElement.innerHTML.trimStart();
// https://github.com/siyuan-note/siyuan/issues/10759
if (newHTML.startsWith("```") || newHTML.startsWith("···") || newHTML.startsWith("~~~") ||
newHTML.indexOf("\n```") > -1 || newHTML.indexOf("\n~~~") > -1 || newHTML.indexOf("\n···") > -1) {
if (newHTML.indexOf("\n") === -1 && newHTML.replace(/·|~/g, "`").replace(/^`{3,}/g, "").indexOf("`") > -1) {
// ```test` 不处理,正常渲染为段落块
} else {
let replaceNewHTML = newEditableElement.innerHTML.replace(/\n(~|·|`){3,}/g, "\n```").trim().replace(/^(~|·|`){3,}/g, "```");
if (!replaceNewHTML.endsWith("\n```")) {
replaceNewHTML += "\n```";
}
newEditableElement.innerHTML = replaceNewHTML;
}
}
// https://github.com/siyuan-note/insider/issues/480
newElement.innerHTML = protyle.lute.SpinBlockDOM(newElement.innerHTML);

Expand Down Expand Up @@ -264,7 +279,11 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
id: newId,
});
previousElement.insertAdjacentElement("afterend", item);
mathRender(previousElement.nextElementSibling);
if (item.classList.contains("code-block")) {
highlightRender(item);
} else {
mathRender(previousElement.nextElementSibling);
}
previousElement = item;
});
transaction(protyle, doOperation, undoOperation);
Expand Down

0 comments on commit 3777453

Please sign in to comment.