Skip to content

Commit

Permalink
Merge branch 'mini' into browser
Browse files Browse the repository at this point in the history
  • Loading branch information
bhsd-harry committed May 8, 2024
2 parents 3783fcd + c03c706 commit a1d9b95
Show file tree
Hide file tree
Showing 11 changed files with 3 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

# 安装方法

Expand Down
2 changes: 0 additions & 2 deletions lib/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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*)' // 疑似标签
+ '|'
+ '\\{+|\\}+' // `{`、`}`
Expand Down
7 changes: 1 addition & 6 deletions parser/commentAndExt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,13 @@ export const parseCommentAndExt = (wikitext: string, config: Config, accum: Toke
return str;
}
}
/* eslint-disable @typescript-eslint/no-unused-expressions */
/<foo(?:\s[^>]*)?>|<\/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*>` // <noinclude>
+ `<${noincludeRegex}(?:\\s[^>]*)?/?>|</${noincludeRegex}\\s*>` // <noinclude>
+ '|'
+ `<(${ext})(\\s[^>]*?)?(?:/>|>(.*?)</(\\1\\s*)>)` // 扩展标签
+ '|'
Expand Down
2 changes: 0 additions & 2 deletions parser/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 0 additions & 2 deletions parser/externalLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'\\[' // 左括号
+ `(${
Expand Down
2 changes: 0 additions & 2 deletions parser/magicLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '',
Expand Down
2 changes: 0 additions & 2 deletions parser/redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 0 additions & 2 deletions src/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/=])*)' // 属性名
+ `(?:${
Expand Down
2 changes: 0 additions & 2 deletions src/imageParameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 0 additions & 2 deletions src/parameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit a1d9b95

Please sign in to comment.