mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-29 19:56:10 +01:00
This commit is contained in:
parent
2a4531194c
commit
476b3a8467
2 changed files with 22 additions and 11 deletions
|
|
@ -309,6 +309,7 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false,
|
|||
if (!blockElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (blockElement.classList.contains("av")) {
|
||||
range.deleteContents();
|
||||
processAV(range, html, protyle, blockElement as HTMLElement);
|
||||
|
|
@ -318,15 +319,17 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false,
|
|||
processTable(range, html, protyle, blockElement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let id = blockElement.getAttribute("data-node-id");
|
||||
range.insertNode(document.createElement("wbr"));
|
||||
let oldHTML = blockElement.outerHTML;
|
||||
const isNodeCodeBlock = blockElement.getAttribute("data-type") === "NodeCodeBlock";
|
||||
const editableElement = getContenteditableElement(blockElement);
|
||||
if (!isBlock &&
|
||||
(isNodeCodeBlock || protyle.toolbar.getCurrentType(range).includes("code"))) {
|
||||
range.deleteContents();
|
||||
// 代码块需保持至少一个 \n https://github.com/siyuan-note/siyuan/pull/13271#issuecomment-2502672155
|
||||
if (isNodeCodeBlock && getContenteditableElement(blockElement).textContent === "") {
|
||||
if (isNodeCodeBlock && editableElement.textContent === "") {
|
||||
html += "\n";
|
||||
}
|
||||
range.insertNode(document.createTextNode(html.replace(/\r\n|\r|\u2028|\u2029/g, "\n")));
|
||||
|
|
@ -385,10 +388,18 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false,
|
|||
innerHTML = innerHTML.replace(/;;;lt;;;/g, "<").replace(/;;;gt;;;/g, ">");
|
||||
tempElement.innerHTML = innerHTML;
|
||||
|
||||
const editableElement = getContenteditableElement(blockElement);
|
||||
// https://github.com/siyuan-note/siyuan/issues/14114
|
||||
let heading2text = false;
|
||||
if (isBlock && editableElement.textContent.replace(Constants.ZWSP, "") !== "" && tempElement.content.childElementCount === 1 &&
|
||||
tempElement.content.firstChild.nodeType !== 3 &&
|
||||
tempElement.content.firstElementChild.getAttribute("data-type") === "NodeHeading") {
|
||||
isBlock = false;
|
||||
heading2text = true
|
||||
}
|
||||
|
||||
// 使用 lute 方法会添加 p 元素,只有一个 p 元素或者只有一个字符串或者为 <u>b</u> 时的时候只拷贝内部
|
||||
if (!isBlock) {
|
||||
if (tempElement.content.firstChild.nodeType === 3 ||
|
||||
if (tempElement.content.firstChild.nodeType === 3 || heading2text ||
|
||||
(tempElement.content.firstChild.nodeType !== 3 &&
|
||||
((tempElement.content.firstElementChild.classList.contains("p") && tempElement.content.childElementCount === 1) ||
|
||||
tempElement.content.firstElementChild.tagName !== "DIV"))) {
|
||||
|
|
|
|||
|
|
@ -366,14 +366,13 @@ export class WYSIWYG {
|
|||
const tempElement = document.createElement("div");
|
||||
// https://github.com/siyuan-note/siyuan/issues/5540
|
||||
const selectTypes = protyle.toolbar.getCurrentType(range);
|
||||
if ((selectTypes.length > 0 || range.startContainer.parentElement.parentElement.getAttribute("data-type") === "NodeHeading") &&
|
||||
(
|
||||
(range.startContainer.nodeType === 3 && range.startContainer.parentElement.textContent === range.toString()) ||
|
||||
(range.startContainer.nodeType !== 3 && range.startContainer.textContent === range.toString())
|
||||
)) {
|
||||
if (range.startContainer.parentElement.parentElement.getAttribute("data-type") === "NodeHeading") {
|
||||
const spanElement = hasClosestByTag(range.startContainer, "SPAN");
|
||||
const headingElement = hasClosestByAttribute(range.startContainer, "data-type", "NodeHeading");
|
||||
if ((selectTypes.length > 0 && spanElement && spanElement.textContent.replace(Constants.ZWSP, "") === range.toString()) ||
|
||||
(headingElement && headingElement.textContent.replace(Constants.ZWSP, "") === range.toString())) {
|
||||
if (headingElement) {
|
||||
// 复制标题 https://github.com/siyuan-note/insider/issues/297
|
||||
tempElement.append(range.startContainer.parentElement.parentElement.cloneNode(true));
|
||||
tempElement.append(headingElement.cloneNode(true));
|
||||
} else if (!["DIV", "TD", "TH", "TR"].includes(range.startContainer.parentElement.tagName)) {
|
||||
// 复制行内元素 https://github.com/siyuan-note/insider/issues/191
|
||||
tempElement.append(range.startContainer.parentElement.cloneNode(true));
|
||||
|
|
@ -388,7 +387,8 @@ export class WYSIWYG {
|
|||
} else if (selectImgElement) {
|
||||
html = selectImgElement.outerHTML;
|
||||
textPlain = selectImgElement.querySelector("img").getAttribute("data-src");
|
||||
} else if (selectTypes.length > 0 && range.startContainer.nodeType === 3 && range.startContainer.parentElement.tagName === "SPAN" &&
|
||||
} else if (selectTypes.length > 0 && range.startContainer.nodeType === 3 &&
|
||||
range.startContainer.parentElement.tagName === "SPAN" &&
|
||||
range.startContainer.parentElement.isSameNode(range.endContainer.parentElement)) {
|
||||
// 复制粗体等字体中的一部分
|
||||
const attributes = range.startContainer.parentElement.attributes;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue