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

支持多行注释文本的渲染;优化函数高亮

old
yutent 2023-01-12 17:59:05 +08:00
parent bcfdacce70
commit 9c78c80bc8
2 changed files with 15 additions and 5 deletions

View File

@ -20,8 +20,9 @@ const BUILDIN2 =
/\b(Object|String|Array|Boolean|Number|Function|class|Promise|Map|Set|WeakMap|WeakSet|URL)\b/g
const STR = /(['"`])(.*?)(?<!\\)\1/g
const NUM = /\b(\d+)\b/g
const FN = /([\.\s])([a-zA-Z$][\da-zA-Z_]*)(\(.*?\))/g
const CM = /(?=\s)?([ ]*\/\/.*)|(^\/\/.*)/g
const FN = /([\.\s])([a-zA-Z$_#][\da-zA-Z_]*)\s?(\(.*?\)?)/g
const CM1 = /(?=\s)?([ ]*\/\/.*)|(^\/\/.*)/g
const CM2 = /\/\*([\w\W]*?)\*\//g
const EXP = /([=\(][ ]*)\/(.+?)\/([gmi]*)/g
const INLINE = {
code: /`([^`]*?[^`\\\s])`/g,
@ -51,7 +52,7 @@ function parseJs(code) {
}`
})
.replace(FN, '$1[fn]$2[/fn]$3')
.replace(KEYWOWRD1, '[key]$1[/key]')
.replace(KEYWOWRD1, '[key]<em>$1</em>[/key]')
.replace(KEYWOWRD2, ' [key]$1[/key] ')
.replace(KEYWOWRD3, '[key]$1[/key]')
.replace(BUILDIN1, '[num]<em>$1</em>[/num]')
@ -67,7 +68,7 @@ function parseJs(code) {
return `[cm]${pun}[/cm][str]${str}[/str][cm]${pun}[/cm]`
})
.replace(CM, (m, str) => {
.replace(CM1, (m, str) => {
str = str
.replace(/\[(\w+)\](.*?)\[\/\1\]/g, '$2')
.replace(/&/g, '&amp;')
@ -75,6 +76,16 @@ function parseJs(code) {
.replace(/>/g, '&gt;')
return `[cm]${str}[/cm]`
})
.replace(CM2, (m, str) => {
str = str
.replace(/\[(\w+)\](.*?)\[\/\1\]/g, '$2')
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
str = `/*${str}*/`.split('\n').map(s => `[cm]${s}[/cm]`)
return str.join('\n')
})
}
function rebuild(code) {

View File

@ -80,7 +80,6 @@
.scroll {
overflow: hidden;
flex: 1;
padding: 5px 0 0;
line-height: 20px;
font-size: 14px;
color: var(--color-dark-1);