wikiparser-node 1.4.1 → 1.4.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 (110) hide show
  1. package/dist/base.d.ts +1 -1
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +15 -12
  4. package/dist/lib/element.d.ts +5 -5
  5. package/dist/lib/element.js +45 -37
  6. package/dist/lib/node.js +6 -0
  7. package/dist/lib/text.js +81 -40
  8. package/dist/lib/title.d.ts +1 -1
  9. package/dist/lib/title.js +13 -4
  10. package/dist/mixin/flagsParent.d.ts +1 -1
  11. package/dist/mixin/flagsParent.js +2 -0
  12. package/dist/mixin/magicLinkParent.d.ts +1 -1
  13. package/dist/mixin/magicLinkParent.js +2 -0
  14. package/dist/mixin/singleLine.js +2 -2
  15. package/dist/mixin/sol.js +2 -4
  16. package/dist/parser/braces.js +2 -2
  17. package/dist/parser/commentAndExt.js +2 -2
  18. package/dist/parser/converter.js +2 -2
  19. package/dist/parser/externalLinks.js +2 -2
  20. package/dist/parser/hrAndDoubleUnderscore.js +2 -2
  21. package/dist/parser/html.js +2 -2
  22. package/dist/parser/links.js +7 -5
  23. package/dist/parser/list.js +2 -2
  24. package/dist/parser/magicLinks.js +2 -2
  25. package/dist/parser/quotes.js +3 -3
  26. package/dist/parser/selector.js +2 -2
  27. package/dist/parser/table.js +7 -7
  28. package/dist/src/arg.d.ts +1 -1
  29. package/dist/src/arg.js +10 -9
  30. package/dist/src/atom.d.ts +1 -1
  31. package/dist/src/atom.js +4 -4
  32. package/dist/src/attribute.d.ts +1 -1
  33. package/dist/src/attribute.js +16 -17
  34. package/dist/src/attributes.d.ts +1 -1
  35. package/dist/src/attributes.js +8 -8
  36. package/dist/src/converter.d.ts +1 -1
  37. package/dist/src/converter.js +7 -8
  38. package/dist/src/converterFlags.d.ts +1 -1
  39. package/dist/src/converterFlags.js +9 -7
  40. package/dist/src/converterRule.d.ts +1 -1
  41. package/dist/src/converterRule.js +11 -10
  42. package/dist/src/extLink.d.ts +1 -1
  43. package/dist/src/extLink.js +18 -14
  44. package/dist/src/gallery.d.ts +2 -2
  45. package/dist/src/gallery.js +7 -7
  46. package/dist/src/heading.d.ts +1 -1
  47. package/dist/src/heading.js +12 -13
  48. package/dist/src/html.d.ts +1 -1
  49. package/dist/src/html.js +15 -14
  50. package/dist/src/imageParameter.d.ts +2 -2
  51. package/dist/src/imageParameter.js +12 -13
  52. package/dist/src/imagemap.d.ts +2 -2
  53. package/dist/src/imagemap.js +11 -7
  54. package/dist/src/imagemapLink.d.ts +1 -1
  55. package/dist/src/imagemapLink.js +6 -6
  56. package/dist/src/index.d.ts +1 -1
  57. package/dist/src/index.js +22 -9
  58. package/dist/src/link/base.d.ts +1 -1
  59. package/dist/src/link/base.js +18 -15
  60. package/dist/src/link/file.d.ts +1 -1
  61. package/dist/src/link/file.js +9 -5
  62. package/dist/src/link/galleryImage.d.ts +1 -1
  63. package/dist/src/link/galleryImage.js +10 -6
  64. package/dist/src/link/index.js +1 -1
  65. package/dist/src/magicLink.d.ts +2 -2
  66. package/dist/src/magicLink.js +8 -7
  67. package/dist/src/nested.d.ts +1 -1
  68. package/dist/src/nested.js +6 -5
  69. package/dist/src/nowiki/base.d.ts +1 -1
  70. package/dist/src/nowiki/base.js +4 -4
  71. package/dist/src/nowiki/comment.d.ts +1 -1
  72. package/dist/src/nowiki/comment.js +9 -6
  73. package/dist/src/nowiki/doubleUnderscore.d.ts +1 -1
  74. package/dist/src/nowiki/doubleUnderscore.js +5 -4
  75. package/dist/src/nowiki/hr.js +1 -0
  76. package/dist/src/nowiki/index.js +2 -2
  77. package/dist/src/nowiki/list.js +1 -0
  78. package/dist/src/nowiki/quote.js +3 -3
  79. package/dist/src/onlyinclude.js +6 -6
  80. package/dist/src/paramTag/index.d.ts +1 -1
  81. package/dist/src/paramTag/index.js +7 -7
  82. package/dist/src/paramTag/inputbox.d.ts +1 -1
  83. package/dist/src/paramTag/inputbox.js +4 -4
  84. package/dist/src/parameter.d.ts +1 -1
  85. package/dist/src/parameter.js +18 -20
  86. package/dist/src/pre.d.ts +1 -1
  87. package/dist/src/pre.js +5 -5
  88. package/dist/src/syntax.d.ts +1 -1
  89. package/dist/src/syntax.js +5 -4
  90. package/dist/src/table/base.d.ts +1 -1
  91. package/dist/src/table/base.js +6 -5
  92. package/dist/src/table/index.d.ts +1 -1
  93. package/dist/src/table/index.js +11 -6
  94. package/dist/src/table/td.d.ts +1 -1
  95. package/dist/src/table/td.js +28 -17
  96. package/dist/src/table/tr.d.ts +1 -1
  97. package/dist/src/table/tr.js +2 -2
  98. package/dist/src/table/trBase.js +2 -2
  99. package/dist/src/tagPair/ext.d.ts +1 -1
  100. package/dist/src/tagPair/ext.js +8 -6
  101. package/dist/src/tagPair/include.d.ts +1 -1
  102. package/dist/src/tagPair/include.js +6 -6
  103. package/dist/src/tagPair/index.d.ts +1 -1
  104. package/dist/src/tagPair/index.js +16 -13
  105. package/dist/src/transclude.d.ts +1 -1
  106. package/dist/src/transclude.js +35 -20
  107. package/dist/util/debug.js +7 -0
  108. package/dist/util/diff.js +11 -1
  109. package/dist/util/lint.js +2 -2
  110. package/package.json +1 -1
@@ -5,7 +5,7 @@ const lint_1 = require("../../util/lint");
5
5
  const debug_1 = require("../../util/debug");
6
6
  const constants_1 = require("../../util/constants");
7
7
  const hidden_1 = require("../../mixin/hidden");
8
- const Parser = require("../../index");
8
+ const index_1 = require("../../index");
9
9
  const base_1 = require("./base");
10
10
  /** HTML注释,不可见 */
11
11
  class CommentToken extends (0, hidden_1.hiddenToken)(base_1.NowikiBaseToken) {
@@ -21,9 +21,10 @@ class CommentToken extends (0, hidden_1.hiddenToken)(base_1.NowikiBaseToken) {
21
21
  }
22
22
  /* NOT FOR BROWSER END */
23
23
  /** @param closed 是否闭合 */
24
- constructor(wikitext, closed = true, config = Parser.getConfig(), accum = []) {
24
+ constructor(wikitext, closed = true, config = index_1.default.getConfig(), accum = []) {
25
25
  super(wikitext, config, accum);
26
26
  this.closed = closed;
27
+ /* NOT FOR BROWSER */
27
28
  Object.defineProperty(this, 'closed', { enumerable: false });
28
29
  }
29
30
  /** @private */
@@ -32,15 +33,17 @@ class CommentToken extends (0, hidden_1.hiddenToken)(base_1.NowikiBaseToken) {
32
33
  }
33
34
  /** @override */
34
35
  lint(start = this.getAbsoluteIndex()) {
35
- return this.closed ? [] : [(0, lint_1.generateForSelf)(this, { start }, Parser.msg('unclosed $1', 'HTML comment'))];
36
+ return this.closed ? [] : [(0, lint_1.generateForSelf)(this, { start }, index_1.default.msg('unclosed $1', 'HTML comment'))];
36
37
  }
37
38
  /** @private */
38
- toString(omit) {
39
+ toString() {
40
+ /* NOT FOR BROWSER */
39
41
  if (!this.closed && this.nextSibling) {
40
- Parser.error('自动闭合HTML注释', this);
42
+ index_1.default.error('自动闭合HTML注释', this);
41
43
  this.closed = true;
42
44
  }
43
- return omit && this.matchesTypes(omit) ? '' : `<!--${this.innerText}${this.closed ? '-->' : ''}`;
45
+ /* NOT FOR BROWSER END */
46
+ return `<!--${this.innerText}${this.closed ? '-->' : ''}`;
44
47
  }
45
48
  /** @override */
46
49
  print() {
@@ -1,4 +1,4 @@
1
- import * as Parser from '../../index';
1
+ import Parser from '../../index';
2
2
  import { NowikiBaseToken } from './base';
3
3
  import type { Token } from '../index';
4
4
  export declare abstract class DoubleUnderscoreToken extends NowikiBaseToken {
@@ -5,7 +5,7 @@ const debug_1 = require("../../util/debug");
5
5
  const constants_1 = require("../../util/constants");
6
6
  const hidden_1 = require("../../mixin/hidden");
7
7
  const syntax_1 = require("../../mixin/syntax");
8
- const Parser = require("../../index");
8
+ const index_1 = require("../../index");
9
9
  const base_1 = require("./base");
10
10
  /** 状态开关 */
11
11
  class DoubleUnderscoreToken extends (0, syntax_1.syntax)((0, hidden_1.hiddenToken)(base_1.NowikiBaseToken)) {
@@ -16,8 +16,9 @@ class DoubleUnderscoreToken extends (0, syntax_1.syntax)((0, hidden_1.hiddenToke
16
16
  * @param word 状态开关名
17
17
  * @param sensitive 是否固定大小写
18
18
  */
19
- constructor(word, sensitive, config = Parser.getConfig(), accum = []) {
19
+ constructor(word, sensitive, config = index_1.default.getConfig(), accum = []) {
20
20
  super(word, config, accum);
21
+ /* NOT FOR BROWSER */
21
22
  this.#sensitive = sensitive;
22
23
  this.setAttribute('name', word.toLowerCase());
23
24
  this.setAttribute('pattern', new RegExp(`^${word}$`, sensitive ? 'u' : 'iu'));
@@ -27,8 +28,8 @@ class DoubleUnderscoreToken extends (0, syntax_1.syntax)((0, hidden_1.hiddenToke
27
28
  return key === 'padding' ? 2 : super.getAttribute(key);
28
29
  }
29
30
  /** @private */
30
- toString(omit) {
31
- return omit && this.matchesTypes(omit) ? '' : `__${this.innerText}__`;
31
+ toString() {
32
+ return `__${this.innerText}__`;
32
33
  }
33
34
  /** @override */
34
35
  print() {
@@ -5,6 +5,7 @@ const constants_1 = require("../../util/constants");
5
5
  const sol_1 = require("../../mixin/sol");
6
6
  const syntax_1 = require("../../mixin/syntax");
7
7
  const base_1 = require("./base");
8
+ /* NOT FOR BROWSER END */
8
9
  /** `<hr>` */
9
10
  class HrToken extends (0, syntax_1.syntax)((0, sol_1.sol)(base_1.NowikiBaseToken), /^-{4,}$/u) {
10
11
  type = 'hr';
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NowikiToken = void 0;
4
4
  const lint_1 = require("../../util/lint");
5
5
  const constants_1 = require("../../util/constants");
6
- const Parser = require("../../index");
6
+ const index_1 = require("../../index");
7
7
  const base_1 = require("./base");
8
8
  /** 扩展标签内的纯文字Token */
9
9
  class NowikiToken extends base_1.NowikiBaseToken {
@@ -12,7 +12,7 @@ class NowikiToken extends base_1.NowikiBaseToken {
12
12
  lint(start = this.getAbsoluteIndex()) {
13
13
  const { name, firstChild: { data } } = this;
14
14
  return (name === 'templatestyles' || name === 'section') && data
15
- ? [(0, lint_1.generateForSelf)(this, { start }, Parser.msg('nothing should be in <$1>', name))]
15
+ ? [(0, lint_1.generateForSelf)(this, { start }, index_1.default.msg('nothing should be in <$1>', name))]
16
16
  : super.lint(start);
17
17
  }
18
18
  }
@@ -4,6 +4,7 @@ exports.ListToken = void 0;
4
4
  const constants_1 = require("../../util/constants");
5
5
  const sol_1 = require("../../mixin/sol");
6
6
  const listBase_1 = require("./listBase");
7
+ /* NOT FOR BROWSER END */
7
8
  /** 位于行首的`;:*#` */
8
9
  class ListToken extends (0, sol_1.sol)(listBase_1.ListBaseToken) {
9
10
  type = 'list';
@@ -4,7 +4,7 @@ exports.QuoteToken = void 0;
4
4
  const lint_1 = require("../../util/lint");
5
5
  const constants_1 = require("../../util/constants");
6
6
  const syntax_1 = require("../../mixin/syntax");
7
- const Parser = require("../../index");
7
+ const index_1 = require("../../index");
8
8
  const base_1 = require("./base");
9
9
  /** `''`和`'''` */
10
10
  class QuoteToken extends (0, syntax_1.syntax)(base_1.NowikiBaseToken, /^(?:'{5}|'''?)$/u) {
@@ -19,7 +19,7 @@ class QuoteToken extends (0, syntax_1.syntax)(base_1.NowikiBaseToken, /^(?:'{5}|
19
19
  }
20
20
  /** @override */
21
21
  lint(start = this.getAbsoluteIndex()) {
22
- const { previousSibling, nextSibling, bold } = this, message = Parser.msg('lonely "$1"', `'`), errors = [];
22
+ const { previousSibling, nextSibling, bold } = this, message = index_1.default.msg('lonely "$1"', `'`), errors = [];
23
23
  let refError;
24
24
  if (previousSibling?.type === 'text' && previousSibling.data.endsWith(`'`)) {
25
25
  refError = (0, lint_1.generateForSelf)(this, { start }, message);
@@ -49,7 +49,7 @@ class QuoteToken extends (0, syntax_1.syntax)(base_1.NowikiBaseToken, /^(?:'{5}|
49
49
  refError ??= (0, lint_1.generateForSelf)(this, { start }, message);
50
50
  errors.push({
51
51
  ...refError,
52
- message: Parser.msg('bold in section header'),
52
+ message: index_1.default.msg('bold in section header'),
53
53
  severity: 'warning',
54
54
  });
55
55
  }
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OnlyincludeToken = void 0;
4
4
  const debug_1 = require("../util/debug");
5
5
  const constants_1 = require("../util/constants");
6
- const Parser = require("../index");
7
- const index_1 = require("./index");
6
+ const index_1 = require("../index");
7
+ const index_2 = require("./index");
8
8
  /**
9
9
  * 嵌入时的`<onlyinclude>`
10
10
  * @classdesc `{childNodes: ...AstText|Token}`
11
11
  */
12
- class OnlyincludeToken extends index_1.Token {
12
+ class OnlyincludeToken extends index_2.Token {
13
13
  type = 'onlyinclude';
14
14
  /* NOT FOR BROWSER */
15
15
  /** 内部wikitext */
@@ -21,12 +21,12 @@ class OnlyincludeToken extends index_1.Token {
21
21
  if (text.includes('</onlyinclude>')) {
22
22
  throw new RangeError('不允许包含 "</onlyinclude>"!');
23
23
  }
24
- this.replaceChildren(...Parser.parse(text, true, undefined, this.getAttribute('config')).childNodes);
24
+ this.replaceChildren(...index_1.default.parse(text, true, undefined, this.getAttribute('config')).childNodes);
25
25
  }
26
26
  /* NOT FOR BROWSER END */
27
27
  /** @private */
28
- toString(omit) {
29
- return omit && this.matchesTypes(omit) ? '' : `<onlyinclude>${super.toString(omit)}</onlyinclude>`;
28
+ toString() {
29
+ return `<onlyinclude>${super.toString()}</onlyinclude>`;
30
30
  }
31
31
  /** @private */
32
32
  getAttribute(key) {
@@ -1,4 +1,4 @@
1
- import * as Parser from '../../index';
1
+ import Parser from '../../index';
2
2
  import { Token } from '../index';
3
3
  import { AtomToken } from '../atom';
4
4
  import type { LintError } from '../../base';
@@ -5,17 +5,17 @@ const lint_1 = require("../../util/lint");
5
5
  const debug_1 = require("../../util/debug");
6
6
  const constants_1 = require("../../util/constants");
7
7
  const singleLine_1 = require("../../mixin/singleLine");
8
- const Parser = require("../../index");
9
- const index_1 = require("../index");
8
+ const index_1 = require("../../index");
9
+ const index_2 = require("../index");
10
10
  const atom_1 = require("../atom");
11
11
  /**
12
12
  * `<dynamicpagelist>`
13
13
  * @classdesc `{childNodes: ...AtomToken}`
14
14
  */
15
- class ParamTagToken extends index_1.Token {
15
+ class ParamTagToken extends index_2.Token {
16
16
  type = 'ext-inner';
17
17
  /** @class */
18
- constructor(wikitext, config = Parser.getConfig(), accum = [], acceptable = {}) {
18
+ constructor(wikitext, config = index_1.default.getConfig(), accum = [], acceptable = {}) {
19
19
  super(undefined, config, accum, {
20
20
  SingleLineAtomToken: ':',
21
21
  });
@@ -27,8 +27,8 @@ class ParamTagToken extends index_1.Token {
27
27
  }
28
28
  }
29
29
  /** @private */
30
- toString(omit) {
31
- return super.toString(omit, '\n');
30
+ toString() {
31
+ return super.toString('\n');
32
32
  }
33
33
  /** @override */
34
34
  text() {
@@ -46,7 +46,7 @@ class ParamTagToken extends index_1.Token {
46
46
  return str && !(i >= 0 ? /^[a-z]+(?:\[\])?\s*(?:=|$)/iu : /^[a-z]+(?:\[\])?\s*=/iu).test(str);
47
47
  }).map(child => {
48
48
  rect ??= { start, ...this.getRootNode().posFromIndex(start) };
49
- return (0, lint_1.generateForChild)(child, rect, Parser.msg('invalid parameter of <$1>', this.name));
49
+ return (0, lint_1.generateForChild)(child, rect, index_1.default.msg('invalid parameter of <$1>', this.name));
50
50
  });
51
51
  }
52
52
  /** @override */
@@ -1,4 +1,4 @@
1
- import * as Parser from '../../index';
1
+ import Parser from '../../index';
2
2
  import { ParamTagToken } from './index';
3
3
  import type { Token } from '../index';
4
4
  /** `<inputbox>` */
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InputboxToken = void 0;
4
4
  const constants_1 = require("../../util/constants");
5
5
  const braces_1 = require("../../parser/braces");
6
- const Parser = require("../../index");
7
- const index_1 = require("./index");
6
+ const index_1 = require("../../index");
7
+ const index_2 = require("./index");
8
8
  /** `<inputbox>` */
9
- class InputboxToken extends index_1.ParamTagToken {
9
+ class InputboxToken extends index_2.ParamTagToken {
10
10
  /** @class */
11
- constructor(wikitext, config = Parser.getConfig(), accum = []) {
11
+ constructor(wikitext, config = index_1.default.getConfig(), accum = []) {
12
12
  const placeholder = Symbol('InputboxToken');
13
13
  accum.push(placeholder);
14
14
  wikitext &&= (0, braces_1.parseBraces)(wikitext, config, accum);
@@ -1,4 +1,4 @@
1
- import * as Parser from '../index';
1
+ import Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import type { LintError } from '../base';
4
4
  import type { AtomToken, SyntaxToken, TranscludeToken } from '../internal';
@@ -6,19 +6,18 @@ const lint_1 = require("../util/lint");
6
6
  const debug_1 = require("../util/debug");
7
7
  const constants_1 = require("../util/constants");
8
8
  const fixed_1 = require("../mixin/fixed");
9
- const Parser = require("../index");
10
- const index_1 = require("./index");
9
+ const index_1 = require("../index");
10
+ const index_2 = require("./index");
11
11
  /**
12
12
  * 准确获取参数名
13
13
  * @param name 预定的参数名
14
14
  */
15
- const getName = (name) => name.toString(new Set(['comment', 'noinclude', 'include']))
16
- .replace(/^[ \t\n\0\v]+|([^ \t\n\0\v])[ \t\n\0\v]+$/gu, '$1');
15
+ const getName = (name) => name.text().replace(/^[ \t\n\0\v]+|([^ \t\n\0\v])[ \t\n\0\v]+$/gu, '$1');
17
16
  /**
18
17
  * 模板或魔术字参数
19
18
  * @classdesc `{childNodes: [Token, Token]}`
20
19
  */
21
- class ParameterToken extends (0, fixed_1.fixedToken)(index_1.Token) {
20
+ class ParameterToken extends (0, fixed_1.fixedToken)(index_2.Token) {
22
21
  type = 'parameter';
23
22
  /** 是否是匿名参数 */
24
23
  get anon() {
@@ -57,11 +56,11 @@ class ParameterToken extends (0, fixed_1.fixedToken)(index_1.Token) {
57
56
  * @param key 参数名
58
57
  * @param value 参数值
59
58
  */
60
- constructor(key, value, config = Parser.getConfig(), accum = []) {
59
+ constructor(key, value, config = index_1.default.getConfig(), accum = []) {
61
60
  super(undefined, config, accum);
62
- const keyToken = new index_1.Token(typeof key === 'number' ? undefined : key, config, accum, {
61
+ const keyToken = new index_2.Token(typeof key === 'number' ? undefined : key, config, accum, {
63
62
  'Stage-11': ':', '!HeadingToken': '',
64
- }), token = new index_1.Token(value, config, accum);
63
+ }), token = new index_2.Token(value, config, accum);
65
64
  keyToken.type = 'parameter-key';
66
65
  token.type = 'parameter-value';
67
66
  token.setAttribute('stage', 2);
@@ -73,10 +72,13 @@ class ParameterToken extends (0, fixed_1.fixedToken)(index_1.Token) {
73
72
  const { parentNode, firstChild } = this, name = getName(firstChild);
74
73
  this.setAttribute('name', name);
75
74
  if (parentNode) {
75
+ /* NOT FOR BROWSER */
76
76
  parentNode.getAttribute('keys').add(name);
77
+ /* NOT FOR BROWSER END */
77
78
  parentNode.getArgs(name, false, false).add(this);
78
79
  }
79
80
  }
81
+ /* NOT FOR BROWSER */
80
82
  const /** @implements */ parameterListener = ({ prevTarget }, data) => {
81
83
  if (!this.anon) { // 匿名参数不管怎么变动还是匿名
82
84
  const { firstChild, name } = this;
@@ -91,11 +93,8 @@ class ParameterToken extends (0, fixed_1.fixedToken)(index_1.Token) {
91
93
  this.addEventListener(['remove', 'insert', 'replace', 'text'], parameterListener);
92
94
  }
93
95
  /** @private */
94
- toString(omit) {
95
- return this.anon
96
- && !(omit && this.matchesTypes(omit))
97
- ? this.lastChild.toString(omit)
98
- : super.toString(omit, '=');
96
+ toString() {
97
+ return this.anon ? String(this.lastChild) : super.toString('=');
99
98
  }
100
99
  /** @override */
101
100
  text() {
@@ -109,8 +108,7 @@ class ParameterToken extends (0, fixed_1.fixedToken)(index_1.Token) {
109
108
  lint(start = this.getAbsoluteIndex()) {
110
109
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
111
110
  /https?:\/\/(?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])(?:[^[\]<>"\0\t\n\p{Zs}]|\0\d+c\x7F)*$/iu;
112
- const errors = super.lint(start), { firstChild } = this, link = new RegExp(`https?://${string_1.extUrlCharFirst}${string_1.extUrlChar}$`, 'iu')
113
- .exec(firstChild.toString(new Set(['comment', 'noinclude', 'include'])))?.[0];
111
+ const errors = super.lint(start), { firstChild } = this, link = new RegExp(`https?://${string_1.extUrlCharFirst}${string_1.extUrlChar}$`, 'iu').exec(firstChild.text())?.[0];
114
112
  if (link && new URL(link).search) {
115
113
  const e = (0, lint_1.generateForChild)(firstChild, { start }, 'unescaped query string in an anonymous parameter');
116
114
  errors.push({
@@ -156,7 +154,7 @@ class ParameterToken extends (0, fixed_1.fixedToken)(index_1.Token) {
156
154
  * @param token 待替换的节点
157
155
  */
158
156
  safeReplaceWith(token) {
159
- Parser.warn(`${this.constructor.name}.safeReplaceWith 方法退化到 replaceWith。`);
157
+ index_1.default.warn(`${this.constructor.name}.safeReplaceWith 方法退化到 replaceWith。`);
160
158
  this.replaceWith(token);
161
159
  }
162
160
  /** 获取参数值 */
@@ -169,7 +167,7 @@ class ParameterToken extends (0, fixed_1.fixedToken)(index_1.Token) {
169
167
  * @param value 参数值
170
168
  */
171
169
  setValue(value) {
172
- const { childNodes } = Parser.parse(value, this.getAttribute('include'), undefined, this.getAttribute('config'));
170
+ const { childNodes } = index_1.default.parse(value, this.getAttribute('include'), undefined, this.getAttribute('config'));
173
171
  this.lastChild.replaceChildren(...childNodes);
174
172
  }
175
173
  /**
@@ -188,13 +186,13 @@ class ParameterToken extends (0, fixed_1.fixedToken)(index_1.Token) {
188
186
  else if (anon) {
189
187
  parentNode?.anonToNamed();
190
188
  }
191
- const root = Parser.parse(key, this.getAttribute('include'), undefined, this.getAttribute('config')), name = getName(root);
189
+ const root = index_1.default.parse(key, this.getAttribute('include'), undefined, this.getAttribute('config')), name = getName(root);
192
190
  if (this.name === name) {
193
- Parser.warn('未改变实际参数名', name);
191
+ index_1.default.warn('未改变实际参数名', name);
194
192
  }
195
193
  else if (parentNode?.hasArg(name)) {
196
194
  if (force) {
197
- Parser.warn('参数更名造成重复参数', name);
195
+ index_1.default.warn('参数更名造成重复参数', name);
198
196
  }
199
197
  else {
200
198
  throw new RangeError(`参数更名造成重复参数:${name}`);
package/dist/src/pre.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as Parser from '../index';
1
+ import Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { NoincludeToken } from './nowiki/noinclude';
4
4
  import type { AstText, AttributesToken, ExtToken, ConverterToken } from '../internal';
package/dist/src/pre.js CHANGED
@@ -1,19 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PreToken = void 0;
4
- const debug_1 = require("../util/debug");
5
4
  const constants_1 = require("../util/constants");
6
- const Parser = require("../index");
7
- const index_1 = require("./index");
5
+ const debug_1 = require("../util/debug");
6
+ const index_1 = require("../index");
7
+ const index_2 = require("./index");
8
8
  const noinclude_1 = require("./nowiki/noinclude");
9
9
  /**
10
10
  * `<pre>`
11
11
  * @classdesc `{childNodes: [...AstText|NoincludeToken|ConverterToken]}`
12
12
  */
13
- class PreToken extends index_1.Token {
13
+ class PreToken extends index_2.Token {
14
14
  type = 'ext-inner';
15
15
  /** @class */
16
- constructor(wikitext, config = Parser.getConfig(), accum = []) {
16
+ constructor(wikitext, config = index_1.default.getConfig(), accum = []) {
17
17
  if (wikitext) {
18
18
  const opening = '<nowiki>', closing = '</nowiki>', { length } = opening;
19
19
  let i = wikitext.indexOf(opening), j = wikitext.indexOf(closing, i + length), str = '';
@@ -1,4 +1,4 @@
1
- import * as Parser from '../index';
1
+ import Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import type { LintError } from '../base';
4
4
  declare type SyntaxTypes = 'plain' | 'heading-trail' | 'magic-word-name' | 'table-syntax';
@@ -4,14 +4,15 @@ exports.SyntaxToken = void 0;
4
4
  const debug_1 = require("../util/debug");
5
5
  const constants_1 = require("../util/constants");
6
6
  const syntax_1 = require("../mixin/syntax");
7
- const Parser = require("../index");
8
- const index_1 = require("./index");
7
+ const index_1 = require("../index");
8
+ const index_2 = require("./index");
9
9
  /** 满足特定语法格式的plain Token */
10
- class SyntaxToken extends (0, syntax_1.syntax)(index_1.Token) {
10
+ class SyntaxToken extends (0, syntax_1.syntax)(index_2.Token) {
11
11
  /** @param pattern 语法正则 */
12
- constructor(wikitext, pattern, type = 'plain', config = Parser.getConfig(), accum = [], acceptable) {
12
+ constructor(wikitext, pattern, type = 'plain', config = index_1.default.getConfig(), accum = [], acceptable) {
13
13
  super(wikitext, config, accum, acceptable);
14
14
  this.type = type;
15
+ /* NOT FOR BROWSER */
15
16
  this.setAttribute('pattern', pattern);
16
17
  }
17
18
  /** @override */
@@ -1,4 +1,4 @@
1
- import * as Parser from '../../index';
1
+ import Parser from '../../index';
2
2
  import { Token } from '../index';
3
3
  import { SyntaxToken } from '../syntax';
4
4
  import { AttributesToken } from '../attributes';
@@ -4,8 +4,8 @@ exports.TableBaseToken = void 0;
4
4
  const debug_1 = require("../../util/debug");
5
5
  const constants_1 = require("../../util/constants");
6
6
  const attributesParent_1 = require("../../mixin/attributesParent");
7
- const Parser = require("../../index");
8
- const index_1 = require("../index");
7
+ const index_1 = require("../../index");
8
+ const index_2 = require("../index");
9
9
  const syntax_1 = require("../syntax");
10
10
  const attributes_1 = require("../attributes");
11
11
  /* NOT FOR BROWSER */
@@ -16,7 +16,7 @@ const attributes_1 = require("../attributes");
16
16
  const escapeTable = (syntax) => {
17
17
  const wikitext = syntax.childNodes.map(child => child.type === 'text'
18
18
  ? child.data.replace(/\|/gu, '{{!}}')
19
- : String(child)).join(''), { childNodes } = Parser.parse(wikitext, syntax.getAttribute('include'), 2, syntax.getAttribute('config'));
19
+ : String(child)).join(''), { childNodes } = index_1.default.parse(wikitext, syntax.getAttribute('include'), 2, syntax.getAttribute('config'));
20
20
  syntax.replaceChildren(...childNodes);
21
21
  };
22
22
  /* NOT FOR BROWSER END */
@@ -24,19 +24,20 @@ const escapeTable = (syntax) => {
24
24
  * 表格行,含开头的换行,不含结尾的换行
25
25
  * @classdesc `{childNodes: [SyntaxToken, AttributesToken, ...Token]}`
26
26
  */
27
- class TableBaseToken extends (0, attributesParent_1.attributesParent)(index_1.Token, 1) {
27
+ class TableBaseToken extends (0, attributesParent_1.attributesParent)(index_2.Token, 1) {
28
28
  /**
29
29
  * @param pattern 表格语法正则
30
30
  * @param syntax 表格语法
31
31
  * @param attr 表格属性
32
32
  */
33
- constructor(pattern, syntax, attr, config = Parser.getConfig(), accum = [], acceptable = {}) {
33
+ constructor(pattern, syntax, attr, config = index_1.default.getConfig(), accum = [], acceptable = {}) {
34
34
  super(undefined, config, accum, acceptable);
35
35
  this.append(new syntax_1.SyntaxToken(syntax, pattern, 'table-syntax', config, accum, {
36
36
  'Stage-1': ':', '!ExtToken': '', TranscludeToken: ':',
37
37
  }),
38
38
  // @ts-expect-error abstract class
39
39
  new attributes_1.AttributesToken(attr, 'table-attrs', this.type, config, accum));
40
+ /* NOT FOR BROWSER */
40
41
  this.protectChildren(0, 1);
41
42
  }
42
43
  /* NOT FOR BROWSER */
@@ -1,4 +1,4 @@
1
- import * as Parser from '../../index';
1
+ import Parser from '../../index';
2
2
  import { TrBaseToken } from './trBase';
3
3
  import { SyntaxToken } from '../syntax';
4
4
  import type { LintError } from '../../base';
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TableToken = void 0;
4
4
  const lint_1 = require("../../util/lint");
5
- const string_1 = require("../../util/string");
6
5
  const debug_1 = require("../../util/debug");
6
+ const string_1 = require("../../util/string");
7
7
  const constants_1 = require("../../util/constants");
8
- const Parser = require("../../index");
8
+ const index_1 = require("../../index");
9
9
  const trBase_1 = require("./trBase");
10
10
  const syntax_1 = require("../syntax");
11
+ /* NOT FOR BROWSER END */
11
12
  const closingPattern = /^\n[^\S\n]*(?:\|\}|\{\{\s*!\s*\}\}\}|\{\{\s*!\)\s*\}\})$/u;
12
13
  /**
13
14
  * 表格
@@ -30,7 +31,7 @@ class TableToken extends trBase_1.TrBaseToken {
30
31
  * @param syntax 表格语法
31
32
  * @param attr 表格属性
32
33
  */
33
- constructor(syntax, attr, config = Parser.getConfig(), accum = []) {
34
+ constructor(syntax, attr, config = index_1.default.getConfig(), accum = []) {
34
35
  super(/^(?:\{\||\{\{\{\s*!\s*\}\}|\{\{\s*\(!\s*\}\})$/u, syntax, attr, config, accum, {
35
36
  Token: 2, SyntaxToken: [0, -1], AttributesToken: 1, TdToken: '2:', TrToken: '2:',
36
37
  });
@@ -39,7 +40,7 @@ class TableToken extends trBase_1.TrBaseToken {
39
40
  lint(start = this.getAbsoluteIndex()) {
40
41
  const errors = super.lint(start);
41
42
  if (!this.closed) {
42
- errors.push((0, lint_1.generateForChild)(this.firstChild, { start }, Parser.msg('unclosed $1', 'table')));
43
+ errors.push((0, lint_1.generateForChild)(this.firstChild, { start }, index_1.default.msg('unclosed $1', 'table')));
43
44
  }
44
45
  return errors;
45
46
  }
@@ -49,14 +50,18 @@ class TableToken extends trBase_1.TrBaseToken {
49
50
  * @param halfParsed
50
51
  */
51
52
  close(syntax = '\n|}', halfParsed = false) {
52
- const config = this.getAttribute('config'), accum = this.getAttribute('accum'), inner = halfParsed ? [syntax] : Parser.parse(syntax, this.getAttribute('include'), 2, config).childNodes;
53
+ const config = this.getAttribute('config'), accum = this.getAttribute('accum'), inner = halfParsed ? [syntax] : index_1.default.parse(syntax, this.getAttribute('include'), 2, config).childNodes;
54
+ /* NOT FOR BROWSER */
53
55
  if (this.lastChild.type !== 'table-syntax') {
56
+ /* NOT FOR BROWSER END */
54
57
  const token = debug_1.Shadow.run(() => super.insertAt(new syntax_1.SyntaxToken(undefined, closingPattern, 'table-syntax', config, accum, {
55
58
  'Stage-1': ':', '!ExtToken': '', TranscludeToken: ':',
56
59
  })));
60
+ /* NOT FOR BROWSER */
57
61
  if (!halfParsed) {
58
62
  token.afterBuild();
59
63
  }
64
+ /* NOT FOR BROWSER END */
60
65
  }
61
66
  this.lastChild.replaceChildren(...inner);
62
67
  }
@@ -78,7 +83,7 @@ class TableToken extends trBase_1.TrBaseToken {
78
83
  i += i < 0 ? this.length : 0;
79
84
  const previous = this.childNodes[i - 1];
80
85
  if (typeof token !== 'string' && token.type === 'td' && previous?.type === 'tr') {
81
- Parser.warn('改为将单元格插入当前行。');
86
+ index_1.default.warn('改为将单元格插入当前行。');
82
87
  return previous.insertAt(token);
83
88
  }
84
89
  else if (i > 0 && token instanceof syntax_1.SyntaxToken && token.getAttribute('pattern') !== closingPattern) {
@@ -1,4 +1,4 @@
1
- import * as Parser from '../../index';
1
+ import Parser from '../../index';
2
2
  import { Token } from '../index';
3
3
  import { TableBaseToken } from './base';
4
4
  import type { LintError } from '../../base';