mirror of
https://github.com/doocs/md.git
synced 2024-11-24 19:10:34 +08:00
feat: export html page (#68)
This commit is contained in:
parent
e14a03c79b
commit
6e8763ff75
@ -235,6 +235,23 @@ export function downloadMD(doc) {
|
||||
document.body.removeChild(downLink);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出 HTML 生成内容
|
||||
* @param {HTML生成内容} htmlStr
|
||||
*/
|
||||
export function exportHTML(htmlStr) {
|
||||
const downLink = document.createElement('a')
|
||||
|
||||
downLink.download = 'content.html';
|
||||
downLink.style.display = "none";
|
||||
let blob = new Blob([`<html><body>${htmlStr}</body></html>`])
|
||||
|
||||
downLink.href = URL.createObjectURL(blob);
|
||||
document.body.appendChild(downLink);
|
||||
downLink.click();
|
||||
document.body.removeChild(downLink);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成列表字符串
|
||||
* @param {*} data 对应内容集合
|
||||
|
@ -22,6 +22,19 @@
|
||||
@click="$emit('download')"
|
||||
></i>
|
||||
</el-tooltip>
|
||||
<!-- 导出 HTML -->
|
||||
<el-tooltip
|
||||
class="header__item"
|
||||
:effect="effect"
|
||||
content="导出 HTML"
|
||||
placement="bottom-start"
|
||||
>
|
||||
<i
|
||||
class="el-icon-document"
|
||||
size="medium"
|
||||
@click="$emit('export')"
|
||||
></i>
|
||||
</el-tooltip>
|
||||
<!-- 页面重置 -->
|
||||
<el-tooltip
|
||||
class="header__item"
|
||||
|
@ -56,6 +56,10 @@ export default {
|
||||
text: "下载 Markdown 文档",
|
||||
key: "download",
|
||||
},
|
||||
{
|
||||
text: "导出 HTML",
|
||||
key: "export",
|
||||
},
|
||||
{
|
||||
text: "格式化 Markdown 文档",
|
||||
key: "formatMarkdown",
|
||||
|
@ -7,6 +7,7 @@
|
||||
@refresh="onEditorRefresh"
|
||||
@cssChanged="cssChanged"
|
||||
@download="downloadEditorContent"
|
||||
@export="exportEditorContent"
|
||||
@showCssEditor="showCssEditor = !showCssEditor"
|
||||
@show-about-dialog="aboutDialogVisible = true"
|
||||
@show-dialog-form="dialogFormVisible = true"
|
||||
@ -101,6 +102,7 @@ import uploadImgDialog from "../../../components/CodemirrorEditor/uploadImgDialo
|
||||
import {
|
||||
css2json,
|
||||
downloadMD,
|
||||
exportHTML,
|
||||
formatDoc,
|
||||
setFontSize,
|
||||
saveEditorContent,
|
||||
@ -330,6 +332,10 @@ export default {
|
||||
downloadEditorContent() {
|
||||
downloadMD(this.editor.getValue(0));
|
||||
},
|
||||
// 导出编辑器内容为 HTML,并且下载到本地
|
||||
exportEditorContent() {
|
||||
exportHTML(this.output);
|
||||
},
|
||||
// 格式化文档
|
||||
formatContent() {
|
||||
const doc = formatDoc(this.editor.getValue(0));
|
||||
@ -361,6 +367,9 @@ export default {
|
||||
case "download":
|
||||
this.downloadEditorContent();
|
||||
break;
|
||||
case "export":
|
||||
this.exportEditorContent();
|
||||
break;
|
||||
case "insertTable":
|
||||
this.dialogFormVisible = true;
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user