mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-30 12:15:16 +01:00
This commit is contained in:
parent
563e2d03ba
commit
be4611bf31
6 changed files with 43 additions and 42 deletions
|
|
@ -7,7 +7,7 @@ import {focusBlock, getEditorRange, focusByWbr} from "./selection";
|
|||
import {mathRender} from "../markdown/mathRender";
|
||||
import {Constants} from "../../constants";
|
||||
|
||||
export const insertHTML = (html: string, protyle: IProtyle, isBlock = false) => {
|
||||
export const insertHTML = (html: string, protyle: IProtyle, isBlock = false, splitSpan = true) => {
|
||||
if (html === "") {
|
||||
return;
|
||||
}
|
||||
|
|
@ -89,7 +89,7 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false) =>
|
|||
}
|
||||
// 粘贴带样式的行内元素到另一个行内元素中需进行切割
|
||||
const spanElement = range.startContainer.nodeType === 3 ? range.startContainer.parentElement: range.startContainer as HTMLElement;
|
||||
if (spanElement.tagName === "SPAN" && spanElement.isSameNode( range.endContainer.nodeType === 3 ? range.endContainer.parentElement: range.endContainer)) {
|
||||
if (splitSpan && spanElement.tagName === "SPAN" && spanElement.isSameNode( range.endContainer.nodeType === 3 ? range.endContainer.parentElement: range.endContainer)) {
|
||||
const afterElement = document.createElement("span");
|
||||
const attributes = spanElement.attributes;
|
||||
for (let i = 0; i < attributes.length; i++) {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import {processPasteCode, processRender} from "./processCode";
|
|||
import {writeText} from "./compatibility";
|
||||
/// #if !BROWSER
|
||||
import {clipboard} from "electron";
|
||||
import * as path from "path";
|
||||
/// #endif
|
||||
import {hasClosestBlock} from "./hasClosest";
|
||||
import {focusByWbr, getEditorRange} from "./selection";
|
||||
|
|
@ -30,6 +31,34 @@ const filterClipboardHint = (protyle: IProtyle, textPlain: string) => {
|
|||
}
|
||||
};
|
||||
|
||||
export const pasteAsPlainText = async (protyle:IProtyle) => {
|
||||
/// #if !BROWSER && !MOBILE
|
||||
let localFiles: string[] = [];
|
||||
if ("darwin" === window.siyuan.config.system.os) {
|
||||
const xmlString = clipboard.read("NSFilenamesPboardType");
|
||||
const domParser = new DOMParser();
|
||||
const xmlDom = domParser.parseFromString(xmlString, "application/xml");
|
||||
Array.from(xmlDom.getElementsByTagName("string")).forEach(item => {
|
||||
localFiles.push(item.childNodes[0].nodeValue);
|
||||
});
|
||||
} else {
|
||||
const xmlString = await fetchSyncPost("/api/clipboard/readFilePaths", {});
|
||||
if (xmlString.data.length > 0) {
|
||||
localFiles = xmlString.data;
|
||||
}
|
||||
}
|
||||
if (localFiles.length > 0) {
|
||||
let fileText = "";
|
||||
localFiles.forEach((item) => {
|
||||
fileText += `[${path.basename(item).replace(/\]/g, "\\]").replace(/\[/g, "\\[")}](file://${item.replace(/\\/g, "\\\\").replace(/\)/g, "\\)").replace(/\(/g, "\\(")})\n`;
|
||||
});
|
||||
insertHTML(protyle.lute.SpinBlockDOM(fileText), protyle);
|
||||
} else {
|
||||
insertHTML(protyle.lute.BlockDOM2Content(protyle.lute.InlineMd2BlockDOM(clipboard.readText())), protyle, false, false);
|
||||
}
|
||||
/// #endif
|
||||
}
|
||||
|
||||
export const pasteText = (protyle: IProtyle, textPlain: string, nodeElement: Element) => {
|
||||
const range = getEditorRange(protyle.wysiwyg.element);
|
||||
const id = nodeElement.getAttribute("data-node-id");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue