diff --git a/README.en.md b/README.en.md index 253063561..7f0a9e044 100644 --- a/README.en.md +++ b/README.en.md @@ -18,7 +18,7 @@ This version provides a [CLI](https://en.wikipedia.org/wiki/Command-line_interfa ## Browser-compatible -A browser-compatible version, which can be used for code highlighting or as a linting plugin in conjunction with the [CodeMirror](https://codemirror.net/) editor. ([Usage example](https://bhsd-harry.github.io/wikiparser-node)) +A browser-compatible version, which can be used for code highlighting or as a linting plugin in conjunction with editors such as [CodeMirror](https://codemirror.net/) and [Monaco](https://microsoft.github.io/monaco-editor/). ([Usage example](https://bhsd-harry.github.io/wikiparser-node)) # Installation diff --git a/README.md b/README.md index 005f8d35b..d25c08cef 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ WikiParser-Node 是一款由 Bhsd 开发的基于 [Node.js](https://nodejs.org/) ## Browser-compatible -兼容浏览器的版本,可用于代码高亮或是搭配 [CodeMirror](https://codemirror.net/) 编辑器作为语法分析插件。([使用实例展示](https://bhsd-harry.github.io/wikiparser-node)) +兼容浏览器的版本,可用于代码高亮或是搭配 [CodeMirror](https://codemirror.net/) 和 [Monaco](https://microsoft.github.io/monaco-editor/) 等编辑器作为语法分析插件。([使用实例展示](https://bhsd-harry.github.io/wikiparser-node)) # 安装方法 diff --git a/lib/text.ts b/lib/text.ts index a16502bdc..ec81c75c2 100644 --- a/lib/text.ts +++ b/lib/text.ts @@ -11,8 +11,6 @@ import type { ExtToken, } from '../internal'; -// eslint-disable-next-line @typescript-eslint/no-unused-expressions -/<\s*(?:\/\s*)?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*?\])|((?:^|\])[^[]*?)\]+|https?[:/]\/+/giu; const source = '<\\s*(?:\\/\\s*)?([a-z]\\w*)' // 疑似标签 + '|' + '\\{+|\\}+' // `{`、`}` diff --git a/parser/commentAndExt.ts b/parser/commentAndExt.ts index 76503bf73..9b23bc5fa 100644 --- a/parser/commentAndExt.ts +++ b/parser/commentAndExt.ts @@ -53,18 +53,13 @@ export const parseCommentAndExt = (wikitext: string, config: Config, accum: Toke return str; } } - /* eslint-disable @typescript-eslint/no-unused-expressions */ - /]*)?>|<\/foo\s*>/giu; - /<(bar)(\s[^>]*?)?(?:\/>|>(.*?)<\/(\1\s*)>)/gisu; - /<(baz)(\s[^>]*?)?(?:\/>|>(.*?)(?:<\/(baz\s*)>|$))/gisu; - /* eslint-enable @typescript-eslint/no-unused-expressions */ const ext = config.ext.join('|'), noincludeRegex = includeOnly ? 'includeonly' : '(?:no|only)include', includeRegex = includeOnly ? 'noinclude' : 'includeonly', regex = new RegExp( '|$)' // comment + '|' - + `<${noincludeRegex}(?:\\s[^>]*)?>|` // + + `<${noincludeRegex}(?:\\s[^>]*)?/?>|` // + '|' + `<(${ext})(\\s[^>]*?)?(?:/>|>(.*?))` // 扩展标签 + '|' diff --git a/parser/converter.ts b/parser/converter.ts index 030248226..eb5cf209c 100644 --- a/parser/converter.ts +++ b/parser/converter.ts @@ -17,8 +17,6 @@ export const parseConverter = (text: string, config: Config, accum: Token[]): st while (mt) { const {0: syntax, index} = mt; if (syntax === '}-') { - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - /;(?=(?:[^;]*?=>)?\s*foo\s*:|(?:\s|\0\d+c\x7F)*$)/u; const top = stack.pop()!, {length} = accum, str = text.slice(top.index + 2, index), diff --git a/parser/externalLinks.ts b/parser/externalLinks.ts index 032408232..1c66ed344 100644 --- a/parser/externalLinks.ts +++ b/parser/externalLinks.ts @@ -12,8 +12,6 @@ import type {Token} from '../src/index'; * @param inFile 是否在图链中 */ export const parseExternalLinks = (wikitext: string, config: Config, accum: Token[], inFile?: boolean): string => { - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - /\[((?:\[[\da-f:.]+\]|[^[\]\t\n\p{Zs}])[^[\]\t\n\p{Zs}]*(?=[[\]\t\p{Zs}]|\0\d))(\p{Zs}*(?=\P{Zs}))([^\]\n]*)\]/giu; const regex = new RegExp( '\\[' // 左括号 + `(${ diff --git a/parser/magicLinks.ts b/parser/magicLinks.ts index 837ee86a9..d7d498ca3 100644 --- a/parser/magicLinks.ts +++ b/parser/magicLinks.ts @@ -10,8 +10,6 @@ import type {Token} from '../src/index'; * @param accum */ export const parseMagicLinks = (wikitext: string, config: Config, accum: Token[]): string => { - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - /(^|[^\p{L}\d_])((?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])(?:[^[\]<>"\0\t\n\p{Zs}]|\0\d+c\x7F)*)/giu; const regex = new RegExp(`(^|[^\\p{L}\\d_])(?:${config.protocol})(${extUrlCharFirst}${extUrlChar})`, 'giu'); return wikitext.replace(regex, (m, lead: string, p1: string) => { let trail = '', diff --git a/parser/redirect.ts b/parser/redirect.ts index ad9a81a09..a70b2a217 100644 --- a/parser/redirect.ts +++ b/parser/redirect.ts @@ -10,8 +10,6 @@ import type {Token} from '../src/index'; * @param accum */ export const parseRedirect = (text: string, config: Config, accum: Token[]): string | false => { - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - /^(\s*)((?:#redirect|#重定向)\s*(?::\s*)?)\[\[([^\n|\]]+)(\|.*?)?\]\](\s*)/iu; const re = new RegExp(`^(\\s*)((?:${ config.redirection.join('|') })\\s*(?::\\s*)?)\\[\\[([^\\n|\\]]+)(\\|.*?)?\\]\\](\\s*)`, 'iu'), diff --git a/src/attributes.ts b/src/attributes.ts index df51fef45..ed56e0b50 100644 --- a/src/attributes.ts +++ b/src/attributes.ts @@ -55,8 +55,6 @@ export abstract class AttributesToken extends Token { this.type = type; this.setAttribute('name', name); if (attr) { - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - /([^\s/](?:(?!\0\d+~\x7F)[^\s/=])*)(?:(\s*(?:=|\0\d+~\x7F)\s*)(?:(["'])(.*?)(\3|$)|(\S*)))?/gsu; const regex = new RegExp( '([^\\s/](?:(?!\0\\d+~\x7F)[^\\s/=])*)' // 属性名 + `(?:${ diff --git a/src/imageParameter.ts b/src/imageParameter.ts index 9cedf4a76..134229d37 100644 --- a/src/imageParameter.ts +++ b/src/imageParameter.ts @@ -38,8 +38,6 @@ function validate( if (!value) { return val; } - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - /^(?:\/\/(?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])|\0\d+m\x7F)(?:[^[\]<>"\0\t\n\p{Zs}]|\0\d+c\x7F)*$/iu; const regex = new RegExp( `^(?:(?:${config.protocol}|//)${extUrlCharFirst}|\0\\d+m\x7F)${extUrlChar}$`, 'iu', diff --git a/src/parameter.ts b/src/parameter.ts index 9e7d33a86..8660fac48 100644 --- a/src/parameter.ts +++ b/src/parameter.ts @@ -78,8 +78,6 @@ export abstract class ParameterToken extends Token { /** @override */ override lint(start = this.getAbsoluteIndex(), re?: RegExp): LintError[] { - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - /https?:\/\/(?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])(?:[^[\]<>"\0\t\n\p{Zs}]|\0\d+c\x7F)*$/iu; const errors = super.lint(start, re), {firstChild} = this, link = new RegExp(`https?://${extUrlCharFirst}${extUrlChar}$`, 'iu').exec(firstChild.text())?.[0];