import {i18n} from "../i18n"; import {getHTML} from "../markdown/getHTML"; import {getMarkdown} from "../markdown/getMarkdown"; export const download = (vditor: IVditor, content: string, filename: string) => { const aElement = document.createElement("a"); if ("download" in aElement) { aElement.download = filename; aElement.style.display = "none"; aElement.href = URL.createObjectURL(new Blob([content])); document.body.appendChild(aElement); aElement.click(); aElement.remove(); } else { vditor.tip.show(i18n[vditor.options.lang].downloadTip, 0); } }; export const exportMarkdown = (vditor: IVditor) => { const content = getMarkdown(vditor); download(vditor, content, content.substr(0, 10) + ".md"); }; export const exportPDF = (vditor: IVditor) => { vditor.tip.show(i18n[vditor.options.lang].generate, 3800); const iframe = document.querySelector("iframe"); iframe.contentDocument.open(); iframe.contentDocument.write(`
`); iframe.contentDocument.close(); setTimeout(() => { iframe.contentWindow.postMessage(getMarkdown(vditor), "*"); }, 200); }; export const exportHTML = (vditor: IVditor) => { const content = getHTML(vditor); const html = `
${content}
`; download(vditor, html, content.substr(0, 10) + ".html"); };