From 66687150f8673b8c2c78575be4db2c01267c6d6e Mon Sep 17 00:00:00 2001 From: yutent Date: Mon, 24 Apr 2023 18:36:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96css=E9=AB=98=E4=BA=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test.md | 133 -------------------------------------------------------- 1 file changed, 133 deletions(-) delete mode 100644 test.md diff --git a/test.md b/test.md deleted file mode 100644 index 0dc3efa..0000000 --- a/test.md +++ /dev/null @@ -1,133 +0,0 @@ -```html -
-
-
-
${this.lang}
- -
-
- ${this.#code.map(s => html`${raw(s)}`)} -
-
-``` - - -```js -import { html, raw, css, Component, nextTick } from '@bd/core' -import { colorHtml, colorJs, colorCss, colorMd } from './colorful.js' -import '../icon/index.js' -import '../layer/index.js' - -function trim(str) { - return str - .trim() - .replace(/</g, '<') - .replace(/>/g, '>') - .replace(/&/g, '&') -} - -class Code extends Component { - static props = { - code: { - type: String, - default: '', - attribute: false, - observer(v) { - this.setCode(v.trim()) - } - }, - lang: '' - } - - - - #code = [] - - setCode(txt, a) { - let lang = this.lang - - switch (lang) { - case 'js': - case 'javascript': - case 'ts': - case 'typescript': - txt = colorJs(txt) - break - - case 'html': - txt = colorHtml(txt) - break - - case 'css': - case 'scss': - case 'less': - txt = colorCss(txt) - break - - case 'md': - case 'markdown': - txt = colorMd(txt) - break - } - - this.#code = txt.split('\n') - } - - copyCode() { - navigator.clipboard.writeText(this.code) - layer.toast('复制到粘贴板成功', 'success') - } - - mounted() { - var txt = this.innerHTML || this.textContent - txt = txt.trim().replace(/^[\r\n]|\s{2,}$/g, '') - - if (txt.startsWith('') && txt.endsWith('')) { - txt = txt.slice(5, -6).trim() - } else if (this.firstElementChild?.tagName === 'TEXTAREA') { - txt = this.firstElementChild.value.trim() - } else if (txt.startsWith('
') && txt.endsWith('
')) { - txt = trim(txt.slice(5, -6)) - } else { - txt = trim(txt) - } - - this.textContent = '' - if (txt) { - nextTick(_ => { - this.code = txt - }) - } - } - - render() { - let foo = html`
${this.#code.map(s => html`${s}`)}
` - - return html` -
-
-
-
${this.lang}
- -
-
- ${this.#code.map(s => html`${raw(s)}`)} -
-
- ` - } -} - -Code.reg('code') - -``` \ No newline at end of file