This commit is contained in:
parent
30c902a01c
commit
cc099ff315
3 changed files with 47 additions and 23 deletions
|
@ -759,7 +759,7 @@ export class Toolbar {
|
|||
window.siyuan.menus.menu.remove();
|
||||
const id = nodeElement.getAttribute("data-node-id");
|
||||
const types = (renderElement.getAttribute("data-type") || "").split(" ");
|
||||
const html = oldHTML || protyle.lute.SpinBlockDOM(nodeElement.outerHTML);
|
||||
const html = oldHTML || nodeElement.outerHTML;
|
||||
let title = "HTML";
|
||||
let placeholder = "";
|
||||
const isInlineMemo = types.includes("inline-memo");
|
||||
|
@ -1009,16 +1009,16 @@ export class Toolbar {
|
|||
}
|
||||
let inlineLastNode: Element;
|
||||
if (types.includes("NodeHTMLBlock")) {
|
||||
let html = textElement.value;
|
||||
if (html) {
|
||||
let htmlText = textElement.value;
|
||||
if (htmlText) {
|
||||
// 需移除首尾的空白字符与连续的换行 (空行) https://github.com/siyuan-note/siyuan/issues/7921
|
||||
html = html.trim().replace(/\n+/g, "\n");
|
||||
htmlText = htmlText.trim().replace(/\n+/g, "\n");
|
||||
// 需一对 div 标签包裹,否则行内元素会解析错误 https://github.com/siyuan-note/siyuan/issues/6764
|
||||
if (!(html.startsWith("<div>") && html.endsWith("</div>"))) {
|
||||
html = `<div>\n${html}\n</div>`;
|
||||
if (!(htmlText.startsWith("<div>") && htmlText.endsWith("</div>"))) {
|
||||
htmlText = `<div>\n${htmlText}\n</div>`;
|
||||
}
|
||||
}
|
||||
renderElement.querySelector("protyle-html").setAttribute("data-content", Lute.EscapeHTMLStr(html));
|
||||
renderElement.querySelector("protyle-html").setAttribute("data-content", Lute.EscapeHTMLStr(htmlText));
|
||||
} else if (isInlineMemo) {
|
||||
let inlineMemoElements;
|
||||
if (updateElements) {
|
||||
|
@ -1100,16 +1100,15 @@ export class Toolbar {
|
|||
}
|
||||
|
||||
nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
|
||||
const newHTML = protyle.lute.SpinBlockDOM(nodeElement.outerHTML);
|
||||
// HTML 块中包含多个 <pre> 时只能保存第一个 https://github.com/siyuan-note/siyuan/issues/5732
|
||||
if (types.includes("NodeHTMLBlock")) {
|
||||
const tempElement = document.createElement("template");
|
||||
tempElement.innerHTML = newHTML;
|
||||
tempElement.innerHTML = protyle.lute.SpinBlockDOM(nodeElement.outerHTML);
|
||||
if (tempElement.content.childElementCount > 1) {
|
||||
showMessage(window.siyuan.languages.htmlBlockTip);
|
||||
}
|
||||
}
|
||||
updateTransaction(protyle, id, newHTML, html);
|
||||
updateTransaction(protyle, id, nodeElement.outerHTML, html);
|
||||
};
|
||||
this.subElement.style.zIndex = (++window.siyuan.zIndex).toString();
|
||||
this.subElement.classList.remove("fn__none");
|
||||
|
|
|
@ -382,19 +382,39 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
|
|||
// 图片后的零宽空格前回车 https://github.com/siyuan-note/siyuan/issues/5690
|
||||
const enterElement = document.createElement("div");
|
||||
enterElement.innerHTML = protyle.lute.SpinBlockDOM(editableElement.parentElement.outerHTML);
|
||||
editableElement.innerHTML = enterElement.querySelector('[contenteditable="true"]').innerHTML;
|
||||
mathRender(editableElement);
|
||||
const doOperation: IOperation[] = [];
|
||||
const undoOperation: IOperation[] = [];
|
||||
// 回车之前的块为 1\n\n2 时会产生多个块
|
||||
Array.from(enterElement.children).forEach((item: HTMLElement) => {
|
||||
if (item.dataset.nodeId === id) {
|
||||
editableElement.innerHTML = item.querySelector('[contenteditable="true"]').innerHTML;
|
||||
doOperation.push({
|
||||
action: "update",
|
||||
data: blockElement.outerHTML,
|
||||
id,
|
||||
})
|
||||
undoOperation.push({
|
||||
action: "update",
|
||||
data: html,
|
||||
id,
|
||||
})
|
||||
mathRender(editableElement);
|
||||
} else {
|
||||
doOperation.push({
|
||||
action: "insert",
|
||||
data: item.outerHTML,
|
||||
id: item.dataset.nodeId,
|
||||
nextID: id,
|
||||
})
|
||||
blockElement.insertAdjacentElement("beforebegin", item);
|
||||
undoOperation.push({
|
||||
action: "delete",
|
||||
id: item.dataset.nodeId,
|
||||
})
|
||||
mathRender(item);
|
||||
}
|
||||
})
|
||||
|
||||
const doOperation: IOperation[] = [{
|
||||
action: "update",
|
||||
data: blockElement.outerHTML,
|
||||
id: id,
|
||||
}];
|
||||
const undoOperation: IOperation[] = [{
|
||||
action: "update",
|
||||
data: html,
|
||||
id: id,
|
||||
}];
|
||||
let previousElement = blockElement;
|
||||
Array.from(newElement.children).forEach((item: HTMLElement) => {
|
||||
const newId = item.getAttribute("data-node-id");
|
||||
|
|
|
@ -336,7 +336,12 @@ const deleteBlock = (updateElements: Element[], id: string, protyle: IProtyle, i
|
|||
|
||||
const updateBlock = (updateElements: Element[], protyle: IProtyle, operation: IOperation, isUndo: boolean) => {
|
||||
updateElements.forEach(item => {
|
||||
item.outerHTML = operation.data;
|
||||
// 图标撤销后无法渲染
|
||||
if (item.getAttribute("data-subtype") === "echarts") {
|
||||
item.outerHTML = protyle.lute.SpinBlockDOM(operation.data);
|
||||
} else {
|
||||
item.outerHTML = operation.data;
|
||||
}
|
||||
});
|
||||
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`)).find(item => {
|
||||
if (item.getAttribute("data-type") === "NodeBlockQueryEmbed" // 引用转换为块嵌入,undo、redo 后也需要更新 updateElement
|
||||
|
|
Loading…
Add table
Reference in a new issue