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

old
宇天 2021-04-18 23:59:39 +08:00
parent ec26d32d8e
commit a4a8f7dfe1
2 changed files with 27 additions and 18 deletions

View File

@ -11,10 +11,14 @@
"url": "git+https://github.com/bytedo/wcui.git"
},
"main": "dist/",
"keywords": ["web-components", "wc", "components", "yutent"],
"keywords": [
"web-components",
"wc",
"components",
"yutent"
],
"author": "yutent",
"license": "MIT",
"dependencies": {},
"devDependencies": {
"chalk": "^2.4.2",
"chokidar": "^1.7.0",

View File

@ -159,7 +159,12 @@ import { colorHtml, colorCss } from './colorful'
export default class Code {
props = {
dark: '',
lang: ''
lang: '',
code: ''
}
state = {
content: ''
}
__init__() {
@ -176,17 +181,14 @@ export default class Code {
this.__CP__ = header.children[2].lastElementChild
}
get value() {
return this.props.content
get code() {
return this.state.content
}
set value(txt) {
txt = txt
.replace(/&/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
set code(txt) {
txt = txt.replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>')
this.props.content = txt
this.state.content = txt
switch (this.props.lang) {
case 'html':
@ -218,9 +220,10 @@ export default class Code {
if (txt.startsWith('<xmp>') && txt.endsWith('</xmp>')) {
txt = txt.slice(5, -6).trim()
}
if (txt) {
this.value = txt
this.textContent = ''
}
this._cpFN = $.bind(this.__CP__, 'click', ev => {
try {
@ -248,13 +251,15 @@ export default class Code {
watch() {
switch (name) {
case 'lang':
this.props.lang = val.toLowerCase()
this.props.lang = (val || '').toLowerCase()
this.__LANG__.textContent = this.props.lang
break
case 'value':
this.value = val
this.removeAttribute('value')
case 'code':
if (val !== null) {
this.code = val
this.removeAttribute('code')
}
break
}
}