This commit is contained in:
parent
4796883707
commit
8be251af00
5 changed files with 34 additions and 20 deletions
|
@ -431,7 +431,7 @@ export const copySubMenu = (id: string, accelerator = true, focusElement?: Eleme
|
|||
}];
|
||||
};
|
||||
|
||||
export const exportMd = (id: string) => {
|
||||
export const exportMd = (id: string, fileType = "NodeDocument") => {
|
||||
return new MenuItem({
|
||||
label: window.siyuan.languages.export,
|
||||
type: "submenu",
|
||||
|
@ -532,7 +532,7 @@ export const exportMd = (id: string) => {
|
|||
label: window.siyuan.languages.image,
|
||||
icon: "iconImage",
|
||||
click: () => {
|
||||
exportImage(id);
|
||||
exportImage(id, fileType);
|
||||
}
|
||||
},
|
||||
/// #if !BROWSER
|
||||
|
@ -540,26 +540,26 @@ export const exportMd = (id: string) => {
|
|||
label: "PDF",
|
||||
icon: "iconPDF",
|
||||
click: () => {
|
||||
saveExport({type: "pdf", id});
|
||||
saveExport({type: "pdf", id, fileType});
|
||||
}
|
||||
}, {
|
||||
label: "HTML (SiYuan)",
|
||||
iconClass: "ft__error",
|
||||
icon: "iconHTML5",
|
||||
click: () => {
|
||||
saveExport({type: "html", id});
|
||||
saveExport({type: "html", id, fileType});
|
||||
}
|
||||
}, {
|
||||
label: "HTML (Markdown)",
|
||||
icon: "iconHTML5",
|
||||
click: () => {
|
||||
saveExport({type: "htmlmd", id});
|
||||
saveExport({type: "htmlmd", id, fileType});
|
||||
}
|
||||
}, {
|
||||
label: "Word .docx",
|
||||
icon: "iconExact",
|
||||
click: () => {
|
||||
saveExport({type: "word", id});
|
||||
saveExport({type: "word", id, fileType});
|
||||
}
|
||||
}, {
|
||||
label: window.siyuan.languages.more,
|
||||
|
|
|
@ -14,15 +14,15 @@ import {pathPosix} from "../../util/pathName";
|
|||
import {replaceLocalPath} from "../../editor/rename";
|
||||
import {setStorageVal} from "../util/compatibility";
|
||||
|
||||
export const saveExport = (option: { type: string, id: string }) => {
|
||||
export const saveExport = (option: IExportOptions) => {
|
||||
/// #if !BROWSER
|
||||
if (option.type === "pdf") {
|
||||
if (window.siyuan.config.appearance.mode === 1) {
|
||||
confirmDialog(window.siyuan.languages.pdfTip, window.siyuan.languages.pdfConfirm, () => {
|
||||
renderPDF(option.id);
|
||||
renderPDF(option.id, option.fileType);
|
||||
});
|
||||
} else {
|
||||
renderPDF(option.id);
|
||||
renderPDF(option.id, option.fileType);
|
||||
}
|
||||
} else if (option.type === "word") {
|
||||
const localData = window.siyuan.storage[Constants.LOCAL_EXPORTWORD];
|
||||
|
@ -69,7 +69,7 @@ export const saveExport = (option: { type: string, id: string }) => {
|
|||
};
|
||||
|
||||
/// #if !BROWSER
|
||||
const renderPDF = (id: string) => {
|
||||
const renderPDF = (id: string, fileType:string) => {
|
||||
const localData = window.siyuan.storage[Constants.LOCAL_EXPORTPDF];
|
||||
const servePath = window.location.protocol + "//" + window.location.host;
|
||||
const isDefault = (window.siyuan.config.appearance.mode === 1 && window.siyuan.config.appearance.themeDark === "midnight") || (window.siyuan.config.appearance.mode === 0 && window.siyuan.config.appearance.themeLight === "daylight");
|
||||
|
@ -243,7 +243,9 @@ const renderPDF = (id: string) => {
|
|||
<button class="b3-button b3-button--text">${window.siyuan.languages.confirm}</button>
|
||||
</div>
|
||||
</div>
|
||||
<div style="zoom:${localData.scale || 1}" class="protyle-wysiwyg${window.siyuan.config.editor.displayBookmarkIcon ? " protyle-wysiwyg--attr" : ""}" id="preview">
|
||||
<div style="zoom:${localData.scale || 1}" class="protyle-wysiwyg${window.siyuan.config.editor.displayBookmarkIcon ? " protyle-wysiwyg--attr" : ""}"
|
||||
data-doc-type="${fileType}"
|
||||
id="preview">
|
||||
<div class="fn__loading" style="left:0"><img width="48px" src="${servePath}/stage/loading-pure.svg"></div>
|
||||
</div>
|
||||
<script src="${servePath}/appearance/icons/${window.siyuan.config.appearance.icon}/icon.js?${Constants.SIYUAN_VERSION}"></script>
|
||||
|
@ -515,7 +517,7 @@ const renderPDF = (id: string) => {
|
|||
});
|
||||
};
|
||||
|
||||
const getExportPath = (option: { type: string, id: string }, removeAssets?: boolean, mergeSubdocs?: boolean) => {
|
||||
const getExportPath = (option: IExportOptions, removeAssets?: boolean, mergeSubdocs?: boolean) => {
|
||||
fetchPost("/api/block/getBlockInfo", {
|
||||
id: option.id
|
||||
}, async (response) => {
|
||||
|
@ -569,17 +571,17 @@ const getExportPath = (option: { type: string, id: string }, removeAssets?: bool
|
|||
}
|
||||
afterExport(path.join(savePath, replaceLocalPath(response.data.rootTitle)) + ".docx", msgId);
|
||||
} else {
|
||||
onExport(exportResponse, savePath, option.type, removeAssets, msgId);
|
||||
onExport(exportResponse, savePath, option, removeAssets, msgId);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const onExport = (data: IWebSocketData, filePath: string, type: string, removeAssets?: boolean, msgId?: string) => {
|
||||
const onExport = (data: IWebSocketData, filePath: string, exportOption:IExportOptions, removeAssets?: boolean, msgId?: string) => {
|
||||
let themeName = window.siyuan.config.appearance.themeLight;
|
||||
let mode = 0;
|
||||
if (["html", "htmlmd"].includes(type) && window.siyuan.config.appearance.mode === 1) {
|
||||
if (["html", "htmlmd"].includes(exportOption.type) && window.siyuan.config.appearance.mode === 1) {
|
||||
themeName = window.siyuan.config.appearance.themeDark;
|
||||
mode = 1;
|
||||
}
|
||||
|
@ -607,7 +609,10 @@ const onExport = (data: IWebSocketData, filePath: string, type: string, removeAs
|
|||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="${["htmlmd", "word"].includes(type) ? "b3-typography" : "protyle-wysiwyg" + (window.siyuan.config.editor.displayBookmarkIcon ? " protyle-wysiwyg--attr" : "")}" style="max-width: 800px;margin: 0 auto;" id="preview">${data.data.content}</div>
|
||||
<div class="${["htmlmd", "word"].includes(exportOption.type) ? "b3-typography" : "protyle-wysiwyg" + (window.siyuan.config.editor.displayBookmarkIcon ? " protyle-wysiwyg--attr" : "")}"
|
||||
style="max-width: 800px;margin: 0 auto;"
|
||||
data-doc-type="${exportOption.fileType}"
|
||||
id="preview">${data.data.content}</div>
|
||||
<script src="appearance/icons/${window.siyuan.config.appearance.icon}/icon.js?${Constants.SIYUAN_VERSION}"></script>
|
||||
<script src="stage/build/export/protyle-method.js?${Constants.SIYUAN_VERSION}"></script>
|
||||
<script src="stage/protyle/js/lute/lute.min.js?${Constants.SIYUAN_VERSION}"></script>
|
||||
|
@ -627,7 +632,7 @@ const onExport = (data: IWebSocketData, filePath: string, type: string, removeAs
|
|||
};
|
||||
const previewElement = document.getElementById('preview');
|
||||
Protyle.highlightRender(previewElement, "stage/protyle");
|
||||
Protyle.mathRender(previewElement, "stage/protyle", ${type === "pdf"});
|
||||
Protyle.mathRender(previewElement, "stage/protyle", ${exportOption.type === "pdf"});
|
||||
Protyle.mermaidRender(previewElement, "stage/protyle");
|
||||
Protyle.flowchartRender(previewElement, "stage/protyle");
|
||||
Protyle.graphvizRender(previewElement, "stage/protyle");
|
||||
|
|
|
@ -25,11 +25,14 @@ export const afterExport = (exportPath: string, msgId: string) => {
|
|||
/// #endif
|
||||
};
|
||||
|
||||
export const exportImage = (id: string) => {
|
||||
export const exportImage = (id: string, fileType:string) => {
|
||||
const exportDialog = new Dialog({
|
||||
title: window.siyuan.languages.exportAsImage,
|
||||
content: `<div class="b3-dialog__content" style="${isMobile() ? "padding:8px;" : ""};background-color: var(--b3-theme-background)">
|
||||
<div style="${isMobile() ? "padding: 16px;margin: 16px 0" : "padding: 48px;margin: 8px 0 24px"};border: 1px solid var(--b3-border-color);border-radius: var(--b3-border-radius-b);" class="export-img protyle-wysiwyg${window.siyuan.config.editor.displayBookmarkIcon ? " protyle-wysiwyg--attr" : ""}" id="preview"></div>
|
||||
<div style="${isMobile() ? "padding: 16px;margin: 16px 0" : "padding: 48px;margin: 8px 0 24px"};border: 1px solid var(--b3-border-color);border-radius: var(--b3-border-radius-b);"
|
||||
class="export-img protyle-wysiwyg${window.siyuan.config.editor.displayBookmarkIcon ? " protyle-wysiwyg--attr" : ""}"
|
||||
data-doc-type="${fileType}"
|
||||
id="preview"></div>
|
||||
<div class="fn__hr--b"></div>
|
||||
<div class="fn__hr--b"></div>
|
||||
</div>
|
||||
|
|
|
@ -230,7 +230,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
|
|||
}).element);
|
||||
}
|
||||
genImportMenu(protyle.notebookId, protyle.path);
|
||||
window.siyuan.menus.menu.append(exportMd(protyle.block.showAll ? protyle.block.id : protyle.block.rootID));
|
||||
window.siyuan.menus.menu.append(exportMd(protyle.block.showAll ? protyle.block.id : protyle.block.rootID, protyle.wysiwyg.element.getAttribute("data-doc-type")));
|
||||
|
||||
if (protyle?.app?.plugins) {
|
||||
emitOpenMenu({
|
||||
|
|
6
app/src/types/index.d.ts
vendored
6
app/src/types/index.d.ts
vendored
|
@ -498,6 +498,12 @@ interface IPluginDockTab {
|
|||
show?: boolean
|
||||
}
|
||||
|
||||
interface IExportOptions {
|
||||
type: string,
|
||||
id: string,
|
||||
fileType: string
|
||||
}
|
||||
|
||||
interface IOpenFileOptions {
|
||||
app: import("../index").App,
|
||||
searchData?: ISearchOption, // 搜索必填
|
||||
|
|
Loading…
Add table
Reference in a new issue