From f6e2b4e3ba20f6c6cf190811635e42652e8d18f7 Mon Sep 17 00:00:00 2001 From: yanglbme Date: Sat, 7 Dec 2019 21:14:02 +0800 Subject: [PATCH] feat: add switch for footnotes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加脚注开关 --- assets/scripts/editor.js | 15 ++++++++++----- assets/scripts/renderers/wx-renderer.js | 7 +++---- index.html | 9 +++++++++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/assets/scripts/editor.js b/assets/scripts/editor.js index d448657..4ae77c1 100644 --- a/assets/scripts/editor.js +++ b/assets/scripts/editor.js @@ -37,6 +37,7 @@ let app = new Vue({ d.currentFont = d.builtinFonts[0].value; d.currentSize = d.sizeOption[1].value; d.currentColor = d.colorOption[0].value; + d.status = '1'; return d; }, mounted() { @@ -59,7 +60,8 @@ let app = new Vue({ this.wxRenderer = new WxRenderer({ theme: setColor(this.currentColor), fonts: this.currentFont, - size: this.currentSize + size: this.currentSize, + status: this.status }); // 如果有编辑内容被保存则读取,否则加载默认文档 if (localStorage.getItem("__editor_content")) { @@ -70,10 +72,10 @@ let app = new Vue({ }, methods: { renderWeChat(source) { - let output = marked(source, { renderer: this.wxRenderer.getRenderer() }); - if (this.wxRenderer.hasFootnotes()) { - // 去除第一行的 margin-top - output = output.replace(/(style=".*?)"/, '$1;margin-top: 0"'); + let output = marked(source, { renderer: this.wxRenderer.getRenderer(this.status) }); + // 去除第一行的 margin-top + output = output.replace(/(style=".*?)"/, '$1;margin-top: 0"'); + if (this.status) { // 引用脚注 output += this.wxRenderer.buildFootnotes(); // 附加的一些 style @@ -161,6 +163,9 @@ let app = new Vue({ this.editor.focus(); }); }, + statusChanged() { + this.refresh(); + }, // 将左侧编辑器内容保存到 LocalStorage saveEditorContent() { let content = this.editor.getValue(0); diff --git a/assets/scripts/renderers/wx-renderer.js b/assets/scripts/renderers/wx-renderer.js index 8a441ff..4d57f34 100644 --- a/assets/scripts/renderers/wx-renderer.js +++ b/assets/scripts/renderers/wx-renderer.js @@ -1,6 +1,5 @@ let WxRenderer = function (opts) { this.opts = opts; - let ENV_USE_REFERENCES = true; let ENV_STRETCH_IMAGE = true; let footnotes = []; @@ -92,7 +91,7 @@ let WxRenderer = function (opts) { this.hasFootnotes = () => footnotes.length !== 0; - this.getRenderer = () => { + this.getRenderer = (status) => { footnotes = []; footnoteIndex = 0; @@ -172,11 +171,11 @@ let WxRenderer = function (opts) { } else if (href === text) { return text; } else { - if (ENV_USE_REFERENCES) { + if (status) { let ref = addFootnote(title || text, href); return `${text}[${ref}]`; } else { - return `${text}`; + return text; } } }; diff --git a/index.html b/index.html index 26730c3..35e429d 100644 --- a/index.html +++ b/index.html @@ -82,6 +82,15 @@ +    + + + + 复制 关于