feat: export html page (#68)

This commit is contained in:
小树 2021-10-14 20:12:19 +08:00 committed by GitHub
parent e14a03c79b
commit 6e8763ff75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 0 deletions

View File

@ -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 对应内容集合

View File

@ -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"

View File

@ -56,6 +56,10 @@ export default {
text: "下载 Markdown 文档",
key: "download",
},
{
text: "导出 HTML",
key: "export",
},
{
text: "格式化 Markdown 文档",
key: "formatMarkdown",

View File

@ -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;