Vanessa 2025-03-08 11:22:13 +08:00
parent 6ad42a4556
commit 8218184ece
2 changed files with 38 additions and 2 deletions

View File

@ -82,7 +82,15 @@ export const getPlainText = (blockElement: HTMLElement, isNested = false) => {
} else if (blockElement.classList.contains("render-node")) { } else if (blockElement.classList.contains("render-node")) {
// 需在嵌入块后,代码块前 // 需在嵌入块后,代码块前
text += Lute.UnEscapeHTMLStr(blockElement.getAttribute("data-content")); text += Lute.UnEscapeHTMLStr(blockElement.getAttribute("data-content"));
} else if (["NodeHeading", "NodeParagraph", "NodeCodeBlock", "NodeTable"].includes(dataType)) { } else if (["NodeHeading", "NodeParagraph", "NodeCodeBlock"].includes(dataType)) {
text += blockElement.querySelector("[spellcheck]").textContent;
} else if (dataType ==="NodeTable") {
blockElement.querySelectorAll("th, td").forEach((item) => {
text += item.textContent.trim() + "\t";
if (!item.nextElementSibling) {
text = text.slice(0, -1) + "\n";
}
});
text += blockElement.querySelector("[spellcheck]").textContent; text += blockElement.querySelector("[spellcheck]").textContent;
} else if (!isNested && ["NodeBlockquote", "NodeList", "NodeSuperBlock", "NodeListItem"].includes(dataType)) { } else if (!isNested && ["NodeBlockquote", "NodeList", "NodeSuperBlock", "NodeListItem"].includes(dataType)) {
blockElement.querySelectorAll("[data-node-id]").forEach((item: HTMLElement) => { blockElement.querySelectorAll("[data-node-id]").forEach((item: HTMLElement) => {

View File

@ -63,7 +63,7 @@ import {openGlobalSearch} from "../../search/util";
import {popSearch} from "../../mobile/menu/search"; import {popSearch} from "../../mobile/menu/search";
/// #endif /// #endif
import {BlockPanel} from "../../block/Panel"; import {BlockPanel} from "../../block/Panel";
import {isInIOS, isMac, isOnlyMeta, readClipboard} from "../util/compatibility"; import {copyPlainText, isInIOS, isMac, isOnlyMeta, readClipboard} from "../util/compatibility";
import {MenuItem} from "../../menus/Menu"; import {MenuItem} from "../../menus/Menu";
import {fetchPost} from "../../util/fetch"; import {fetchPost} from "../../util/fetch";
import {onGet} from "../util/onGet"; import {onGet} from "../util/onGet";
@ -1295,6 +1295,34 @@ export class WYSIWYG {
}).element); }).element);
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element); window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
} }
window.siyuan.menus.menu.append(new MenuItem({
id: "copyPlainText",
label: window.siyuan.languages.copyPlainText,
click() {
if (tableBlockElement) {
const selectCellElements: HTMLTableCellElement[] = [];
const scrollLeft = tableBlockElement.firstElementChild.scrollLeft;
const tableSelectElement = tableBlockElement.querySelector(".table__select") as HTMLElement;
tableBlockElement.querySelectorAll("th, td").forEach((item: HTMLTableCellElement) => {
if (!item.classList.contains("fn__none") &&
item.offsetLeft + 6 > tableSelectElement.offsetLeft + scrollLeft && item.offsetLeft + item.clientWidth - 6 < tableSelectElement.offsetLeft + scrollLeft + tableSelectElement.clientWidth &&
item.offsetTop + 6 > tableSelectElement.offsetTop && item.offsetTop + item.clientHeight - 6 < tableSelectElement.offsetTop + tableSelectElement.clientHeight) {
selectCellElements.push(item);
}
});
let textPlain = "";
selectCellElements.forEach((item, index) => {
textPlain += item.textContent.trim() + "\t";
if (!item.nextElementSibling || !selectCellElements[index + 1] ||
!item.nextElementSibling.isSameNode(selectCellElements[index + 1])) {
textPlain = textPlain.slice(0, -1) + "\n";
}
});
copyPlainText(textPlain);
focusBlock(tableBlockElement);
}
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
icon: "iconCopy", icon: "iconCopy",
accelerator: "⌘C", accelerator: "⌘C",