mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-24 02:20:13 +01:00
This commit is contained in:
parent
675d585e3a
commit
94fb5673d7
3 changed files with 34 additions and 6 deletions
|
|
@ -1,4 +1,9 @@
|
|||
import {hasClosestBlock, hasClosestByAttribute, hasClosestByMatchTag, hasClosestByTag} from "../util/hasClosest";
|
||||
import {
|
||||
hasClosestBlock,
|
||||
hasClosestByAttribute,
|
||||
hasClosestByMatchTag,
|
||||
hasClosestByTag
|
||||
} from "../util/hasClosest";
|
||||
import {getIconByType} from "../../editor/getIcon";
|
||||
import {iframeMenu, setFold, tableMenu, videoMenu, zoomOut} from "../../menus/protyle";
|
||||
import {MenuItem} from "../../menus/Menu";
|
||||
|
|
@ -16,7 +21,7 @@ import {hideElements} from "../ui/hideElements";
|
|||
import {processRender} from "../util/processCode";
|
||||
import {highlightRender} from "../markdown/highlightRender";
|
||||
import {blockRender} from "../markdown/blockRender";
|
||||
import {removeEmbed} from "../wysiwyg/removeEmbed";
|
||||
import {getEnableHTML, removeEmbed} from "../wysiwyg/removeEmbed";
|
||||
import {getContenteditableElement, getTopAloneElement, isNotEditBlock} from "../wysiwyg/getBlock";
|
||||
import * as dayjs from "dayjs";
|
||||
import {fetchPost, fetchSyncPost} from "../../util/fetch";
|
||||
|
|
@ -583,7 +588,7 @@ export class Gutter {
|
|||
click() {
|
||||
let html = "";
|
||||
selectsElement.forEach(item => {
|
||||
item.querySelectorAll('[contenteditable="true"]').forEach(editItem => {
|
||||
item.querySelectorAll('[spellcheck="false"]').forEach(editItem => {
|
||||
const cloneNode = editItem.cloneNode(true) as HTMLElement;
|
||||
cloneNode.querySelectorAll('[data-type="backslash"]').forEach(slashItem => {
|
||||
slashItem.firstElementChild.remove();
|
||||
|
|
@ -600,6 +605,9 @@ export class Gutter {
|
|||
selectsElement.forEach(item => {
|
||||
html += item.outerHTML;
|
||||
});
|
||||
if (protyle.disabled) {
|
||||
html = getEnableHTML(html)
|
||||
}
|
||||
writeText(protyle.lute.BlockDOM2HTML(html));
|
||||
}
|
||||
}, {
|
||||
|
|
@ -959,7 +967,7 @@ export class Gutter {
|
|||
accelerator: window.siyuan.config.keymap.editor.general.copyPlainText.custom,
|
||||
click() {
|
||||
let text = "";
|
||||
nodeElement.querySelectorAll('[contenteditable="true"]').forEach(item => {
|
||||
nodeElement.querySelectorAll('[spellcheck="false"]').forEach(item => {
|
||||
const cloneNode = item.cloneNode(true) as HTMLElement;
|
||||
cloneNode.querySelectorAll('[data-type="backslash"]').forEach(slashItem => {
|
||||
slashItem.firstElementChild.remove();
|
||||
|
|
@ -971,7 +979,11 @@ export class Gutter {
|
|||
}, {
|
||||
label: window.siyuan.languages.copy + " HTML",
|
||||
click() {
|
||||
writeText(protyle.lute.BlockDOM2HTML(nodeElement.outerHTML));
|
||||
let html = nodeElement.outerHTML
|
||||
if (protyle.disabled) {
|
||||
html = getEnableHTML(html)
|
||||
}
|
||||
writeText(protyle.lute.BlockDOM2HTML(html));
|
||||
}
|
||||
}, {
|
||||
label: window.siyuan.languages.duplicate,
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ import {hideElements} from "../ui/hideElements";
|
|||
import {shell} from "electron";
|
||||
import {getCurrentWindow} from "@electron/remote";
|
||||
/// #endif
|
||||
import {removeEmbed} from "./removeEmbed";
|
||||
import {getEnableHTML, removeEmbed} from "./removeEmbed";
|
||||
import {keydown} from "./keydown";
|
||||
import {openMobileFileById} from "../../mobile/editor";
|
||||
import {removeBlock} from "./remove";
|
||||
|
|
@ -277,6 +277,9 @@ export class WYSIWYG {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (protyle.disabled) {
|
||||
html = getEnableHTML(html)
|
||||
}
|
||||
event.clipboardData.setData("text/plain", textPlain || protyle.lute.BlockDOM2StdMd(html).trimEnd());
|
||||
event.clipboardData.setData("text/html", html + Constants.ZWSP);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import {hasClosestByClassName} from "../util/hasClosest";
|
||||
|
||||
export const removeEmbed = (element: Element, type: "outerHTML" | "innerHTML" = "outerHTML") => {
|
||||
// 防止内容块引用嵌入的标签打断 lute 渲染
|
||||
// :zap:
|
||||
|
|
@ -11,3 +13,14 @@ export const removeEmbed = (element: Element, type: "outerHTML" | "innerHTML" =
|
|||
});
|
||||
return cloneElement[type];
|
||||
};
|
||||
|
||||
export const getEnableHTML = (html: string) => {
|
||||
const tempElement = document.createElement("template");
|
||||
tempElement.innerHTML = html;
|
||||
tempElement.content.querySelectorAll('[contenteditable="false"][spellcheck="false"]').forEach(item => {
|
||||
if (!hasClosestByClassName(item, "protyle-wysiwyg__embed")) {
|
||||
item.setAttribute("contenteditable", "true");
|
||||
}
|
||||
});
|
||||
return tempElement.innerHTML;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue