🎨 Document supports copying as Markdown (#15397)

*  Document supports copying standard Markdown

*  Document supports copying as Markdown
This commit is contained in:
Jeffrey Chen 2025-08-02 09:38:43 +08:00 committed by GitHub
parent 77ead023f8
commit 9a89a0eb4c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 43 additions and 4 deletions

View file

@ -6,7 +6,7 @@ import {getSearch, isMobile, isValidAttrName} from "../util/functions";
import {isLocalPath, movePathTo, moveToPath, pathPosix} from "../util/pathName";
import {MenuItem} from "./Menu";
import {saveExport} from "../protyle/export";
import {isInAndroid, isInHarmony, openByMobile} from "../protyle/util/compatibility";
import {isInAndroid, isInHarmony, openByMobile, writeText} from "../protyle/util/compatibility";
import {fetchPost, fetchSyncPost} from "../util/fetch";
import {hideMessage, showMessage} from "../dialog/message";
import {Dialog} from "../dialog";
@ -380,8 +380,8 @@ export const openAttr = (nodeElement: Element, focusName = "bookmark", protyle?:
});
};
export const copySubMenu = (ids: string[], accelerator = true, focusElement?: Element) => {
return [{
export const copySubMenu = (ids: string[], accelerator = true, focusElement?: Element, stdMarkdownId?: string) => {
const menuItems = [{
id: "copyBlockRef",
iconHTML: "",
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyBlockRef.custom : undefined,
@ -448,6 +448,32 @@ export const copySubMenu = (ids: string[], accelerator = true, focusElement?: El
}
}
}];
if (stdMarkdownId) {
menuItems.push({
id: "copyMarkdown",
iconHTML: "",
label: window.siyuan.languages.copyMarkdown,
accelerator: undefined,
click: async () => {
const response = await fetchSyncPost("/api/export/exportMdContent", {
id: stdMarkdownId,
refMode: 3,
embedMode: 1,
yfm: false,
fillCSSVar: false,
adjustHeadingLevel: false
});
const text = response.data.content;
writeText(text);
if (focusElement) {
focusBlock(focusElement);
}
}
});
}
return menuItems;
};
export const exportMd = (id: string) => {