diff --git a/parser/magicLinks.ts b/parser/magicLinks.ts index b2706924..9bc83ef3 100644 --- a/parser/magicLinks.ts +++ b/parser/magicLinks.ts @@ -3,6 +3,11 @@ import {MagicLinkToken} from '../src/magicLink'; import type {Config} from '../base'; import type {Token} from '../src/index'; +const space = String.raw`[\p{Zs}\t]| |�*160;|�*a0;`, + sp = `(?:${space})+`, + spdash = `(?:${space}|-)`, + magicLinkPattern = String.raw`(?:RFC|PMID)${sp}\d+\b|ISBN${sp}(?:97[89]${spdash}?)?(?:\d${spdash}?){9}[\dx]\b`; + /** * 解析自由外链 * @param wikitext @@ -10,14 +15,10 @@ import type {Token} from '../src/index'; * @param accum */ export const parseMagicLinks = (wikitext: string, config: Config, accum: Token[]): string => { - const space = String.raw`[\p{Zs}\t]| |�*160;|�*a0;`, - spdash = `(?:${space}|-)`, - regex = new RegExp( - String.raw`(^|[^\p{L}\d_])(?:(?:${config.protocol})(${extUrlCharFirst}${ - extUrlChar - })|(?:RFC|PMID)(?:${space})+\d+\b|ISBN(?:${space})+(?:97[89]${spdash}?)?(?:\d${spdash}?){9}[\dx]\b)`, - 'giu', - ); + const regex = new RegExp( + String.raw`(^|[^\p{L}\d_])(?:(?:${config.protocol})(${extUrlCharFirst}${extUrlChar})|${magicLinkPattern})`, + 'giu', + ); return wikitext.replace(regex, (m, lead: string, p1: string | undefined) => { let url = lead ? m.slice(lead.length) : m; if (p1) { diff --git a/src/heading.ts b/src/heading.ts index ed50dd26..da81b72b 100644 --- a/src/heading.ts +++ b/src/heading.ts @@ -94,7 +94,7 @@ export abstract class HeadingToken extends Token { Parser.msg('unbalanced $1 in a section header', '"="'), )); } - if (this.closest('html-attrs, table-attrs')) { + if (this.closest('html-attrs,table-attrs')) { errors.push(generateForSelf(this, rect, 'parsing-order', 'section header in a HTML tag')); } if (boldQuotes.length % 2) { diff --git a/src/index.ts b/src/index.ts index da26bb8b..b2ad87b5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -400,7 +400,7 @@ export class Token extends AstElement { let errors = super.lint(start, re); if (this.type === 'root') { const record: Record> = {}, - selector = 'category, html-attr#id, ext-attr#id, table-attr#id'; + selector = 'category,html-attr#id,ext-attr#id,table-attr#id'; for (const cat of this.querySelectorAll(selector)) { let key; if (cat.type === 'category') { diff --git a/src/tagPair/ext.ts b/src/tagPair/ext.ts index 66ee6312..1943a843 100644 --- a/src/tagPair/ext.ts +++ b/src/tagPair/ext.ts @@ -161,7 +161,7 @@ export abstract class ExtToken extends TagPairToken { override lint(start = this.getAbsoluteIndex(), re?: RegExp): LintError[] { const errors = super.lint(start, re), rect = new BoundingRect(this, start); - if (this.name !== 'nowiki' && this.closest('html-attrs, table-attrs')) { + if (this.name !== 'nowiki' && this.closest('html-attrs,table-attrs')) { errors.push(generateForSelf(this, rect, 'parsing-order', 'extension tag in HTML tag attributes')); } if (this.name === 'ref' && this.closest('heading-title')) {