This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues/pull-requests.
bytedo
/
wcui
Archived
1
0
Fork 0

markd支持传入hide-copy

old
宇天 2021-05-18 11:27:36 +08:00
parent 222f4d56eb
commit 0e990eb657
2 changed files with 14 additions and 5 deletions

View File

@ -189,7 +189,7 @@ class Tool {
} }
// 初始化字符串, 处理多余换行等 // 初始化字符串, 处理多余换行等
static init(str) { static init(str, hideCopy) {
var links = {} var links = {}
var list = [] var list = []
var lines = str.split('\n') var lines = str.split('\n')
@ -206,10 +206,14 @@ class Tool {
if (tmp) { if (tmp) {
emptyLineLength = 0 emptyLineLength = 0
if (tmp.startsWith('```')) { if (tmp.startsWith('```')) {
let attr = hideCopy ? ' hide-copy' : ''
if (isCodeBlock) { if (isCodeBlock) {
list.push('</wc-code>') list.push('</wc-code>')
} else { } else {
list.push(tmp.replace(/^```([\w\#\-]*?)$/, '<wc-code lang="$1">')) list.push(
tmp.replace(/^```([\w\#\-]*?)$/, `<wc-code lang="$1"${attr}>`)
)
} }
isCodeBlock = !isCodeBlock isCodeBlock = !isCodeBlock
} else { } else {
@ -563,6 +567,6 @@ class Tool {
} }
} }
export default function(str) { export default function(str, hideCopy) {
return Tool.init(fixed(str)).parse() return Tool.init(fixed(str), hideCopy).parse()
} }

View File

@ -190,6 +190,7 @@ import '../form/checkbox'
export default class Markd { export default class Markd {
props = { props = {
md: '', md: '',
'hide-copy': false,
toc: false toc: false
} }
@ -205,7 +206,7 @@ export default class Markd {
set md(txt) { set md(txt) {
if (txt) { if (txt) {
this.__BOX__.innerHTML = markd(txt) this.__BOX__.innerHTML = markd(txt, this.props['hide-copy'])
} else { } else {
this.__BOX__.innerHTML = '' this.__BOX__.innerHTML = ''
} }
@ -252,6 +253,10 @@ export default class Markd {
this.md = val this.md = val
} }
break break
case 'hide-copy':
this.props[name] = val !== null
break
} }
} }
} }