Skip to content

Commit

Permalink
feat(base): infer maxStage from token type(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
bhsd-harry authored Oct 1, 2024
1 parent 356938d commit 5c30094
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,35 @@ export type TokenTypes = 'root'
| 'param-line'
| 'imagemap-link';

export const stages = {
redirect: 1,
onlyinclude: 1,
noinclude: 1,
include: 1,
comment: 1,
ext: 1,
arg: 2,
'magic-word': 2,
template: 2,
heading: 2,
html: 3,
table: 4,
hr: 5,
'double-underscore': 5,
link: 6,
category: 6,
file: 6,
quote: 7,
'ext-link': 8,
'free-ext-link': 9,
'magic-link': 9,
list: 10,
dd: 10,
converter: 11,
};

export type Stage = keyof typeof stages;

export const rules = [
'bold-header',
'format-leakage',
Expand Down Expand Up @@ -208,5 +237,5 @@ export interface Parser {
* @param include 是否嵌入
* @param maxStage 最大解析层级
*/
parse(wikitext: string, include?: boolean, maxStage?: number, config?: Config): Token;
parse(wikitext: string, include?: boolean, maxStage?: number | Stage | Stage[], config?: Config): Token;
}

0 comments on commit 5c30094

Please sign in to comment.