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 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('</wc-code>')
} else {
list.push(tmp.replace(/^```([\w\#\-]*?)$/, '<wc-code lang="$1">'))
list.push(
tmp.replace(/^```([\w\#\-]*?)$/, `<wc-code lang="$1"${attr}>`)
)
}
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()
}

View File

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