mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
This commit is contained in:
parent
fc1cbf46aa
commit
4e4398ef47
3 changed files with 31 additions and 10 deletions
|
@ -23,24 +23,30 @@ export const encodeBase64 = (text: string): string => {
|
|||
}
|
||||
};
|
||||
|
||||
const getSiyuanHTML = (text: IClipboardData) => {
|
||||
const siyuanMatch = text.textHTML.match(/<!--data-siyuan='([^']+)'-->/);
|
||||
export const getTextSiyuanFromTextHTML = (html: string) => {
|
||||
const siyuanMatch = html.match(/<!--data-siyuan='([^']+)'-->/);
|
||||
let textSiyuan = "";
|
||||
let textHtml = html;
|
||||
if (siyuanMatch) {
|
||||
try {
|
||||
if (typeof Buffer !== "undefined") {
|
||||
const decodedBytes = Buffer.from(siyuanMatch[1], "base64");
|
||||
text.siyuanHTML = decodedBytes.toString("utf8");
|
||||
textSiyuan = decodedBytes.toString("utf8");
|
||||
} else {
|
||||
const decoder = new TextDecoder();
|
||||
const bytes = Uint8Array.from(atob(siyuanMatch[1]), char => char.charCodeAt(0));
|
||||
text.siyuanHTML = decoder.decode(bytes);
|
||||
textSiyuan = decoder.decode(bytes);
|
||||
}
|
||||
// 移除注释节点,保持原有的 text/html 内容
|
||||
text.textHTML = text.textHTML.replace(/<!--data-siyuan='[^']+'-->/, "");
|
||||
textHtml = html.replace(/<!--data-siyuan='[^']+'-->/, "");
|
||||
} catch (e) {
|
||||
console.log("Failed to decode siyuan data from HTML comment:", e);
|
||||
}
|
||||
}
|
||||
return {
|
||||
textSiyuan,
|
||||
textHtml
|
||||
};
|
||||
};
|
||||
|
||||
export const openByMobile = (uri: string) => {
|
||||
|
@ -124,7 +130,9 @@ export const readClipboard = async () => {
|
|||
if (item.types.includes("text/html")) {
|
||||
const blob = await item.getType("text/html");
|
||||
text.textHTML = await blob.text();
|
||||
getSiyuanHTML(text);
|
||||
const textObj = getTextSiyuanFromTextHTML(text.textHTML);
|
||||
text.textHTML = textObj.textHtml;
|
||||
text.siyuanHTML = textObj.textSiyuan;
|
||||
}
|
||||
if (item.types.includes("text/plain")) {
|
||||
const blob = await item.getType("text/plain");
|
||||
|
@ -145,11 +153,15 @@ export const readClipboard = async () => {
|
|||
if (isInAndroid()) {
|
||||
text.textPlain = window.JSAndroid.readClipboard();
|
||||
text.textHTML = window.JSAndroid.readHTMLClipboard();
|
||||
getSiyuanHTML(text);
|
||||
const textObj = getTextSiyuanFromTextHTML(text.textHTML);
|
||||
text.textHTML = textObj.textHtml;
|
||||
text.siyuanHTML = textObj.textSiyuan;
|
||||
} else if (isInHarmony()) {
|
||||
text.textPlain = window.JSHarmony.readClipboard();
|
||||
text.textHTML = window.JSHarmony.readHTMLClipboard();
|
||||
getSiyuanHTML(text);
|
||||
const textObj = getTextSiyuanFromTextHTML(text.textHTML);
|
||||
text.textHTML = textObj.textHtml;
|
||||
text.siyuanHTML = textObj.textSiyuan;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
|
|
@ -463,10 +463,13 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false,
|
|||
foldHeadingId = item.getAttribute("data-node-id");
|
||||
return true;
|
||||
}
|
||||
if (foldHeadingId && item.getAttribute("parent-heading") === foldHeadingId) {
|
||||
if (foldHeadingId && item.getAttribute("parent-heading")) {
|
||||
foldHTML += item.outerHTML;
|
||||
}
|
||||
});
|
||||
if (foldHeadingId && foldHTML) {
|
||||
fetchPost("/api/block/appendHeadingChildren", {id: foldHeadingId, dom: foldHTML});
|
||||
}
|
||||
(insertBefore ? Array.from(tempElement.content.children) : Array.from(tempElement.content.children).reverse()).find((item) => {
|
||||
if (item.getAttribute("parent-heading")) {
|
||||
return;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {Constants} from "../../constants";
|
||||
import {uploadFiles, uploadLocalFiles} from "../upload";
|
||||
import {processPasteCode, processRender} from "./processCode";
|
||||
import {getLocalFiles, readText} from "./compatibility";
|
||||
import {getLocalFiles, getTextSiyuanFromTextHTML, readText} from "./compatibility";
|
||||
import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "./hasClosest";
|
||||
import {getEditorRange} from "./selection";
|
||||
import {blockRender} from "../render/blockRender";
|
||||
|
@ -288,6 +288,12 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
|
|||
if (textPlain.endsWith(Constants.ZWSP) && !textHTML && !siyuanHTML) {
|
||||
siyuanHTML = textPlain.substr(0, textPlain.length - 1);
|
||||
}
|
||||
// 复制/剪切折叠标题需获取 siyuanHTML
|
||||
if (textHTML && textPlain && !siyuanHTML) {
|
||||
const textObj = getTextSiyuanFromTextHTML(textHTML);
|
||||
siyuanHTML = textObj.textSiyuan;
|
||||
textHTML = textObj.textHtml;
|
||||
}
|
||||
// 剪切复制中首位包含空格或仅有空格 https://github.com/siyuan-note/siyuan/issues/5667
|
||||
if (!siyuanHTML) {
|
||||
// process word
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue