wikiparser-node 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/dist/base.d.ts +45 -0
  4. package/dist/bin/toc.js +2 -2
  5. package/dist/index.d.ts +6 -30
  6. package/dist/index.js +1 -1
  7. package/dist/lib/element.d.ts +3 -3
  8. package/dist/lib/element.js +2 -2
  9. package/dist/lib/node.d.ts +5 -2
  10. package/dist/lib/node.js +0 -1
  11. package/dist/lib/text.d.ts +4 -2
  12. package/dist/lib/text.js +6 -1
  13. package/dist/src/arg.d.ts +1 -1
  14. package/dist/src/atom.d.ts +1 -1
  15. package/dist/src/attribute.d.ts +1 -1
  16. package/dist/src/attributes.d.ts +1 -1
  17. package/dist/src/attributes.js +0 -1
  18. package/dist/src/converterFlags.d.ts +1 -1
  19. package/dist/src/converterRule.js +8 -17
  20. package/dist/src/gallery.d.ts +1 -1
  21. package/dist/src/heading.d.ts +2 -6
  22. package/dist/src/heading.js +5 -4
  23. package/dist/src/html.d.ts +2 -3
  24. package/dist/src/imageParameter.d.ts +1 -1
  25. package/dist/src/imagemap.d.ts +1 -1
  26. package/dist/src/link/base.d.ts +1 -1
  27. package/dist/src/link/base.js +16 -7
  28. package/dist/src/link/file.d.ts +1 -1
  29. package/dist/src/link/galleryImage.d.ts +3 -1
  30. package/dist/src/link/galleryImage.js +15 -7
  31. package/dist/src/magicLink.d.ts +1 -1
  32. package/dist/src/nested.d.ts +1 -1
  33. package/dist/src/nowiki/comment.d.ts +2 -2
  34. package/dist/src/nowiki/comment.js +1 -1
  35. package/dist/src/nowiki/index.d.ts +1 -1
  36. package/dist/src/nowiki/quote.d.ts +1 -1
  37. package/dist/src/nowiki/quote.js +2 -2
  38. package/dist/src/paramTag/index.d.ts +1 -1
  39. package/dist/src/parameter.d.ts +1 -1
  40. package/dist/src/parameter.js +0 -4
  41. package/dist/src/table/index.d.ts +1 -1
  42. package/dist/src/table/td.d.ts +1 -1
  43. package/dist/src/table/td.js +2 -2
  44. package/dist/src/table/trBase.d.ts +1 -1
  45. package/dist/src/tagPair/ext.d.ts +1 -1
  46. package/dist/src/transclude.d.ts +1 -1
  47. package/dist/src/transclude.js +1 -6
  48. package/dist/util/constants.js +2 -4
  49. package/dist/util/debug.js +1 -4
  50. package/dist/util/diff.js +0 -2
  51. package/dist/util/lint.js +0 -2
  52. package/dist/util/string.js +2 -6
  53. package/package.json +2 -2
package/README.en.md CHANGED
@@ -16,7 +16,7 @@ wikiparser-node is an offline [Wikitext](https://www.mediawiki.org/wiki/Wikitext
16
16
 
17
17
  This version provides a [CLI](https://en.wikipedia.org/wiki/Command-line_interface), but only retains the parsing functionality and linting functionality. The parsed AST cannot be modified. It is used in the [eslint-plugin-wikitext](https://www.npmjs.com/package/eslint-plugin-wikitext) plugin.
18
18
 
19
- ## Browser
19
+ ## Browser-compatible
20
20
 
21
21
  A browser-compatible version, which can be used for code highlighting or as a linting plugin in conjunction with the [CodeMirror5](https://codemirror.net/5/) editor. ([Usage example](https://bhsd-harry.github.io/wikiparser-node))
22
22
 
package/README.md CHANGED
@@ -16,7 +16,7 @@ wikiparser-node 是一款由 Bhsd 开发的基于 [Node.js](https://nodejs.org/)
16
16
 
17
17
  提供了 [CLI](https://en.wikipedia.org/wiki/Command-line_interface),但仅保留了解析功能和语法错误分析功能,解析生成的语法树不能修改。这个版本被应用于 [eslint-plugin-wikitext](https://www.npmjs.com/package/eslint-plugin-wikitext) 插件。
18
18
 
19
- ## Browser
19
+ ## Browser-compatible
20
20
 
21
21
  兼容浏览器的版本,可用于代码高亮或是搭配 [CodeMirror5](https://codemirror.net/5/) 编辑器作为语法分析插件。([使用实例展示](https://bhsd-harry.github.io/wikiparser-node))
22
22
 
package/dist/base.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ export interface Config {
2
+ ext: string[];
3
+ html: [string[], string[], string[]];
4
+ namespaces: Record<string, string>;
5
+ nsid: Record<string, number>;
6
+ parserFunction: [Record<string, string>, string[], string[], string[]];
7
+ doubleUnderscore: [string[], string[]];
8
+ protocol: string;
9
+ img: Record<string, string>;
10
+ variants: string[];
11
+ interwiki: string[];
12
+ excludes?: string[];
13
+ conversionTable?: [string, string][];
14
+ redirects?: [string, string][];
15
+ }
16
+ export interface LintError {
17
+ message: string;
18
+ severity: 'error' | 'warning';
19
+ startIndex: number;
20
+ endIndex: number;
21
+ startLine: number;
22
+ startCol: number;
23
+ endLine: number;
24
+ endCol: number;
25
+ excerpt: string;
26
+ }
27
+ /** 类似Node */
28
+ export interface AstNode {
29
+ type: string;
30
+ childNodes: AstNode[];
31
+ /** Linter */
32
+ lint(): LintError[];
33
+ /** 以HTML格式打印 */
34
+ print(): string;
35
+ }
36
+ export interface Parser {
37
+ config: string | Config;
38
+ i18n: string | Record<string, string> | undefined;
39
+ /**
40
+ * 解析wikitext
41
+ * @param include 是否嵌入
42
+ * @param maxStage 最大解析层级
43
+ */
44
+ parse(wikitext: string, include?: boolean, maxStage?: number, config?: Config): AstNode;
45
+ }
package/dist/bin/toc.js CHANGED
@@ -6,7 +6,7 @@ const { argv: [, , filename] } = process;
6
6
  if (!filename) {
7
7
  throw new RangeError('请指定文档文件!');
8
8
  }
9
- const fullpath = path.join(__dirname, '..', '..', 'wiki', `${filename}.md`), isEnglish = filename.endsWith('.en');
9
+ const fullpath = path.join(__dirname, '..', '..', 'wiki', `${filename}.md`), isEnglish = filename.endsWith('-(EN)');
10
10
  if (!fs.existsSync(fullpath)) {
11
11
  throw new RangeError(`文档 ${filename}.md 不存在!`);
12
12
  }
@@ -15,4 +15,4 @@ if (/^- \[[^\]]+\]\(#[^)]+\)$/mu.test(content)) {
15
15
  throw new Error(`文档 ${filename}.md 中已包含目录!`);
16
16
  }
17
17
  const toc = content.split('\n').filter(line => line.startsWith('#')).map(line => line.replace(/^(#+)\s+(\S.*)$/u, (_, { length }, title) => `${'\t'.repeat(length - 1)}- [${title}](#${title.toLowerCase().replaceAll(' ', '-').replaceAll('.', '')})`)).join('\n');
18
- fs.writeFileSync(fullpath, `<details>\n\t<summary>${isEnglish ? 'Table of Contents' : '目录'}</summary>\n\n${toc}\n</details>\n\n# Other Languages\n\n- [${isEnglish ? '简体中文' : 'English'}](./${isEnglish ? filename.slice(0, -3) : `${filename}.en`})\n\n${content}`);
18
+ fs.writeFileSync(fullpath, `<details>\n\t<summary>${isEnglish ? 'Table of Contents' : '目录'}</summary>\n\n${toc}\n\n</details>\n\n# Other Languages\n\n- [${isEnglish ? '简体中文' : 'English'}](./${isEnglish ? filename.slice(0, -5) : `${filename}-%28EN%29`})\n\n${content}`);
package/dist/index.d.ts CHANGED
@@ -1,34 +1,9 @@
1
+ import { Shadow } from './util/debug';
1
2
  import type { Title } from './lib/title';
2
3
  import type { Token } from './internal';
3
- export interface Config {
4
- ext: string[];
5
- html: [string[], string[], string[]];
6
- namespaces: Record<string, string>;
7
- nsid: Record<string, number>;
8
- parserFunction: [Record<string, string>, string[], string[], string[]];
9
- doubleUnderscore: [string[], string[]];
10
- protocol: string;
11
- img: Record<string, string>;
12
- variants: string[];
13
- interwiki: string[];
14
- excludes?: string[];
15
- conversionTable?: [string, string][];
16
- redirects?: [string, string][];
17
- }
18
- export interface LintError {
19
- message: string;
20
- severity: 'error' | 'warning';
21
- startIndex: number;
22
- endIndex: number;
23
- startLine: number;
24
- startCol: number;
25
- endLine: number;
26
- endCol: number;
27
- excerpt: string;
28
- }
29
- declare interface Parser {
30
- config: string | Config;
31
- i18n: string | Record<string, string> | undefined;
4
+ import type { Config, LintError, Parser as ParserBase } from './base';
5
+ declare interface Parser extends ParserBase {
6
+ Shadow: typeof Shadow;
32
7
  conversionTable: Map<string, string>;
33
8
  redirects: Map<string, string>;
34
9
  warning: boolean;
@@ -44,7 +19,7 @@ declare interface Parser {
44
19
  */
45
20
  normalizeTitle(title: string, defaultNs?: number, include?: boolean, config?: Config, halfParsed?: boolean, decode?: boolean, selfLink?: boolean): Title;
46
21
  /**
47
- * 解析wikitext
22
+ * @override
48
23
  * @param include 是否嵌入
49
24
  * @param maxStage 最大解析层级
50
25
  */
@@ -57,4 +32,5 @@ declare interface Parser {
57
32
  }
58
33
  declare const Parser: Parser;
59
34
  export = Parser;
35
+ export type { Config, LintError };
60
36
  export type * from './internal';
package/dist/index.js CHANGED
@@ -21,6 +21,7 @@ const Parser = {
21
21
  config: 'default',
22
22
  i18n: undefined,
23
23
  /* NOT FOR BROWSER */
24
+ Shadow: debug_1.Shadow,
24
25
  conversionTable: new Map(),
25
26
  redirects: new Map(),
26
27
  warning: true,
@@ -143,7 +144,6 @@ const Parser = {
143
144
  ...Object.entries(constants_1.classes),
144
145
  ...Object.entries(constants_1.mixins),
145
146
  ...Object.entries(constants_1.parsers),
146
- ...Object.entries(constants_1.utils),
147
147
  ];
148
148
  for (const [, filePath] of entries) {
149
149
  try {
@@ -1,5 +1,5 @@
1
1
  import { AstNode } from './node';
2
- import type { LintError } from '../index';
2
+ import type { LintError } from '../base';
3
3
  import type { AstNodes, AstText, Token } from '../internal';
4
4
  /** 类似HTMLElement */
5
5
  export declare abstract class AstElement extends AstNode {
@@ -73,12 +73,12 @@ export declare abstract class AstElement extends AstNode {
73
73
  */
74
74
  setText(str: string, i?: number): string;
75
75
  /**
76
- * Linter
76
+ * @override
77
77
  * @param start
78
78
  */
79
79
  lint(start?: number): LintError[];
80
80
  /**
81
- * 以HTML格式打印
81
+ * @override
82
82
  * @param opt 选项
83
83
  */
84
84
  print(opt?: PrintOpt): string;
@@ -244,7 +244,7 @@ class AstElement extends node_1.AstNode {
244
244
  : this.childNodes.map(child => child.toString(omit)).join(separator);
245
245
  }
246
246
  /**
247
- * Linter
247
+ * @override
248
248
  * @param start
249
249
  */
250
250
  lint(start = this.getAbsoluteIndex()) {
@@ -262,7 +262,7 @@ class AstElement extends node_1.AstNode {
262
262
  return errors;
263
263
  }
264
264
  /**
265
- * 以HTML格式打印
265
+ * @override
266
266
  * @param opt 选项
267
267
  */
268
268
  print(opt = {}) {
@@ -1,6 +1,7 @@
1
+ import type { LintError, AstNode as AstNodeBase } from '../base';
1
2
  import type { AstText, Token } from '../internal';
2
3
  export type AstNodes = AstText | Token;
3
- export type TokenTypes = 'root' | 'plain' | 'onlyinclude' | 'noinclude' | 'include' | 'comment' | 'ext' | 'ext-attrs' | 'ext-attr-dirty' | 'ext-attr' | 'attr-key' | 'attr-value' | 'ext-inner' | 'arg' | 'arg-name' | 'arg-default' | 'hidden' | 'magic-word' | 'magic-word-name' | 'invoke-function' | 'invoke-module' | 'template' | 'template-name' | 'parameter' | 'parameter-key' | 'parameter-value' | 'heading' | 'heading-title' | 'heading-trail' | 'html' | 'html-attrs' | 'html-attr-dirty' | 'html-attr' | 'table' | 'tr' | 'td' | 'table-syntax' | 'table-attrs' | 'table-attr-dirty' | 'table-attr' | 'table-inter' | 'td-inner' | 'hr' | 'double-underscore' | 'link' | 'link-target' | 'link-text' | 'category' | 'file' | 'gallery-image' | 'imagemap-image' | 'image-parameter' | 'quote' | 'ext-link' | 'ext-link-text' | 'ext-link-url' | 'free-ext-link' | 'list' | 'dd' | 'converter' | 'converter-flags' | 'converter-flag' | 'converter-rule' | 'converter-rule-noconvert' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'param-line' | 'imagemap-link';
4
+ export type TokenTypes = 'root' | 'plain' | 'onlyinclude' | 'noinclude' | 'include' | 'comment' | 'ext' | 'ext-attrs' | 'ext-attr-dirty' | 'ext-attr' | 'attr-key' | 'attr-value' | 'ext-inner' | 'arg' | 'arg-name' | 'arg-default' | 'hidden' | 'magic-word' | 'magic-word-name' | 'invoke-function' | 'invoke-module' | 'template' | 'template-name' | 'parameter' | 'parameter-key' | 'parameter-value' | 'heading' | 'heading-title' | 'heading-trail' | 'html' | 'html-attrs' | 'html-attr-dirty' | 'html-attr' | 'table' | 'tr' | 'td' | 'table-syntax' | 'table-attrs' | 'table-attr-dirty' | 'table-attr' | 'table-inter' | 'td-inner' | 'hr' | 'double-underscore' | 'link' | 'link-target' | 'link-text' | 'category' | 'file' | 'gallery-image' | 'imagemap-image' | 'image-parameter' | 'quote' | 'ext-link' | 'ext-link-text' | 'ext-link-url' | 'free-ext-link' | 'list' | 'dd' | 'converter' | 'converter-flags' | 'converter-flag' | 'converter-rule' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'param-line' | 'imagemap-link';
4
5
  export interface Dimension {
5
6
  height: number;
6
7
  width: number;
@@ -14,11 +15,13 @@ export interface CaretPosition {
14
15
  offset: number;
15
16
  }
16
17
  /** 类似Node */
17
- export declare abstract class AstNode {
18
+ export declare abstract class AstNode implements AstNodeBase {
18
19
  #private;
19
20
  type: TokenTypes | 'text';
20
21
  data?: string | undefined;
21
22
  readonly childNodes: AstNodes[];
23
+ abstract lint(): LintError[];
24
+ abstract print(): string;
22
25
  /** 首位子节点 */
23
26
  get firstChild(): AstNodes | undefined;
24
27
  /** 末位子节点 */
package/dist/lib/node.js CHANGED
@@ -23,7 +23,6 @@ class AstNode {
23
23
  /* NOT FOR BROWSER */
24
24
  #optional = new Set();
25
25
  #events = new EventEmitter();
26
- /* NOT FOR BROWSER END */
27
26
  /** 首位子节点 */
28
27
  get firstChild() {
29
28
  return this.childNodes[0];
@@ -1,5 +1,5 @@
1
1
  import { AstNode } from './node';
2
- import type { LintError } from '../index';
2
+ import type { LintError } from '../base';
3
3
  /** 文本节点 */
4
4
  export declare class AstText extends AstNode {
5
5
  #private;
@@ -13,7 +13,7 @@ export declare class AstText extends AstNode {
13
13
  /** 可见部分 */
14
14
  text(): string;
15
15
  /**
16
- * Linter
16
+ * @override
17
17
  * @param start
18
18
  */
19
19
  lint(start?: number): LintError[];
@@ -22,6 +22,8 @@ export declare class AstText extends AstNode {
22
22
  * @param text 替换的字符串
23
23
  */
24
24
  replaceData(text: string): void;
25
+ /** @override */
26
+ print(): string;
25
27
  /** 复制 */
26
28
  cloneNode(): AstText;
27
29
  /**
package/dist/lib/text.js CHANGED
@@ -56,6 +56,7 @@ const errorSyntax = /https?:\/\/|\{+|\}+|\[{2,}|\[(?![^[]*\])|(?<=^|\])([^[]*?)\
56
56
  'param',
57
57
  'xmp',
58
58
  ];
59
+ const entities = { '&': 'amp', '<': 'lt', '>': 'gt' };
59
60
  /** 文本节点 */
60
61
  class AstText extends node_1.AstNode {
61
62
  type = 'text';
@@ -84,7 +85,7 @@ class AstText extends node_1.AstNode {
84
85
  return this.data;
85
86
  }
86
87
  /**
87
- * Linter
88
+ * @override
88
89
  * @param start
89
90
  */
90
91
  lint(start = this.getAbsoluteIndex()) {
@@ -142,6 +143,10 @@ class AstText extends node_1.AstNode {
142
143
  replaceData(text) {
143
144
  this.#setData(text);
144
145
  }
146
+ /** @override */
147
+ print() {
148
+ return this.data.replace(/[&<>]/gu, p => `&${entities[p]};`);
149
+ }
145
150
  /* NOT FOR BROWSER */
146
151
  /** 复制 */
147
152
  cloneNode() {
package/dist/src/arg.d.ts CHANGED
@@ -2,7 +2,7 @@ import * as Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { AtomToken } from './atom';
4
4
  import { HiddenToken } from './hidden';
5
- import type { LintError } from '../index';
5
+ import type { LintError } from '../base';
6
6
  /**
7
7
  * `{{{}}}`包裹的参数
8
8
  * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
@@ -1,6 +1,6 @@
1
1
  import * as Parser from '../index';
2
2
  import { Token } from './index';
3
- declare type AtomTypes = 'arg-name' | 'attr-key' | 'attr-value' | 'ext-attr-dirty' | 'html-attr-dirty' | 'table-attr-dirty' | 'converter-flag' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'converter-rule-noconvert' | 'invoke-function' | 'invoke-module' | 'template-name' | 'link-target' | 'param-line';
3
+ declare type AtomTypes = 'arg-name' | 'attr-key' | 'attr-value' | 'ext-attr-dirty' | 'html-attr-dirty' | 'table-attr-dirty' | 'converter-flag' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'invoke-function' | 'invoke-module' | 'template-name' | 'link-target' | 'param-line';
4
4
  /** 不会被继续解析的plain Token */
5
5
  export declare class AtomToken extends Token {
6
6
  type: AtomTypes;
@@ -1,7 +1,7 @@
1
1
  import * as Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { AtomToken } from './atom';
4
- import type { LintError } from '../index';
4
+ import type { LintError } from '../base';
5
5
  import type { AttributesToken } from '../internal';
6
6
  export type AttributeTypes = 'ext-attr' | 'html-attr' | 'table-attr';
7
7
  declare const AttributeToken_base: ((abstract new (...args: any[]) => {
@@ -2,7 +2,7 @@ import * as Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { AtomToken } from './atom';
4
4
  import { AttributeToken } from './attribute';
5
- import type { LintError } from '../index';
5
+ import type { LintError } from '../base';
6
6
  import type { ExtToken, HtmlToken, TdToken, TrToken, TableToken } from '../internal';
7
7
  declare type AttributesTypes = 'ext-attrs' | 'html-attrs' | 'table-attrs';
8
8
  /**
@@ -258,7 +258,6 @@ class AttributesToken extends index_1.Token {
258
258
  return;
259
259
  }
260
260
  const token = debug_1.Shadow.run(() => new attribute_1.AttributeToken(this.type.slice(0, -1), this.name, key, value === true ? '' : '=', value === true ? '' : value, ['"', '"'], this.getAttribute('config')));
261
- token.setAttribute('name', key);
262
261
  this.insertAt(token);
263
262
  }
264
263
  /**
@@ -1,7 +1,7 @@
1
1
  import * as Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { AtomToken } from './atom';
4
- import type { LintError } from '../index';
4
+ import type { LintError } from '../base';
5
5
  import type { ConverterToken, ConverterRuleToken } from '../internal';
6
6
  /**
7
7
  * 转换flags
@@ -61,21 +61,16 @@ class ConverterRuleToken extends index_1.Token {
61
61
  */
62
62
  constructor(rule, hasColon = true, config = Parser.getConfig(), accum = []) {
63
63
  super(undefined, config, accum);
64
- if (hasColon) {
65
- const i = rule.indexOf(':'), j = rule.slice(0, i).indexOf('=>'), v = j === -1 ? rule.slice(0, i) : rule.slice(j + 2, i);
66
- if (config.variants.includes(v.trim())) {
67
- super.insertAt(new atom_1.AtomToken(v, 'converter-rule-variant', config, accum));
68
- super.insertAt(new atom_1.AtomToken(rule.slice(i + 1), 'converter-rule-to', config, accum));
69
- if (j !== -1) {
70
- super.insertAt(new atom_1.AtomToken(rule.slice(0, j), 'converter-rule-from', config, accum), 0);
71
- }
72
- }
73
- else {
74
- super.insertAt(new atom_1.AtomToken(rule, 'converter-rule-noconvert', config, accum));
64
+ const i = rule.indexOf(':'), j = rule.slice(0, i).indexOf('=>'), v = j === -1 ? rule.slice(0, i) : rule.slice(j + 2, i);
65
+ if (hasColon && config.variants.includes(v.trim())) {
66
+ super.insertAt(new atom_1.AtomToken(v, 'converter-rule-variant', config, accum));
67
+ super.insertAt(new atom_1.AtomToken(rule.slice(i + 1), 'converter-rule-to', config, accum));
68
+ if (j !== -1) {
69
+ super.insertAt(new atom_1.AtomToken(rule.slice(0, j), 'converter-rule-from', config, accum), 0);
75
70
  }
76
71
  }
77
72
  else {
78
- super.insertAt(new atom_1.AtomToken(rule, 'converter-rule-noconvert', config, accum));
73
+ super.insertAt(new atom_1.AtomToken(rule, 'converter-rule-to', config, accum));
79
74
  }
80
75
  this.protectChildren('1:');
81
76
  }
@@ -146,11 +141,7 @@ class ConverterRuleToken extends index_1.Token {
146
141
  if (this.length === 1) {
147
142
  throw new Error(`${this.constructor.name} 需至少保留 1 个子节点!`);
148
143
  }
149
- const removed = super.removeAt(i);
150
- if (this.length === 1) {
151
- this.firstChild.type = 'converter-rule-noconvert';
152
- }
153
- return removed;
144
+ return super.removeAt(i);
154
145
  }
155
146
  /**
156
147
  * @override
@@ -2,7 +2,7 @@ import * as Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { GalleryImageToken } from './link/galleryImage';
4
4
  import { HiddenToken } from './hidden';
5
- import type { LintError } from '../index';
5
+ import type { LintError } from '../base';
6
6
  import type { AstNodes, AstText, AttributesToken, ExtToken } from '../internal';
7
7
  /**
8
8
  * gallery标签
@@ -1,7 +1,7 @@
1
1
  import * as Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { SyntaxToken } from './syntax';
4
- import type { LintError } from '../index';
4
+ import type { LintError } from '../base';
5
5
  declare const HeadingToken_base: (abstract new (...args: any[]) => {
6
6
  prependNewLine(): string;
7
7
  toString(omit?: Set<string> | undefined): string;
@@ -26,10 +26,7 @@ declare const HeadingToken_base: (abstract new (...args: any[]) => {
26
26
  addEventListener(events: string | string[], listener: AstListener): void;
27
27
  replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
28
28
  }) & {
29
- readonly fixed: true; /**
30
- * 章节标题
31
- * @classdesc `{childNodes: [Token, SyntaxToken]}`
32
- */
29
+ readonly fixed: true;
33
30
  }) & typeof Parser.Token;
34
31
  /**
35
32
  * 章节标题
@@ -38,7 +35,6 @@ declare const HeadingToken_base: (abstract new (...args: any[]) => {
38
35
  export declare class HeadingToken extends HeadingToken_base {
39
36
  #private;
40
37
  readonly type = "heading";
41
- name: string;
42
38
  childNodes: [Token, SyntaxToken];
43
39
  abstract get children(): [Token, SyntaxToken];
44
40
  abstract get firstChild(): Token;
@@ -15,13 +15,14 @@ const syntax_1 = require("./syntax");
15
15
  */
16
16
  class HeadingToken extends (0, sol_1.sol)((0, fixed_1.fixed)(index_1.Token)) {
17
17
  type = 'heading';
18
+ #level;
18
19
  /** 标题格式的等号 */
19
20
  get #equals() {
20
21
  return '='.repeat(this.level);
21
22
  }
22
23
  /** 标题层级 */
23
24
  get level() {
24
- return Number(this.name);
25
+ return this.#level;
25
26
  }
26
27
  /* NOT FOR BROWSER */
27
28
  set level(n) {
@@ -46,7 +47,7 @@ class HeadingToken extends (0, sol_1.sol)((0, fixed_1.fixed)(index_1.Token)) {
46
47
  */
47
48
  constructor(level, input, config = Parser.getConfig(), accum = []) {
48
49
  super(undefined, config, accum);
49
- this.setAttribute('name', String(level));
50
+ this.#level = level;
50
51
  const token = new index_1.Token(input[0], config, accum);
51
52
  token.type = 'heading-title';
52
53
  token.setAttribute('stage', 2);
@@ -81,7 +82,7 @@ class HeadingToken extends (0, sol_1.sol)((0, fixed_1.fixed)(index_1.Token)) {
81
82
  lint(start = this.getAbsoluteIndex()) {
82
83
  const errors = super.lint(start), innerStr = String(this.firstChild);
83
84
  let refError;
84
- if (this.name === '1') {
85
+ if (this.level === 1) {
85
86
  refError = (0, lint_1.generateForSelf)(this, { start }, '<h1>');
86
87
  errors.push(refError);
87
88
  }
@@ -116,7 +117,7 @@ class HeadingToken extends (0, sol_1.sol)((0, fixed_1.fixed)(index_1.Token)) {
116
117
  * @param n 标题层级
117
118
  */
118
119
  setLevel(n) {
119
- this.setAttribute('name', String(Math.min(Math.max(n, 1), 6)));
120
+ this.#level = Math.min(Math.max(n, 1), 6);
120
121
  }
121
122
  /** 移除标题后的不可见内容 */
122
123
  removeTrail() {
@@ -1,6 +1,6 @@
1
1
  import * as Parser from '../index';
2
2
  import { Token } from './index';
3
- import type { LintError } from '../index';
3
+ import type { LintError } from '../base';
4
4
  import type { AttributesToken } from '../internal';
5
5
  declare const HtmlToken_base: (abstract new (...args: any[]) => {
6
6
  childNodes: Parser.AstNodes[];
@@ -14,8 +14,7 @@ declare const HtmlToken_base: (abstract new (...args: any[]) => {
14
14
  getAttrNames(): Set<string>;
15
15
  getAttrs(): Record<string, string | true>;
16
16
  setAttr(key: string, value: string | boolean): void;
17
- removeAttr(key: string): void;
18
- /**
17
+ removeAttr(key: string): void; /**
19
18
  * @param name 标签名
20
19
  * @param attr 标签属性
21
20
  * @param closing 是否闭合
@@ -1,6 +1,6 @@
1
1
  import * as Parser from '../index';
2
2
  import { Token } from './index';
3
- import type { LintError } from '../index';
3
+ import type { LintError } from '../base';
4
4
  import type { Title } from '../lib/title';
5
5
  import type { AstNodes, AstText, AtomToken, FileToken } from '../internal';
6
6
  export declare const galleryParams: Set<string>;
@@ -3,7 +3,7 @@ import { Token } from './index';
3
3
  import { NoincludeToken } from './nowiki/noinclude';
4
4
  import { GalleryImageToken } from './link/galleryImage';
5
5
  import { ImagemapLinkToken } from './imagemapLink';
6
- import type { LintError } from '../index';
6
+ import type { LintError } from '../base';
7
7
  import type { AstNodes, AstText, AttributesToken, ExtToken } from '../internal';
8
8
  /**
9
9
  * `<imagemap>`
@@ -1,7 +1,7 @@
1
1
  import * as Parser from '../../index';
2
2
  import { Token } from '../index';
3
3
  import { AtomToken } from '../atom';
4
- import type { LintError } from '../../index';
4
+ import type { LintError } from '../../base';
5
5
  import type { Title } from '../../lib/title';
6
6
  /**
7
7
  * 内链
@@ -14,17 +14,18 @@ const atom_1 = require("../atom");
14
14
  class LinkBaseToken extends index_1.Token {
15
15
  #bracket = true;
16
16
  #delimiter;
17
+ #title;
17
18
  /* NOT FOR BROWSER */
18
19
  /** 完整链接 */
19
20
  get link() {
20
- return this.#getTitle();
21
+ return this.#title;
21
22
  }
22
23
  set link(link) {
23
24
  this.setTarget(link);
24
25
  }
25
26
  /** fragment */
26
27
  get fragment() {
27
- return this.#getTitle().fragment;
28
+ return this.#title.fragment;
28
29
  }
29
30
  set fragment(fragment) {
30
31
  if (fragment === undefined) {
@@ -57,14 +58,15 @@ class LinkBaseToken extends index_1.Token {
57
58
  }
58
59
  /** @private */
59
60
  afterBuild() {
60
- this.setAttribute('name', this.#getTitle().title);
61
+ this.#title = this.getTitle();
62
+ this.setAttribute('name', this.#title.title);
61
63
  if (this.#delimiter.includes('\0')) {
62
64
  this.#delimiter = this.buildFromStr(this.#delimiter, 'string');
63
65
  }
64
66
  const /** @implements */ linkListener = (e, data) => {
65
67
  const { prevTarget } = e;
66
68
  if (prevTarget?.type === 'link-target') {
67
- const name = prevTarget.text(), { title, interwiki, ns, valid } = this.#getTitle();
69
+ const name = prevTarget.text(), titleObj = this.getTitle(), { title, interwiki, ns, valid } = titleObj;
68
70
  if (!valid) {
69
71
  (0, debug_1.undo)(e, data);
70
72
  throw new Error(`非法的内链目标:${name}`);
@@ -84,6 +86,7 @@ class LinkBaseToken extends index_1.Token {
84
86
  prevTarget.prepend(':');
85
87
  }
86
88
  }
89
+ this.#title = titleObj;
87
90
  this.setAttribute('name', title);
88
91
  }
89
92
  };
@@ -94,6 +97,9 @@ class LinkBaseToken extends index_1.Token {
94
97
  if (key === 'bracket') {
95
98
  this.#bracket = Boolean(value);
96
99
  }
100
+ else if (key === 'title') {
101
+ this.#title = value;
102
+ }
97
103
  else {
98
104
  super.setAttribute(key, value);
99
105
  }
@@ -113,6 +119,9 @@ class LinkBaseToken extends index_1.Token {
113
119
  }
114
120
  /** @private */
115
121
  getAttribute(key) {
122
+ if (key === 'title') {
123
+ return this.#title;
124
+ }
116
125
  return key === 'padding' ? 2 : super.getAttribute(key);
117
126
  }
118
127
  /** @private */
@@ -121,7 +130,7 @@ class LinkBaseToken extends index_1.Token {
121
130
  }
122
131
  /** @override */
123
132
  lint(start = this.getAbsoluteIndex()) {
124
- const errors = super.lint(start), { childNodes: [target, linkText], type: linkType } = this, { encoded, fragment } = this.#getTitle();
133
+ const errors = super.lint(start), { childNodes: [target, linkText], type: linkType } = this, { encoded, fragment } = this.#title;
125
134
  let rect;
126
135
  if (linkType === 'link' && target.childNodes.some(({ type }) => type === 'template')) {
127
136
  rect = { start, ...this.getRootNode().posFromIndex(start) };
@@ -141,8 +150,8 @@ class LinkBaseToken extends index_1.Token {
141
150
  }
142
151
  return errors;
143
152
  }
144
- /** 生成Title对象 */
145
- #getTitle() {
153
+ /** @private */
154
+ getTitle() {
146
155
  return this.normalizeTitle(this.firstChild.text(), 0, false, true, true);
147
156
  }
148
157
  /** @override */
@@ -2,7 +2,7 @@ import * as Parser from '../../index';
2
2
  import { LinkBaseToken } from './base';
3
3
  import { ImageParameterToken } from '../imageParameter';
4
4
  import type { Title } from '../../lib/title';
5
- import type { LintError } from '../../index';
5
+ import type { LintError } from '../../base';
6
6
  import type { Token, AtomToken } from '../../internal';
7
7
  /**
8
8
  * 图片
@@ -1,7 +1,7 @@
1
1
  import * as Parser from '../../index';
2
2
  import { Token } from '../index';
3
3
  import type { Title } from '../../lib/title';
4
- import type { LintError } from '../../index';
4
+ import type { LintError } from '../../base';
5
5
  import type { AtomToken, ImageParameterToken } from '../../internal';
6
6
  declare const GalleryImageToken_base: (abstract new (...args: any[]) => {
7
7
  toString(omit?: Set<string> | undefined): string;
@@ -27,6 +27,8 @@ export declare class GalleryImageToken extends GalleryImageToken_base {
27
27
  * @param text 图片参数
28
28
  */
29
29
  constructor(type: 'gallery' | 'imagemap', link: string, text?: string, config?: Parser.Config, accum?: Token[]);
30
+ /** private */
31
+ getTitle(): Title;
30
32
  /** @override */
31
33
  lint(start?: number): LintError[];
32
34
  /**
@@ -42,8 +42,8 @@ class GalleryImageToken extends (0, singleLine_1.singleLine)(file_1.FileToken) {
42
42
  this.setAttribute('bracket', false);
43
43
  this.type = `${type}-image`;
44
44
  }
45
- /** 生成Title对象 */
46
- #getTitle() {
45
+ /** private */
46
+ getTitle() {
47
47
  const imagemap = this.type === 'imagemap-image';
48
48
  return this.normalizeTitle(String(this.firstChild), imagemap ? 0 : 6, true, !imagemap);
49
49
  }
@@ -53,20 +53,27 @@ class GalleryImageToken extends (0, singleLine_1.singleLine)(file_1.FileToken) {
53
53
  }
54
54
  /** @override */
55
55
  lint(start = this.getAbsoluteIndex()) {
56
- const errors = super.lint(start), { interwiki, ns, } = this.#getTitle();
56
+ const errors = super.lint(start), { interwiki, ns, } = this.getAttribute('title');
57
57
  if (interwiki || ns !== 6) {
58
58
  errors.push((0, lint_1.generateForSelf)(this, { start }, 'invalid gallery image'));
59
59
  }
60
60
  return errors;
61
61
  }
62
- /* NOT FOR BROWSER */
62
+ /**
63
+ * 设置`#title`
64
+ * @param title Title对象
65
+ */
66
+ #setName(title) {
67
+ this.setAttribute('title', title);
68
+ this.setAttribute('name', title.title);
69
+ }
63
70
  /** @private */
64
71
  afterBuild() {
65
- this.setAttribute('name', this.#getTitle().title);
72
+ this.#setName(this.getTitle());
66
73
  const /** @implements */ linkListener = (e, data) => {
67
74
  const { prevTarget } = e;
68
75
  if (prevTarget?.type === 'link-target') {
69
- const name = String(prevTarget), { title, interwiki, ns, valid } = this.#getTitle();
76
+ const name = String(prevTarget), title = this.getTitle(), { interwiki, ns, valid } = title;
70
77
  if (!valid) {
71
78
  (0, debug_1.undo)(e, data);
72
79
  throw new Error(`非法的图片文件名:${name}`);
@@ -75,11 +82,12 @@ class GalleryImageToken extends (0, singleLine_1.singleLine)(file_1.FileToken) {
75
82
  (0, debug_1.undo)(e, data);
76
83
  throw new Error(`图片链接不可更改命名空间:${name}`);
77
84
  }
78
- this.setAttribute('name', title);
85
+ this.#setName(title);
79
86
  }
80
87
  };
81
88
  this.addEventListener(['remove', 'insert', 'replace', 'text'], linkListener);
82
89
  }
90
+ /* NOT FOR BROWSER */
83
91
  /**
84
92
  * @override
85
93
  * @param token 待插入的子节点
@@ -1,6 +1,6 @@
1
1
  import * as Parser from '../index';
2
2
  import { Token } from './index';
3
- import type { LintError } from '../index';
3
+ import type { LintError } from '../base';
4
4
  import type { AstText, CommentToken, IncludeToken, NoincludeToken } from '../internal';
5
5
  declare const MagicLinkToken_base: (abstract new (...args: any[]) => {
6
6
  "__#5@#pattern": RegExp;
@@ -3,7 +3,7 @@ import { Token } from './index';
3
3
  import { ExtToken } from './tagPair/ext';
4
4
  import { NoincludeToken } from './nowiki/noinclude';
5
5
  import { CommentToken } from './nowiki/comment';
6
- import type { LintError } from '../index';
6
+ import type { LintError } from '../base';
7
7
  import type { AttributesToken } from './attributes';
8
8
  /**
9
9
  * 嵌套式的扩展标签
@@ -1,6 +1,6 @@
1
1
  import * as Parser from '../../index';
2
2
  import { NowikiBaseToken } from './base';
3
- import type { LintError } from '../../index';
3
+ import type { LintError } from '../../base';
4
4
  import type { Token } from '../index';
5
5
  declare const CommentToken_base: ((abstract new (...args: any[]) => {
6
6
  text(): string;
@@ -19,7 +19,7 @@ declare const CommentToken_base: ((abstract new (...args: any[]) => {
19
19
  export declare class CommentToken extends CommentToken_base {
20
20
  readonly type = "comment";
21
21
  closed: boolean;
22
- /** 内部wikitext */
22
+ /** 内部文本 */
23
23
  get innerText(): string;
24
24
  set innerText(text: string);
25
25
  /** @param closed 是否闭合 */
@@ -13,7 +13,7 @@ class CommentToken extends (0, hidden_1.hidden)(base_1.NowikiBaseToken) {
13
13
  type = 'comment';
14
14
  closed;
15
15
  /* NOT FOR BROWSER */
16
- /** 内部wikitext */
16
+ /** 内部文本 */
17
17
  get innerText() {
18
18
  return super.innerText;
19
19
  }
@@ -1,5 +1,5 @@
1
1
  import { NowikiBaseToken } from './base';
2
- import type { LintError } from '../../index';
2
+ import type { LintError } from '../../base';
3
3
  import type { AttributesToken, ExtToken } from '../../internal';
4
4
  /** 扩展标签内的纯文字Token */
5
5
  export declare class NowikiToken extends NowikiBaseToken {
@@ -1,6 +1,6 @@
1
1
  import * as Parser from '../../index';
2
2
  import { NowikiBaseToken } from './base';
3
- import type { LintError } from '../../index';
3
+ import type { LintError } from '../../base';
4
4
  declare const QuoteToken_base: (abstract new (...args: any[]) => {
5
5
  "__#5@#pattern": RegExp;
6
6
  afterBuild(): void;
@@ -18,7 +18,7 @@ class QuoteToken extends (0, syntax_1.syntax)(base_1.NowikiBaseToken, /^(?:'{5}|
18
18
  if (previousSibling?.type === 'text' && previousSibling.data.endsWith(`'`)) {
19
19
  refError = (0, lint_1.generateForSelf)(this, { start }, message);
20
20
  wikitext = String(this.getRootNode());
21
- const { startIndex: endIndex, startLine: endLine, startCol: endCol } = refError, [{ length }] = previousSibling.data.match(/(?<!')'+$/u), startIndex = start - length;
21
+ const { startIndex: endIndex, startLine: endLine, startCol: endCol } = refError, [{ length }] = /(?<!')'+$/u.exec(previousSibling.data), startIndex = start - length;
22
22
  errors.push({
23
23
  ...refError,
24
24
  startIndex,
@@ -32,7 +32,7 @@ class QuoteToken extends (0, syntax_1.syntax)(base_1.NowikiBaseToken, /^(?:'{5}|
32
32
  if (nextSibling?.type === 'text' && nextSibling.data.startsWith(`'`)) {
33
33
  refError ??= (0, lint_1.generateForSelf)(this, { start }, message);
34
34
  wikitext ??= String(this.getRootNode());
35
- const { endIndex: startIndex, endLine: startLine, endCol: startCol } = refError, [{ length }] = nextSibling.data.match(/^'+/u), endIndex = startIndex + length;
35
+ const { endIndex: startIndex, endLine: startLine, endCol: startCol } = refError, [{ length }] = /^'+/u.exec(nextSibling.data), endIndex = startIndex + length;
36
36
  errors.push({
37
37
  ...refError,
38
38
  startIndex,
@@ -1,7 +1,7 @@
1
1
  import * as Parser from '../../index';
2
2
  import { Token } from '../index';
3
3
  import { AtomToken } from '../atom';
4
- import type { LintError } from '../../index';
4
+ import type { LintError } from '../../base';
5
5
  import type { AttributesToken, ExtToken } from '../../internal';
6
6
  /**
7
7
  * `<dynamicpagelist>`
@@ -1,6 +1,6 @@
1
1
  import * as Parser from '../index';
2
2
  import { Token } from './index';
3
- import type { LintError } from '../index';
3
+ import type { LintError } from '../base';
4
4
  import type { AtomToken, SyntaxToken, TranscludeToken } from '../internal';
5
5
  declare const ParameterToken_base: ((abstract new (...args: any[]) => {
6
6
  removeAt(): never;
@@ -160,10 +160,6 @@ class ParameterToken extends (0, fixed_1.fixed)(index_1.Token) {
160
160
  * @param value 参数值
161
161
  */
162
162
  setValue(value) {
163
- const { anon, parentNode } = this;
164
- if (anon && parentNode?.isTemplate()) {
165
- parentNode.anonToNamed();
166
- }
167
163
  const { childNodes } = Parser.parse(value, this.getAttribute('include'), undefined, this.getAttribute('config'));
168
164
  this.lastChild.replaceChildren(...childNodes);
169
165
  }
@@ -1,7 +1,7 @@
1
1
  import * as Parser from '../../index';
2
2
  import { TrBaseToken } from './trBase';
3
3
  import { SyntaxToken } from '../syntax';
4
- import type { LintError } from '../../index';
4
+ import type { LintError } from '../../base';
5
5
  import type { AttributesToken, TdToken, TrToken, Token } from '../../internal';
6
6
  import type { TableCoords } from './trBase';
7
7
  import type { TdAttrs, TdSubtypes } from './td';
@@ -1,7 +1,7 @@
1
1
  import * as Parser from '../../index';
2
2
  import { Token } from '../index';
3
3
  import { TableBaseToken } from './base';
4
- import type { LintError } from '../../index';
4
+ import type { LintError } from '../../base';
5
5
  import type { SyntaxToken, AttributesToken, TrToken, TableToken } from '../../internal';
6
6
  export type TdSubtypes = 'td' | 'th' | 'caption';
7
7
  declare type TdAttrGetter<T extends string> = T extends 'rowspan' | 'colspan' ? number : string | true | undefined;
@@ -51,9 +51,9 @@ class TdToken extends (0, fixed_1.fixed)(base_1.TableBaseToken) {
51
51
  * @param inner 内部wikitext
52
52
  */
53
53
  constructor(syntax, inner, config = Parser.getConfig(), accum = []) {
54
- let innerSyntax = inner?.match(/\||\0\d+!\x7F/u), attr = innerSyntax ? inner.slice(0, innerSyntax.index) : '';
54
+ let innerSyntax = /\||\0\d+!\x7F/u.exec(inner ?? ''), attr = innerSyntax ? inner.slice(0, innerSyntax.index) : '';
55
55
  if (/\[\[|-\{/u.test(attr)) {
56
- innerSyntax = undefined;
56
+ innerSyntax = null;
57
57
  attr = '';
58
58
  }
59
59
  super(/^(?:\n[^\S\n]*(?:[|!]|\|\+|\{\{\s*!\s*\}\}\+?)|(?:\||\{\{\s*!\s*\}\}){2}|!!|\{\{\s*!!\s*\}\})$/u, syntax, attr, config, accum, { SyntaxToken: 0, AttributesToken: 1, Token: 2 });
@@ -1,7 +1,7 @@
1
1
  import { Token } from '..';
2
2
  import { TableBaseToken } from './base';
3
3
  import { TdToken } from './td';
4
- import type { LintError } from '../../index';
4
+ import type { LintError } from '../../base';
5
5
  import type { AstNodes, SyntaxToken, TrToken } from '../../internal';
6
6
  import type { TdAttrs, TdSubtypes } from './td';
7
7
  export interface TableCoords {
@@ -2,7 +2,7 @@ import * as Parser from '../../index';
2
2
  import { Token } from '../index';
3
3
  import { TagPairToken } from './index';
4
4
  import { AttributesToken } from '../attributes';
5
- import type { LintError } from '../../index';
5
+ import type { LintError } from '../../base';
6
6
  declare const ExtToken_base: (abstract new (...args: any[]) => {
7
7
  childNodes: Parser.AstNodes[];
8
8
  readonly "__#8@#attributesChild": Parser.AttributesToken;
@@ -3,7 +3,7 @@ import { Token } from './index';
3
3
  import { ParameterToken } from './parameter';
4
4
  import { AtomToken } from './atom';
5
5
  import { SyntaxToken } from './syntax';
6
- import type { LintError } from '../index';
6
+ import type { LintError } from '../base';
7
7
  /**
8
8
  * 模板或魔术字
9
9
  * @classdesc `{childNodes: [AtomToken|SyntaxToken, ...AtomToken, ...ParameterToken]}`
@@ -668,8 +668,7 @@ class TranscludeToken extends index_1.Token {
668
668
  * @throws `Error` 转义失败
669
669
  */
670
670
  escapeTables() {
671
- const count = this.hasDuplicatedArgs(), str = this.text(), i = str.search(/\n[^\S\n]*(?::+[^\S\n]*)?\{\|/u);
672
- if (i === -1 || str.slice(i).search(/\n[^\S\n]*\|\}/u) === -1) {
671
+ if (!/\n[^\S\n]*(?::+[^\S\n]*)?\{\|/u.test(this.text())) {
673
672
  return this;
674
673
  }
675
674
  const stripped = String(this).slice(2, -2), include = this.getAttribute('include'), config = this.getAttribute('config'), parsed = Parser.parse(stripped, include, 4, config);
@@ -682,10 +681,6 @@ class TranscludeToken extends index_1.Token {
682
681
  if (length !== 1 || !(firstChild instanceof TranscludeToken)) {
683
682
  throw new Error('转义表格失败!');
684
683
  }
685
- const fixed = count - firstChild.hasDuplicatedArgs();
686
- if (fixed) {
687
- Parser.info(`共修复了 ${fixed} 个重复参数。`);
688
- }
689
684
  this.safeReplaceWith(firstChild);
690
685
  return firstChild;
691
686
  }
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.promises = exports.typeAliases = exports.aliases = exports.utils = exports.parsers = exports.mixins = exports.classes = exports.MAX_STAGE = void 0;
3
+ exports.promises = exports.typeAliases = exports.aliases = exports.parsers = exports.mixins = exports.classes = exports.MAX_STAGE = void 0;
4
4
  exports.MAX_STAGE = 11;
5
5
  /* NOT FOR BROWSER */
6
6
  exports.classes = {};
7
7
  exports.mixins = {};
8
8
  exports.parsers = {};
9
- exports.utils = {};
10
9
  exports.aliases = [
11
10
  ['AstText'],
12
11
  ['CommentToken', 'ExtToken', 'IncludeToken', 'NoincludeToken'],
@@ -98,9 +97,8 @@ exports.typeAliases = {
98
97
  'converter-flags': ['convert-flags', 'conversion-flags'],
99
98
  'converter-flag': ['convert-flag', 'conversion-flag'],
100
99
  'converter-rule': ['convert-rule', 'conversion-rule'],
101
- 'converter-rule-noconvert': ['convert-rule-noconvert', 'conversion-rule-noconvert'],
102
100
  'converter-rule-variant': ['convert-rule-variant', 'conversion-rule-variant'],
103
- 'converter-rule-to': ['convert-rule-to', 'conversion-rule-to'],
101
+ 'converter-rule-to': ['convert-rule-to', 'conversion-rule-to', 'converter-rule-noconvert'],
104
102
  'converter-rule-from': ['convert-rule-from', 'conversion-rule-from'],
105
103
  // specific extensions
106
104
  'param-line': ['parameter-line'],
@@ -1,13 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.undo = exports.Shadow = void 0;
4
- const constants_1 = require("./constants");
5
- // eslint-disable-next-line @typescript-eslint/no-redeclare
6
4
  exports.Shadow = {
7
5
  /* NOT FOR BROWSER */
8
6
  running: false,
9
7
  /* NOT FOR BROWSER END */
10
- /** @implements */
8
+ /** @private */
11
9
  run(callback) {
12
10
  const { running } = this;
13
11
  this.running = true;
@@ -62,4 +60,3 @@ const undo = (e, data) => {
62
60
  }
63
61
  };
64
62
  exports.undo = undo;
65
- constants_1.utils['debug'] = __filename;
package/dist/util/diff.js CHANGED
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.diff = exports.cmd = void 0;
4
4
  const fs = require("fs/promises");
5
5
  const child_process_1 = require("child_process");
6
- const constants_1 = require("./constants");
7
6
  process.on('unhandledRejection', e => {
8
7
  console.error(e);
9
8
  });
@@ -71,4 +70,3 @@ const diff = async (oldStr, newStr, uid = -1) => {
71
70
  console.log(stdout?.split('\n').slice(4).join('\n'));
72
71
  };
73
72
  exports.diff = diff;
74
- constants_1.utils['diff'] = __filename;
package/dist/util/lint.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateForSelf = exports.generateForChild = void 0;
4
- const constants_1 = require("./constants");
5
4
  const Parser = require("../index");
6
5
  /**
7
6
  * 生成对于子节点的LintError对象
@@ -47,4 +46,3 @@ const generateForSelf = (token, boundingRect, msg, severity = 'error') => {
47
46
  };
48
47
  };
49
48
  exports.generateForSelf = generateForSelf;
50
- constants_1.utils['lint'] = __filename;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeSpace = exports.print = exports.noWrap = exports.decodeHtml = exports.text = exports.escapeRegExp = exports.removeComment = exports.extUrlChar = exports.extUrlCharFirst = void 0;
4
- const constants_1 = require("./constants");
5
4
  exports.extUrlCharFirst = '(?:\\[[\\da-f:.]+\\]|[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD])';
6
5
  exports.extUrlChar = '(?:[^[\\]<>"\\0-\\x1F\\x7F\\p{Zs}\\uFFFD]|\\0\\d+c\\x7F)*';
7
6
  /**
@@ -41,10 +40,8 @@ exports.noWrap = noWrap;
41
40
  * @param opt 选项
42
41
  */
43
42
  const print = (childNodes, opt = {}) => {
44
- const { pre = '', post = '', sep = '' } = opt, entities = { '&': 'amp', '<': 'lt', '>': 'gt' };
45
- return `${pre}${childNodes.map(child => child.type === 'text'
46
- ? child.data.replace(/[&<>]/gu, p => `&${entities[p]};`)
47
- : child.print()).join(sep)}${post}`;
43
+ const { pre = '', post = '', sep = '' } = opt;
44
+ return `${pre}${childNodes.map(child => child.print()).join(sep)}${post}`;
48
45
  };
49
46
  exports.print = print;
50
47
  /* NOT FOR BROWSER */
@@ -62,4 +59,3 @@ const normalizeSpace = (token) => {
62
59
  }
63
60
  };
64
61
  exports.normalizeSpace = normalizeSpace;
65
- constants_1.utils['string'] = __filename;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikiparser-node",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "A Node.js parser for MediaWiki markup with AST",
5
5
  "keywords": [
6
6
  "mediawiki",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "scripts": {
29
29
  "toc": "node ./dist/bin/toc.js",
30
- "prepublishOnly": "npm run build; rm dist/internal.js; rm -r dist/test; rm dist/[bmpu]*/*.d.ts; grep -rl --include='*.d.ts' '@private' dist/ | xargs gsed -i '/@private/,+1d'",
30
+ "prepublishOnly": "npm run build; rm dist/internal.js dist/base.js dist/[bmpu]*/*.d.ts; rm -r dist/test; grep -rl --include='*.d.ts' '@private' dist/ | xargs gsed -i '/@private/,+1d'",
31
31
  "build": "rm -rf dist/; tsc; grep -rl --include='*.d.ts' '@private' dist/ | xargs gsed -i '/@private/,+1d'",
32
32
  "diff": "git diff --ignore-all-space --color-moved",
33
33
  "lint:ts": "tsc --noEmit && eslint --cache .",