From 0e990eb657bd60720cac5aa5d2e4d99393c2cf22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Tue, 18 May 2021 11:27:36 +0800 Subject: [PATCH] =?UTF-8?q?markd=E6=94=AF=E6=8C=81=E4=BC=A0=E5=85=A5hide-c?= =?UTF-8?q?opy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/markd/core.js | 12 ++++++++---- src/markd/index.wc | 7 ++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/markd/core.js b/src/markd/core.js index 43d2d8f..0811116 100644 --- a/src/markd/core.js +++ b/src/markd/core.js @@ -189,7 +189,7 @@ class Tool { } // 初始化字符串, 处理多余换行等 - static init(str) { + static init(str, hideCopy) { var links = {} var list = [] var lines = str.split('\n') @@ -206,10 +206,14 @@ class Tool { if (tmp) { emptyLineLength = 0 if (tmp.startsWith('```')) { + let attr = hideCopy ? ' hide-copy' : '' + if (isCodeBlock) { list.push('') } else { - list.push(tmp.replace(/^```([\w\#\-]*?)$/, '')) + list.push( + tmp.replace(/^```([\w\#\-]*?)$/, ``) + ) } isCodeBlock = !isCodeBlock } else { @@ -563,6 +567,6 @@ class Tool { } } -export default function(str) { - return Tool.init(fixed(str)).parse() +export default function(str, hideCopy) { + return Tool.init(fixed(str), hideCopy).parse() } diff --git a/src/markd/index.wc b/src/markd/index.wc index f592546..4e38127 100644 --- a/src/markd/index.wc +++ b/src/markd/index.wc @@ -190,6 +190,7 @@ import '../form/checkbox' export default class Markd { props = { md: '', + 'hide-copy': false, toc: false } @@ -205,7 +206,7 @@ export default class Markd { set md(txt) { if (txt) { - this.__BOX__.innerHTML = markd(txt) + this.__BOX__.innerHTML = markd(txt, this.props['hide-copy']) } else { this.__BOX__.innerHTML = '' } @@ -252,6 +253,10 @@ export default class Markd { this.md = val } break + + case 'hide-copy': + this.props[name] = val !== null + break } } }