From 30a8738092a88bb887e0fc80e28fa398e26580f5 Mon Sep 17 00:00:00 2001 From: yutent Date: Thu, 4 May 2023 15:24:48 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BC=98=E5=8C=96code=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E6=B8=B2=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/code/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/code/index.js b/src/code/index.js index ee61075..3f2cf55 100644 --- a/src/code/index.js +++ b/src/code/index.js @@ -194,7 +194,9 @@ class Code extends Component { txt = colorMd(txt) break } - + // 除代码高亮用的特殊标签 外, 其他的全部转义 + // 避免渲染时混乱 + txt = txt.replace(/<(\/?)(?!c)(\w+)([^>]*?)>/g, '<$1$2$3>') this.#code = txt.split('\n') } From 4f62a0adf3980116b580fbfbd34cd2e47ecc092a Mon Sep 17 00:00:00 2001 From: yutent Date: Thu, 4 May 2023 15:25:54 +0800 Subject: [PATCH 2/3] 0.1.12 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a7ffd07..23d92e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bd/ui", - "version": "0.1.11", + "version": "0.1.12", "description": "", "files": [ "dist/*" From c86a1d9dc6812d8bbe4cb753818ab031a7269bfa Mon Sep 17 00:00:00 2001 From: yutent Date: Thu, 4 May 2023 16:13:48 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=B8=B2=E6=9F=93=E6=B3=A8=E9=87=8A=E3=80=81?= =?UTF-8?q?xml=E5=BC=82=E5=B8=B8=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/code/index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/code/index.js b/src/code/index.js index 3f2cf55..ea4f60b 100644 --- a/src/code/index.js +++ b/src/code/index.js @@ -170,6 +170,7 @@ class Code extends Component { setCode(txt, a) { let lang = this.lang + let skip = false switch (lang) { case 'js': @@ -180,12 +181,14 @@ class Code extends Component { break case 'html': + case 'xml': txt = colorHtml(txt) break case 'css': case 'scss': case 'less': + skip = true txt = colorCss(txt) break @@ -196,7 +199,15 @@ class Code extends Component { } // 除代码高亮用的特殊标签 外, 其他的全部转义 // 避免渲染时混乱 - txt = txt.replace(/<(\/?)(?!c)(\w+)([^>]*?)>/g, '<$1$2$3>') + + if (skip === false) { + txt = txt + .replace(/<(\/?)(?!c)(\w+)([^>]*?)>/g, '<$1$2$3>') + .replace(/]*?)>/gi, '<$1$2>') + .replace(/<\?([^\?>]*?)\?>/g, '<?$1?>') + .replace(/<\!\-\-([^>]*?)\-\->/g, '<!--$1-->') + } + this.#code = txt.split('\n') }