mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-01 22:38:49 +01:00
This commit is contained in:
parent
83e6f5d664
commit
18377d0e9f
4 changed files with 44 additions and 17 deletions
|
|
@ -52,11 +52,14 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
|
|||
if (blockElement.getAttribute("data-type") === "NodeAttributeView") {
|
||||
return true;
|
||||
}
|
||||
// 代码块
|
||||
const trimStartText = editableElement.innerHTML.trimStart();
|
||||
if (trimStartText.startsWith("```") || trimStartText.startsWith("···") || trimStartText.startsWith("~~~") ||
|
||||
trimStartText.indexOf("\n```") > -1 || trimStartText.indexOf("\n~~~") > -1 || trimStartText.indexOf("\n···") > -1) {
|
||||
if (trimStartText.indexOf("\n") === -1 && trimStartText.replace(/·|~/g, "`").replace(/^`{3,}/g, "").indexOf("`") > -1) {
|
||||
|
||||
const trimStartHTML = editableElement.innerHTML.trimStart();
|
||||
const trimStartText = editableElement.textContent.trimStart();
|
||||
if (trimStartHTML.startsWith("```") || trimStartHTML.startsWith("···") || trimStartHTML.startsWith("~~~") ||
|
||||
(trimStartHTML.indexOf("\n```") > -1 && trimStartText.indexOf("\n```") > -1) ||
|
||||
(trimStartHTML.indexOf("\n~~~") > -1 && trimStartText.indexOf("\n~~~") > -1) ||
|
||||
(trimStartHTML.indexOf("\n···") > -1 && trimStartText.indexOf("\n···") > -1)) {
|
||||
if (trimStartHTML.indexOf("\n") === -1 && trimStartHTML.replace(/·|~/g, "`").replace(/^`{3,}/g, "").indexOf("`") > -1) {
|
||||
// ```test` 不处理,正常渲染为段落块
|
||||
} else if (blockElement.classList.contains("p")) { // https://github.com/siyuan-note/siyuan/issues/6953
|
||||
const oldHTML = blockElement.outerHTML;
|
||||
|
|
@ -93,6 +96,7 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
|
|||
return true;
|
||||
}
|
||||
}
|
||||
// 代码块
|
||||
if (blockElement.getAttribute("data-type") === "NodeCodeBlock") {
|
||||
const wbrElement = document.createElement("wbr");
|
||||
range.insertNode(wbrElement);
|
||||
|
|
@ -224,9 +228,12 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
|
|||
selectWbrElement.parentElement.outerHTML = "<wbr>";
|
||||
}
|
||||
const newHTML = newEditableElement.innerHTML.trimStart();
|
||||
const newText = newEditableElement.textContent.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) {
|
||||
(newHTML.indexOf("\n```") > -1 && newText.indexOf("\n```") > -1) ||
|
||||
(newHTML.indexOf("\n~~~") > -1 && newText.indexOf("\n~~~") > -1) ||
|
||||
(newHTML.indexOf("\n···") > -1 && newText.indexOf("\n···") > -1)) {
|
||||
if (newHTML.indexOf("\n") === -1 && newHTML.replace(/·|~/g, "`").replace(/^`{3,}/g, "").indexOf("`") > -1) {
|
||||
// ```test` 不处理,正常渲染为段落块
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -109,12 +109,13 @@ export const input = async (protyle: IProtyle, blockElement: HTMLElement, range:
|
|||
)) {
|
||||
editElement.innerHTML = editElement.innerHTML.replace("》<wbr>", "><wbr>");
|
||||
}
|
||||
const trimStartText = editElement.innerHTML.trimStart();
|
||||
if ((trimStartText.startsWith("````") || trimStartText.startsWith("····") || trimStartText.startsWith("~~~~")) &&
|
||||
trimStartText.indexOf("\n") === -1) {
|
||||
const trimStartHTML = editElement.innerHTML.trimStart();
|
||||
const trimStartText = editElement.textContent.trimStart();
|
||||
if ((trimStartHTML.startsWith("````") || trimStartHTML.startsWith("····") || trimStartHTML.startsWith("~~~~")) &&
|
||||
trimStartHTML.indexOf("\n") === -1) {
|
||||
// 超过三个标记符就可以形成为代码块,下方会处理
|
||||
} else if ((trimStartText.startsWith("```") || trimStartText.startsWith("···") || trimStartText.startsWith("~~~")) &&
|
||||
trimStartText.indexOf("\n") === -1 && trimStartText.replace(/·|~/g, "`").replace(/^`{3,}/g, "").indexOf("`") === -1) {
|
||||
} else if ((trimStartHTML.startsWith("```") || trimStartHTML.startsWith("···") || trimStartHTML.startsWith("~~~")) &&
|
||||
trimStartHTML.indexOf("\n") === -1 && trimStartHTML.replace(/·|~/g, "`").replace(/^`{3,}/g, "").indexOf("`") === -1) {
|
||||
// ```test` 后续处理,```test 不处理
|
||||
updateTransaction(protyle, id, blockElement.outerHTML, protyle.wysiwyg.lastHTMLs[id]);
|
||||
wbrElement.remove();
|
||||
|
|
@ -124,7 +125,7 @@ export const input = async (protyle: IProtyle, blockElement: HTMLElement, range:
|
|||
if (type === "NodeParagraph" && (
|
||||
editElement.innerHTML.startsWith("¥¥<wbr>") || editElement.innerHTML.startsWith("¥¥<wbr>") ||
|
||||
// https://ld246.com/article/1730020516427
|
||||
trimStartText.indexOf("\n¥¥<wbr>") > -1 || trimStartText.indexOf("\n¥¥<wbr>") > -1
|
||||
trimStartHTML.indexOf("\n¥¥<wbr>") > -1 || trimStartHTML.indexOf("\n¥¥<wbr>") > -1
|
||||
)) {
|
||||
editElement.innerHTML = editElement.innerHTML.replace("¥¥<wbr>", "$$$$<wbr>").replace("¥¥<wbr>", "$$$$<wbr>");
|
||||
}
|
||||
|
|
@ -153,10 +154,12 @@ export const input = async (protyle: IProtyle, blockElement: HTMLElement, range:
|
|||
}
|
||||
} else {
|
||||
if (type !== "NodeCodeBlock" && (
|
||||
trimStartText.startsWith("```") || trimStartText.startsWith("~~~") || trimStartText.startsWith("···") ||
|
||||
trimStartText.indexOf("\n```") > -1 || trimStartText.indexOf("\n~~~") > -1 || trimStartText.indexOf("\n···") > -1
|
||||
trimStartHTML.startsWith("```") || trimStartHTML.startsWith("~~~") || trimStartHTML.startsWith("···") ||
|
||||
(trimStartHTML.indexOf("\n```") > -1 && trimStartText.indexOf("\n```") > -1) ||
|
||||
(trimStartHTML.indexOf("\n~~~") > -1 && trimStartText.indexOf("\n~~~") > -1) ||
|
||||
(trimStartHTML.indexOf("\n···") > -1 && trimStartText.indexOf("\n···") > -1)
|
||||
)) {
|
||||
if (trimStartText.indexOf("\n") === -1 && trimStartText.replace(/·|~/g, "`").replace(/^`{3,}/g, "").indexOf("`") > -1) {
|
||||
if (trimStartHTML.indexOf("\n") === -1 && trimStartHTML.replace(/·|~/g, "`").replace(/^`{3,}/g, "").indexOf("`") > -1) {
|
||||
// ```test` 不处理,正常渲染为段落块
|
||||
} else {
|
||||
let replaceInnerHTML = editElement.innerHTML.trim().replace(/^(~|·|`){3,}/g, "```").replace(/\n(~|·|`){3,}/g, "\n```").trim();
|
||||
|
|
|
|||
|
|
@ -691,8 +691,8 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
} else {
|
||||
// 修正光标上移至 \n 结尾的块时落点错误 https://github.com/siyuan-note/siyuan/issues/14443
|
||||
const prevEditableElement = getContenteditableElement(previousElement) as HTMLElement;
|
||||
if (prevEditableElement && prevEditableElement.lastChild.nodeType === 3 &&
|
||||
prevEditableElement.lastChild.textContent.endsWith("\n")) {
|
||||
if (prevEditableElement && prevEditableElement.lastChild?.nodeType === 3 &&
|
||||
prevEditableElement.lastChild?.textContent.endsWith("\n")) {
|
||||
// 不能移除 /n, 否则两个 /n 导致界面异常
|
||||
focusBlock(previousElement, undefined, false);
|
||||
event.preventDefault();
|
||||
|
|
|
|||
|
|
@ -453,6 +453,23 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
|
|||
range.selectNodeContents(previousLastEditElement);
|
||||
range.collapse(false);
|
||||
range.insertNode(leftNodes);
|
||||
const previousHTML = previousLastEditElement.innerHTML.trimStart();
|
||||
const previousText = previousLastEditElement.textContent.trimStart();
|
||||
// https://github.com/siyuan-note/siyuan/issues/15554
|
||||
if (previousHTML.startsWith("```") || previousHTML.startsWith("···") || previousHTML.startsWith("~~~") ||
|
||||
(previousHTML.indexOf("\n```") > -1 && previousText.indexOf("\n```") > -1) ||
|
||||
(previousHTML.indexOf("\n~~~") > -1 && previousText.indexOf("\n~~~") > -1) ||
|
||||
(previousHTML.indexOf("\n···") > -1 && previousText.indexOf("\n···") > -1)) {
|
||||
if (previousHTML.indexOf("\n") === -1 && previousHTML.replace(/·|~/g, "`").replace(/^`{3,}/g, "").indexOf("`") > -1) {
|
||||
// ```test` 不处理,正常渲染为段落块
|
||||
} else {
|
||||
let replaceNewHTML = previousLastEditElement.innerHTML.replace(/\n(~|·|`){3,}/g, "\n```").trim().replace(/^(~|·|`){3,}/g, "```");
|
||||
if (!replaceNewHTML.endsWith("\n```")) {
|
||||
replaceNewHTML += "\n```";
|
||||
}
|
||||
previousLastEditElement.innerHTML = replaceNewHTML;
|
||||
}
|
||||
}
|
||||
// 图片前删除到上一个文字块时,图片前有 zwsp
|
||||
previousLastElement.outerHTML = protyle.lute.SpinBlockDOM(previousLastElement.outerHTML);
|
||||
mathRender(getPreviousBlock(removeElement) as HTMLElement);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue