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
@@ -4,15 +4,15 @@ exports.ConverterFlagsToken = void 0;
4
4
  const lint_1 = require("../util/lint");
5
5
  const debug_1 = require("../util/debug");
6
6
  const constants_1 = require("../util/constants");
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 atom_1 = require("./atom");
10
10
  const definedFlags = new Set(['A', 'T', 'R', 'D', '-', 'H', 'N']);
11
11
  /**
12
12
  * 转换flags
13
13
  * @classdesc `{childNodes: ...AtomToken}`
14
14
  */
15
- class ConverterFlagsToken extends index_1.Token {
15
+ class ConverterFlagsToken extends index_2.Token {
16
16
  type = 'converter-flags';
17
17
  #flags;
18
18
  /* NOT FOR BROWSER */
@@ -26,8 +26,9 @@ class ConverterFlagsToken extends index_1.Token {
26
26
  this.#newFlag(flag);
27
27
  }
28
28
  }
29
+ /* NOT FOR BROWSER END */
29
30
  /** @param flags 转换类型标记 */
30
- constructor(flags, config = Parser.getConfig(), accum = []) {
31
+ constructor(flags, config = index_1.default.getConfig(), accum = []) {
31
32
  super(undefined, config, accum, {
32
33
  AtomToken: ':',
33
34
  });
@@ -36,6 +37,7 @@ class ConverterFlagsToken extends index_1.Token {
36
37
  /** @private */
37
38
  afterBuild() {
38
39
  this.#flags = this.childNodes.map(child => child.text().trim());
40
+ /* NOT FOR BROWSER */
39
41
  const /** @implements */ converterFlagsListener = ({ prevTarget }) => {
40
42
  if (prevTarget) {
41
43
  this.#flags[this.childNodes.indexOf(prevTarget)] = prevTarget.text().trim();
@@ -44,8 +46,8 @@ class ConverterFlagsToken extends index_1.Token {
44
46
  this.addEventListener(['remove', 'insert', 'text', 'replace'], converterFlagsListener);
45
47
  }
46
48
  /** @private */
47
- toString(omit) {
48
- return super.toString(omit, ';');
49
+ toString() {
50
+ return super.toString(';');
49
51
  }
50
52
  /** @override */
51
53
  text() {
@@ -66,7 +68,7 @@ class ConverterFlagsToken extends index_1.Token {
66
68
  }
67
69
  /** @override */
68
70
  lint(start = this.getAbsoluteIndex()) {
69
- const variantFlags = this.getVariantFlags(), unknownFlags = this.getUnknownFlags(), validFlags = new Set(this.#flags.filter(flag => definedFlags.has(flag))), { length: emptyFlagCount } = this.#flags.filter(flag => !flag), knownFlagCount = this.#flags.length - unknownFlags.size - emptyFlagCount, errors = super.lint(start);
71
+ const variantFlags = this.getVariantFlags(), unknownFlags = this.getUnknownFlags(), validFlags = new Set(this.#flags.filter(flag => definedFlags.has(flag))), emptyFlagCount = this.#flags.filter(flag => !flag).length, knownFlagCount = this.#flags.length - unknownFlags.size - emptyFlagCount, errors = super.lint(start);
70
72
  if (variantFlags.size === knownFlagCount || validFlags.size === knownFlagCount) {
71
73
  return errors;
72
74
  }
@@ -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 { ConverterToken, ConverterFlagsToken } from '../internal';
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConverterRuleToken = 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
  const atom_1 = require("./atom");
9
9
  /**
10
10
  * 转换规则
11
11
  * @classdesc `{childNodes: ...AtomToken}`
12
12
  */
13
- class ConverterRuleToken extends index_1.Token {
13
+ class ConverterRuleToken extends index_2.Token {
14
14
  type = 'converter-rule';
15
15
  /* NOT FOR BROWSER */
16
16
  /** 语言变体 */
@@ -59,7 +59,7 @@ class ConverterRuleToken extends index_1.Token {
59
59
  * @param rule 转换规则
60
60
  * @param hasColon 是否带有":"
61
61
  */
62
- constructor(rule, hasColon = true, config = Parser.getConfig(), accum = []) {
62
+ constructor(rule, hasColon = true, config = index_1.default.getConfig(), accum = []) {
63
63
  super(undefined, config, accum);
64
64
  const i = rule.indexOf(':'), j = rule.slice(0, i).indexOf('=>'), v = j === -1 ? rule.slice(0, i) : rule.slice(j + 2, i);
65
65
  if (hasColon && config.variants.includes(v.trim())) {
@@ -72,16 +72,17 @@ class ConverterRuleToken extends index_1.Token {
72
72
  else {
73
73
  super.insertAt(new atom_1.AtomToken(rule, 'converter-rule-to', config, accum));
74
74
  }
75
+ /* NOT FOR BROWSER */
75
76
  this.protectChildren('1:');
76
77
  }
77
78
  /** @private */
78
- toString(omit) {
79
+ toString() {
79
80
  const { childNodes } = this;
80
- if (childNodes.length === 3 && !(omit && this.matchesTypes(omit))) {
81
+ if (childNodes.length === 3) {
81
82
  const [from, variant, to] = childNodes;
82
- return `${from.toString(omit)}=>${variant.toString(omit)}:${to.toString(omit)}`;
83
+ return `${String(from)}=>${String(variant)}:${String(to)}`;
83
84
  }
84
- return super.toString(omit, ':');
85
+ return super.toString(':');
85
86
  }
86
87
  /** @override */
87
88
  text() {
@@ -159,7 +160,7 @@ class ConverterRuleToken extends index_1.Token {
159
160
  * @param to 转换目标
160
161
  */
161
162
  setTo(to) {
162
- const { childNodes } = Parser.parse(to, this.getAttribute('include'), undefined, this.getAttribute('config'));
163
+ const { childNodes } = index_1.default.parse(to, this.getAttribute('include'), undefined, this.getAttribute('config'));
163
164
  this.lastChild.replaceChildren(...childNodes);
164
165
  }
165
166
  /**
@@ -185,7 +186,7 @@ class ConverterRuleToken extends index_1.Token {
185
186
  if (!variant) {
186
187
  throw new Error('请先指定语言变体!');
187
188
  }
188
- const config = this.getAttribute('config'), { childNodes } = Parser.parse(from, this.getAttribute('include'), undefined, config);
189
+ const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(from, this.getAttribute('include'), undefined, config);
189
190
  if (!unidirectional) {
190
191
  super.insertAt(debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'converter-rule-from', config)), 0);
191
192
  }
@@ -1,4 +1,4 @@
1
- import * as Parser from '../index';
1
+ import Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { MagicLinkToken } from './magicLink';
4
4
  import type { LintError } from '../base';
@@ -1,19 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ExtLinkToken = void 0;
4
- const string_1 = require("../util/string");
5
- const debug_1 = require("../util/debug");
6
4
  const constants_1 = require("../util/constants");
7
5
  const lint_1 = require("../util/lint");
6
+ const string_1 = require("../util/string");
7
+ const debug_1 = require("../util/debug");
8
8
  const magicLinkParent_1 = require("../mixin/magicLinkParent");
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
  const magicLink_1 = require("./magicLink");
12
12
  /**
13
13
  * 外链
14
14
  * @classdesc `{childNodes: [MagicLinkToken, ?Token]}`
15
15
  */
16
- class ExtLinkToken extends (0, magicLinkParent_1.magicLinkParent)(index_1.Token) {
16
+ class ExtLinkToken extends (0, magicLinkParent_1.magicLinkParent)(index_2.Token) {
17
17
  type = 'ext-link';
18
18
  #space;
19
19
  /* NOT FOR BROWSER */
@@ -32,7 +32,7 @@ class ExtLinkToken extends (0, magicLinkParent_1.magicLinkParent)(index_1.Token)
32
32
  * @param space 空白字符
33
33
  * @param text 链接文字
34
34
  */
35
- constructor(url, space = '', text = '', config = Parser.getConfig(), accum = []) {
35
+ constructor(url, space = '', text = '', config = index_1.default.getConfig(), accum = []) {
36
36
  super(undefined, config, accum, {
37
37
  MagicLinkToken: 0, Token: 1,
38
38
  });
@@ -40,30 +40,32 @@ class ExtLinkToken extends (0, magicLinkParent_1.magicLinkParent)(index_1.Token)
40
40
  this.insertAt(new magicLink_1.MagicLinkToken(url, true, config, accum));
41
41
  this.#space = space;
42
42
  if (text) {
43
- const inner = new index_1.Token(text, config, accum, {
43
+ const inner = new index_2.Token(text, config, accum, {
44
44
  'Stage-7': ':', ConverterToken: ':',
45
45
  });
46
46
  inner.type = 'ext-link-text';
47
47
  inner.setAttribute('stage', constants_1.MAX_STAGE - 1);
48
48
  this.insertAt(inner);
49
49
  }
50
+ /* NOT FOR BROWSER */
50
51
  this.protectChildren(0);
51
52
  }
52
53
  /** @private */
53
- toString(omit) {
54
- if (omit && this.matchesTypes(omit)) {
55
- return '';
56
- }
54
+ toString() {
57
55
  if (this.length === 1) {
58
- return `[${super.toString(omit)}${this.#space}]`;
56
+ return `[${super.toString()}${this.#space}]`;
59
57
  }
58
+ /* NOT FOR BROWSER */
60
59
  this.#correct();
61
60
  (0, string_1.normalizeSpace)(this.lastChild);
62
- return `[${super.toString(omit, this.#space)}]`;
61
+ /* NOT FOR BROWSER END */
62
+ return `[${super.toString(this.#space)}]`;
63
63
  }
64
64
  /** @override */
65
65
  text() {
66
+ /* NOT FOR BROWSER */
66
67
  (0, string_1.normalizeSpace)(this.childNodes[1]);
68
+ /* NOT FOR BROWSER END */
67
69
  return `[${super.text(' ')}]`;
68
70
  }
69
71
  /** @private */
@@ -72,7 +74,9 @@ class ExtLinkToken extends (0, magicLinkParent_1.magicLinkParent)(index_1.Token)
72
74
  }
73
75
  /** @private */
74
76
  getGaps() {
77
+ /* NOT FOR BROWSER */
75
78
  this.#correct();
79
+ /* NOT FOR BROWSER END */
76
80
  return this.#space.length;
77
81
  }
78
82
  /** @override */
@@ -115,7 +119,7 @@ class ExtLinkToken extends (0, magicLinkParent_1.magicLinkParent)(index_1.Token)
115
119
  * @param str 链接显示文字
116
120
  */
117
121
  setLinkText(str) {
118
- const root = Parser.parse(str, this.getAttribute('include'), 7, this.getAttribute('config'));
122
+ const root = index_1.default.parse(str, this.getAttribute('include'), 7, this.getAttribute('config'));
119
123
  if (this.length === 1) {
120
124
  root.type = 'ext-link-text';
121
125
  root.setAttribute('acceptable', {
@@ -1,9 +1,9 @@
1
- import * as Parser from '../index';
1
+ import Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { GalleryImageToken } from './link/galleryImage';
4
4
  import { NoincludeToken } from './nowiki/noinclude';
5
5
  import type { LintError } from '../base';
6
- import type { AstNodes, AstText, AttributesToken, ExtToken } from '../internal';
6
+ import type { AstText, AttributesToken, ExtToken, AstNodes } from '../internal';
7
7
  /**
8
8
  * gallery标签
9
9
  * @classdesc `{childNodes: ...(GalleryImageToken|NoincludeToken|AstText)}`
@@ -3,15 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GalleryToken = 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
  const galleryImage_1 = require("./link/galleryImage");
9
9
  const noinclude_1 = require("./nowiki/noinclude");
10
10
  /**
11
11
  * gallery标签
12
12
  * @classdesc `{childNodes: ...(GalleryImageToken|NoincludeToken|AstText)}`
13
13
  */
14
- class GalleryToken extends index_1.Token {
14
+ class GalleryToken extends index_2.Token {
15
15
  type = 'ext-inner';
16
16
  /* NOT FOR BROWSER */
17
17
  /** 所有图片 */
@@ -20,7 +20,7 @@ class GalleryToken extends index_1.Token {
20
20
  }
21
21
  /* NOT FOR BROWSER END */
22
22
  /** @param inner 标签内部wikitext */
23
- constructor(inner, config = Parser.getConfig(), accum = []) {
23
+ constructor(inner, config = index_1.default.getConfig(), accum = []) {
24
24
  super(undefined, config, accum, {
25
25
  AstText: ':', GalleryImageToken: ':', NoincludeToken: ':',
26
26
  });
@@ -50,8 +50,8 @@ class GalleryToken extends index_1.Token {
50
50
  return this.normalizeTitle(file, 6, true, true).valid;
51
51
  }
52
52
  /** @private */
53
- toString(omit) {
54
- return super.toString(omit, '\n');
53
+ toString() {
54
+ return super.toString('\n');
55
55
  }
56
56
  /** @override */
57
57
  text() {
@@ -68,7 +68,7 @@ class GalleryToken extends index_1.Token {
68
68
  const child = this.childNodes[i], str = String(child), { length } = str, trimmed = str.trim(), startLine = top + i, startCol = i ? 0 : left;
69
69
  if (child.type === 'noinclude' && trimmed && !/^<!--.*-->$/u.test(trimmed)) {
70
70
  errors.push({
71
- message: Parser.msg('invalid content in <$1>', 'gallery'),
71
+ message: index_1.default.msg('invalid content in <$1>', 'gallery'),
72
72
  severity: 'error',
73
73
  startIndex: start,
74
74
  endIndex: start + length,
@@ -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 type { LintError } from '../base';
@@ -6,14 +6,15 @@ const debug_1 = require("../util/debug");
6
6
  const constants_1 = require("../util/constants");
7
7
  const fixed_1 = require("../mixin/fixed");
8
8
  const sol_1 = require("../mixin/sol");
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
  const syntax_1 = require("./syntax");
12
+ /* NOT FOR BROWSER END */
12
13
  /**
13
14
  * 章节标题
14
15
  * @classdesc `{childNodes: [Token, SyntaxToken]}`
15
16
  */
16
- class HeadingToken extends (0, sol_1.sol)((0, fixed_1.fixedToken)(index_1.Token)) {
17
+ class HeadingToken extends (0, sol_1.sol)((0, fixed_1.fixedToken)(index_2.Token)) {
17
18
  type = 'heading';
18
19
  #level;
19
20
  /** 标题格式的等号 */
@@ -37,7 +38,7 @@ class HeadingToken extends (0, sol_1.sol)((0, fixed_1.fixedToken)(index_1.Token)
37
38
  if (text.length > 1 && text.startsWith('=') && text.endsWith('=')) {
38
39
  throw new Error('修改标题层级请使用 setLevel 方法!');
39
40
  }
40
- const { childNodes } = Parser.parse(text, this.getAttribute('include'), undefined, this.getAttribute('config'));
41
+ const { childNodes } = index_1.default.parse(text, this.getAttribute('include'), undefined, this.getAttribute('config'));
41
42
  this.firstChild.replaceChildren(...childNodes);
42
43
  }
43
44
  /* NOT FOR BROWSER END */
@@ -45,10 +46,10 @@ class HeadingToken extends (0, sol_1.sol)((0, fixed_1.fixedToken)(index_1.Token)
45
46
  * @param level 标题层级
46
47
  * @param input 标题文字
47
48
  */
48
- constructor(level, input, config = Parser.getConfig(), accum = []) {
49
+ constructor(level, input, config = index_1.default.getConfig(), accum = []) {
49
50
  super(undefined, config, accum);
50
51
  this.#level = level;
51
- const token = new index_1.Token(input[0], config, accum);
52
+ const token = new index_2.Token(input[0], config, accum);
52
53
  token.type = 'heading-title';
53
54
  token.setAttribute('stage', 2);
54
55
  const trail = new syntax_1.SyntaxToken(input[1], /^[^\S\n]*$/u, 'heading-trail', config, accum, {
@@ -57,11 +58,9 @@ class HeadingToken extends (0, sol_1.sol)((0, fixed_1.fixedToken)(index_1.Token)
57
58
  this.append(token, trail);
58
59
  }
59
60
  /** @private */
60
- toString(omit) {
61
+ toString() {
61
62
  const equals = this.#equals;
62
- return omit && this.matchesTypes(omit)
63
- ? ''
64
- : `${this.prependNewLine()}${equals}${this.firstChild.toString(omit)}${equals}${this.lastChild.toString(omit)}`;
63
+ return `${this.prependNewLine()}${equals}${String(this.firstChild)}${equals}${String(this.lastChild)}`;
65
64
  }
66
65
  /** @override */
67
66
  text() {
@@ -88,7 +87,7 @@ class HeadingToken extends (0, sol_1.sol)((0, fixed_1.fixedToken)(index_1.Token)
88
87
  }
89
88
  if (innerStr.startsWith('=') || innerStr.endsWith('=')) {
90
89
  rect ??= { start, ...this.getRootNode().posFromIndex(start) };
91
- errors.push((0, lint_1.generateForChild)(firstChild, rect, Parser.msg('unbalanced $1 in a section header', '"="')));
90
+ errors.push((0, lint_1.generateForChild)(firstChild, rect, index_1.default.msg('unbalanced $1 in a section header', '"="')));
92
91
  }
93
92
  if (this.closest('html-attrs, table-attrs')) {
94
93
  rect ??= { start, ...this.getRootNode().posFromIndex(start) };
@@ -96,11 +95,11 @@ class HeadingToken extends (0, sol_1.sol)((0, fixed_1.fixedToken)(index_1.Token)
96
95
  }
97
96
  if (boldQuotes.length % 2) {
98
97
  rect ??= { start, ...this.getRootNode().posFromIndex(start) };
99
- errors.push((0, lint_1.generateForChild)(boldQuotes[boldQuotes.length - 1], { ...rect, start: start + level, left: rect.left + level }, Parser.msg('unbalanced $1 in a section header', 'bold apostrophes')));
98
+ errors.push((0, lint_1.generateForChild)(boldQuotes[boldQuotes.length - 1], { ...rect, start: start + level, left: rect.left + level }, index_1.default.msg('unbalanced $1 in a section header', 'bold apostrophes')));
100
99
  }
101
100
  if (italicQuotes.length % 2) {
102
101
  rect ??= { start, ...this.getRootNode().posFromIndex(start) };
103
- errors.push((0, lint_1.generateForChild)(italicQuotes[italicQuotes.length - 1], { start: start + level }, Parser.msg('unbalanced $1 in a section header', 'italic apostrophes')));
102
+ errors.push((0, lint_1.generateForChild)(italicQuotes[italicQuotes.length - 1], { start: start + level }, index_1.default.msg('unbalanced $1 in a section header', 'italic apostrophes')));
104
103
  }
105
104
  return errors;
106
105
  }
@@ -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 { AttributesParentBase } from '../mixin/attributesParent';
package/dist/src/html.js CHANGED
@@ -7,8 +7,8 @@ const debug_1 = require("../util/debug");
7
7
  const constants_1 = require("../util/constants");
8
8
  const fixed_1 = require("../mixin/fixed");
9
9
  const attributesParent_1 = require("../mixin/attributesParent");
10
- const Parser = require("../index");
11
- const index_1 = require("./index");
10
+ const index_1 = require("../index");
11
+ const index_2 = require("./index");
12
12
  const magicWords = new Set(['if', 'ifeq', 'ifexpr', 'ifexist', 'iferror', 'switch']), formattingTags = new Set([
13
13
  'b',
14
14
  'big',
@@ -36,11 +36,12 @@ const magicWords = new Set(['if', 'ifeq', 'ifexpr', 'ifexist', 'iferror', 'switc
36
36
  'u',
37
37
  'var',
38
38
  ]), obsoleteTags = new Set(['strike', 'big', 'center', 'font', 'tt']);
39
+ /* NOT FOR BROWSER END */
39
40
  /**
40
41
  * HTML标签
41
42
  * @classdesc `{childNodes: [AttributesToken]}`
42
43
  */
43
- class HtmlToken extends (0, attributesParent_1.attributesParent)((0, fixed_1.fixedToken)(index_1.Token)) {
44
+ class HtmlToken extends (0, attributesParent_1.attributesParent)((0, fixed_1.fixedToken)(index_2.Token)) {
44
45
  type = 'html';
45
46
  #closing;
46
47
  #selfClosing;
@@ -91,7 +92,7 @@ class HtmlToken extends (0, attributesParent_1.attributesParent)((0, fixed_1.fix
91
92
  * @param closing 是否闭合
92
93
  * @param selfClosing 是否自封闭
93
94
  */
94
- constructor(name, attr, closing, selfClosing, config = Parser.getConfig(), accum = []) {
95
+ constructor(name, attr, closing, selfClosing, config = index_1.default.getConfig(), accum = []) {
95
96
  super(undefined, config, accum);
96
97
  this.insertAt(attr);
97
98
  this.setAttribute('name', name.toLowerCase());
@@ -100,10 +101,8 @@ class HtmlToken extends (0, attributesParent_1.attributesParent)((0, fixed_1.fix
100
101
  this.#tag = name;
101
102
  }
102
103
  /** @private */
103
- toString(omit) {
104
- return omit && this.matchesTypes(omit)
105
- ? ''
106
- : `<${this.closing ? '/' : ''}${this.#tag}${super.toString(omit)}${this.selfClosing ? '/' : ''}>`;
104
+ toString() {
105
+ return `<${this.closing ? '/' : ''}${this.#tag}${super.toString()}${this.#selfClosing ? '/' : ''}>`;
107
106
  }
108
107
  /** @override */
109
108
  text() {
@@ -115,9 +114,11 @@ class HtmlToken extends (0, attributesParent_1.attributesParent)((0, fixed_1.fix
115
114
  }
116
115
  /** @private */
117
116
  getAttribute(key) {
117
+ /* NOT FOR BROWSER */
118
118
  if (key === 'tag') {
119
119
  return this.#tag;
120
120
  }
121
+ /* NOT FOR BROWSER END */
121
122
  return key === 'padding'
122
123
  ? this.#tag.length + (this.closing ? 2 : 1)
123
124
  : super.getAttribute(key);
@@ -134,7 +135,7 @@ class HtmlToken extends (0, attributesParent_1.attributesParent)((0, fixed_1.fix
134
135
  refError ??= (0, lint_1.generateForSelf)(this, { start }, '');
135
136
  errors.push({
136
137
  ...refError,
137
- message: Parser.msg('HTML tag in table attributes'),
138
+ message: index_1.default.msg('HTML tag in table attributes'),
138
139
  });
139
140
  }
140
141
  try {
@@ -142,9 +143,9 @@ class HtmlToken extends (0, attributesParent_1.attributesParent)((0, fixed_1.fix
142
143
  }
143
144
  catch (e) {
144
145
  if (e instanceof SyntaxError) {
145
- const { message: errorMsg } = e;
146
+ const { message } = e;
146
147
  refError ??= (0, lint_1.generateForSelf)(this, { start }, '');
147
- const [msg] = errorMsg.split(':'), error = { ...refError, message: Parser.msg(msg) };
148
+ const [msg] = message.split(':'), error = { ...refError, message: index_1.default.msg(msg) };
148
149
  if (msg === 'unclosed tag' && !this.closest('heading-title')) {
149
150
  if (formattingTags.has(this.name)) {
150
151
  const childNodes = this.parentNode?.childNodes, i = childNodes?.indexOf(this);
@@ -169,7 +170,7 @@ class HtmlToken extends (0, attributesParent_1.attributesParent)((0, fixed_1.fix
169
170
  refError ??= (0, lint_1.generateForSelf)(this, { start }, '');
170
171
  errors.push({
171
172
  ...refError,
172
- message: Parser.msg('obsolete HTML tag'),
173
+ message: index_1.default.msg('obsolete HTML tag'),
173
174
  severity: 'warning',
174
175
  });
175
176
  }
@@ -177,7 +178,7 @@ class HtmlToken extends (0, attributesParent_1.attributesParent)((0, fixed_1.fix
177
178
  refError ??= (0, lint_1.generateForSelf)(this, { start }, '');
178
179
  errors.push({
179
180
  ...refError,
180
- message: Parser.msg('bold in section header'),
181
+ message: index_1.default.msg('bold in section header'),
181
182
  severity: 'warning',
182
183
  });
183
184
  }
@@ -267,7 +268,7 @@ class HtmlToken extends (0, attributesParent_1.attributesParent)((0, fixed_1.fix
267
268
  }
268
269
  else if (firstChild.text().trim()) {
269
270
  this.#selfClosing = false;
270
- this.after(Parser.parse(`</${this.name}>`, false, 3, this.getAttribute('config')).firstChild);
271
+ this.after(index_1.default.parse(`</${this.name}>`, false, 3, this.getAttribute('config')).firstChild);
271
272
  return;
272
273
  }
273
274
  const { childNodes } = parentNode, i = childNodes.indexOf(this), prevSiblings = childNodes.slice(0, i)
@@ -1,8 +1,8 @@
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 { Title } from '../lib/title';
5
- import type { AstNodes, AstText, AtomToken, FileToken } from '../internal';
5
+ import type { AtomToken, FileToken, AstNodes, AstText } from '../internal';
6
6
  export declare const galleryParams: Set<string>;
7
7
  /** 图片参数 */
8
8
  export declare abstract class ImageParameterToken extends Token {
@@ -5,10 +5,10 @@ const string_1 = require("../util/string");
5
5
  const lint_1 = require("../util/lint");
6
6
  const debug_1 = require("../util/debug");
7
7
  const constants_1 = require("../util/constants");
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
  exports.galleryParams = new Set(['alt', 'link', 'lang', 'page', 'caption']);
11
- function validate(key, val, config = Parser.getConfig(), halfParsed = false) {
11
+ function validate(key, val, config = index_1.default.getConfig(), halfParsed = false) {
12
12
  val = val.trim();
13
13
  let value = val.replace(/\0\d+t\x7F/gu, '').trim();
14
14
  switch (key) {
@@ -27,7 +27,7 @@ function validate(key, val, config = Parser.getConfig(), halfParsed = false) {
27
27
  else if (value.startsWith('[[') && value.endsWith(']]')) {
28
28
  value = value.slice(2, -2);
29
29
  }
30
- const title = Parser.normalizeTitle(value, 0, false, config, halfParsed, true, true);
30
+ const title = index_1.default.normalizeTitle(value, 0, false, config, halfParsed, true, true);
31
31
  return title.valid && title;
32
32
  }
33
33
  case 'lang':
@@ -41,7 +41,7 @@ function validate(key, val, config = Parser.getConfig(), halfParsed = false) {
41
41
  }
42
42
  }
43
43
  /** 图片参数 */
44
- class ImageParameterToken extends index_1.Token {
44
+ class ImageParameterToken extends index_2.Token {
45
45
  type = 'image-parameter';
46
46
  #syntax = '';
47
47
  /** 图片链接 */
@@ -69,7 +69,7 @@ class ImageParameterToken extends index_1.Token {
69
69
  const [width, height = ''] = size.split('x');
70
70
  return { width, height };
71
71
  }
72
- const token = Parser.parse(size, false, 2, this.getAttribute('config')), i = token.childNodes.findIndex(({ type, data }) => type === 'text' && data.includes('x'));
72
+ const token = index_1.default.parse(size, false, 2, this.getAttribute('config')), i = token.childNodes.findIndex(({ type, data }) => type === 'text' && data.includes('x'));
73
73
  if (i === -1) {
74
74
  return { width: size, height: '' };
75
75
  }
@@ -105,7 +105,7 @@ class ImageParameterToken extends index_1.Token {
105
105
  }
106
106
  /* NOT FOR BROWSER END */
107
107
  /** @param str 图片参数 */
108
- constructor(str, config = Parser.getConfig(), accum = []) {
108
+ constructor(str, config = index_1.default.getConfig(), accum = []) {
109
109
  let mt;
110
110
  const regexes = Object.entries(config.img).map(([syntax, param]) => [
111
111
  syntax,
@@ -142,11 +142,8 @@ class ImageParameterToken extends index_1.Token {
142
142
  }
143
143
  }
144
144
  /** @private */
145
- toString(omit) {
146
- return this.#syntax
147
- && !(omit && this.matchesTypes(omit))
148
- ? this.#syntax.replace('$1', super.toString(omit))
149
- : super.toString(omit);
145
+ toString() {
146
+ return this.#syntax ? this.#syntax.replace('$1', super.toString()) : super.toString();
150
147
  }
151
148
  /** @override */
152
149
  text() {
@@ -156,9 +153,11 @@ class ImageParameterToken extends index_1.Token {
156
153
  getAttribute(key) {
157
154
  if (key === 'plain') {
158
155
  return (this.name === 'caption');
156
+ /* NOT FOR BROWSER */
159
157
  }
160
158
  else if (key === 'syntax') {
161
159
  return this.#syntax;
160
+ /* NOT FOR BROWSER END */
162
161
  }
163
162
  return key === 'padding'
164
163
  ? Math.max(0, this.#syntax.indexOf('$1'))
@@ -239,7 +238,7 @@ class ImageParameterToken extends index_1.Token {
239
238
  this.typeError('setValue', type);
240
239
  }
241
240
  else if (value !== true) {
242
- const include = this.getAttribute('include'), config = this.getAttribute('config'), { childNodes } = Parser.parse(value, include, name === 'caption' ? undefined : 5, config);
241
+ const include = this.getAttribute('include'), config = this.getAttribute('config'), { childNodes } = index_1.default.parse(value, include, name === 'caption' ? undefined : 5, config);
243
242
  this.replaceChildren(...childNodes);
244
243
  }
245
244
  }
@@ -1,10 +1,10 @@
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 { GalleryImageToken } from './link/galleryImage';
5
5
  import { ImagemapLinkToken } from './imagemapLink';
6
6
  import type { LintError } from '../base';
7
- import type { AstNodes, AstText, AttributesToken, ExtToken } from '../internal';
7
+ import type { AstText, AttributesToken, ExtToken, AstNodes } from '../internal';
8
8
  /**
9
9
  * `<imagemap>`
10
10
  * @classdesc `{childNodes: ...NoincludeToken, GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)}`