Skip to content

Commit

Permalink
Merge branch 'noprint' into lint
Browse files Browse the repository at this point in the history
  • Loading branch information
bhsd-harry committed Aug 6, 2024
2 parents ac88852 + 7727ea2 commit 996ae33
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
17 changes: 9 additions & 8 deletions parser/magicLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ import {MagicLinkToken} from '../src/magicLink';
import type {Config} from '../base';
import type {Token} from '../src/index';

const space = String.raw`[\p{Zs}\t]| |&#0*160;|&#x0*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
* @param config
* @param accum
*/
export const parseMagicLinks = (wikitext: string, config: Config, accum: Token[]): string => {
const space = String.raw`[\p{Zs}\t]| |&#0*160;|&#x0*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) {
Expand Down
2 changes: 1 addition & 1 deletion src/heading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export class Token extends AstElement {
let errors = super.lint(start, re);
if (this.type === 'root') {
const record: Record<string, Set<CategoryToken | AttributeToken>> = {},
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<CategoryToken | AttributeToken>(selector)) {
let key;
if (cat.type === 'category') {
Expand Down
2 changes: 1 addition & 1 deletion src/tagPair/ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down

0 comments on commit 996ae33

Please sign in to comment.