From feeab444df20faf64ff31ff987987a1fa74cac9b Mon Sep 17 00:00:00 2001 From: yanglbme Date: Thu, 19 Dec 2019 21:04:13 +0800 Subject: [PATCH] feat: add one-click download function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增一键下载功能 --- README.md | 1 + assets/scripts/editor.js | 14 ++++++++++++++ index.html | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/README.md b/README.md index ba29fd6..34efa5c 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ Markdown 文档自动即时渲染为微信图文,让你不再为微信文章 - [x] 支持链接微信图文,外链自动转为文末索引 - [x] 支持一键复制并粘贴到公众号后台 - [x] 支持多图上传并将 URL 插入编辑器光标定位处 +- [x] 支持一键下载 Markdown 文档到本地 - [x] 支持自定义 CSS 样式并实时渲染 - [x] 支持一键恢复至默认内容及样式 - [x] 支持打开或关闭引用链接的选项 diff --git a/assets/scripts/editor.js b/assets/scripts/editor.js index 3967abe..9c026d8 100644 --- a/assets/scripts/editor.js +++ b/assets/scripts/editor.js @@ -202,6 +202,19 @@ let app = new Vue({ localStorage.removeItem(name); } }, + // 下载编辑器内容到本地 + downloadEditorContent() { + let downLink = document.createElement('a'); + downLink.download = 'content.md'; + downLink.style.display = 'none'; + let blob = new Blob([this.editor.getValue(0)]); + downLink.href = URL.createObjectURL(blob); + console.log(downLink); + document.body.appendChild(downLink); + downLink.click(); + document.body.removeChild(downLink); + }, + // 自定义CSS样式 async customStyle() { this.showBox = !this.showBox; let flag = await localStorage.getItem("__css_content") @@ -209,6 +222,7 @@ let app = new Vue({ this.cssEditor.setValue(DEFAULT_CSS_CONTENT); } }, + // 复制渲染后的内容到剪贴板 copy() { let clipboardDiv = document.getElementById('output'); clipboardDiv.focus(); diff --git a/index.html b/index.html index ba05467..1d1c13c 100644 --- a/index.html +++ b/index.html @@ -50,6 +50,10 @@   + + +   +