mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
This commit is contained in:
parent
028e3118c4
commit
c0b68b1e5e
5 changed files with 121 additions and 96 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import {fetchPost} from "../../util/fetch";
|
||||
import {fetchPost, fetchSyncPost} from "../../util/fetch";
|
||||
import {Constants} from "../../constants";
|
||||
import {focusByRange, focusByWbr} from "../util/selection";
|
||||
import {writeText} from "../util/compatibility";
|
||||
|
||||
export const previewTemplate = (pathString: string, element: Element, parentId: string) => {
|
||||
if (!pathString) {
|
||||
|
|
@ -213,3 +214,34 @@ export const toolbarKeyToMenu = (toolbar: Array<string | IMenuItem>) => {
|
|||
});
|
||||
return toolbarResult;
|
||||
};
|
||||
|
||||
export const copyTextByType = async (ids: string[],
|
||||
type: "ref" | "blockEmbed" | "protocol" | "protocolMd" | "hPath" | "id") => {
|
||||
let text = "";
|
||||
for (let i = 0; i < ids.length; i++) {
|
||||
const id = ids[i];
|
||||
if (ids.length > 1) {
|
||||
text += "* ";
|
||||
}
|
||||
if (type === "ref") {
|
||||
const response = await fetchSyncPost("/api/block/getRefText", {id});
|
||||
text += `((${id} '${response.data}'))`;
|
||||
} else if (type === "blockEmbed") {
|
||||
text += `{{select * from blocks where id='${id}'}}`;
|
||||
} else if (type === "protocol") {
|
||||
text += `siyuan://blocks/${id}`;
|
||||
} else if (type === "protocolMd") {
|
||||
const response = await fetchSyncPost("/api/block/getRefText", {id});
|
||||
text += `[${response.data}](siyuan://blocks/${id})`;
|
||||
} else if (type === "hPath") {
|
||||
const response = await fetchSyncPost("/api/filetree/getHPathByID", {id});
|
||||
text += response.data;
|
||||
} else if (type === "id") {
|
||||
text += id;
|
||||
}
|
||||
if (ids.length > 1 && i !== ids.length - 1) {
|
||||
text += "\n";
|
||||
}
|
||||
}
|
||||
writeText(text);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue