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,8 +5,8 @@ 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 noinclude_1 = require("./nowiki/noinclude");
11
11
  const galleryImage_1 = require("./link/galleryImage");
12
12
  const imagemapLink_1 = require("./imagemapLink");
@@ -14,7 +14,7 @@ const imagemapLink_1 = require("./imagemapLink");
14
14
  * `<imagemap>`
15
15
  * @classdesc `{childNodes: ...NoincludeToken, GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)}`
16
16
  */
17
- class ImagemapToken extends index_1.Token {
17
+ class ImagemapToken extends index_2.Token {
18
18
  type = 'ext-inner';
19
19
  /** 图片 */
20
20
  get image() {
@@ -27,7 +27,7 @@ class ImagemapToken extends index_1.Token {
27
27
  }
28
28
  /* NOT FOR BROWSER END */
29
29
  /** @param inner 标签内部wikitext */
30
- constructor(inner, config = Parser.getConfig(), accum = []) {
30
+ constructor(inner, config = index_1.default.getConfig(), accum = []) {
31
31
  super(undefined, config, accum, {
32
32
  GalleryImageToken: ':', ImagemapLinkToken: ':', SingleLineNoincludeToken: ':', AstText: ':',
33
33
  });
@@ -44,7 +44,9 @@ class ImagemapToken extends index_1.Token {
44
44
  else if (first) {
45
45
  const [file, ...options] = line.split('|'), title = this.normalizeTitle(file, 0, true);
46
46
  if (title.valid
47
+ /* NOT FOR BROWSER */
47
48
  && !title.interwiki
49
+ /* NOT FOR BROWSER END */
48
50
  && title.ns === 6) {
49
51
  // @ts-expect-error abstract class
50
52
  const token = new galleryImage_1.GalleryImageToken('imagemap', file, options.length > 0 ? options.join('|') : undefined, config, accum);
@@ -53,7 +55,9 @@ class ImagemapToken extends index_1.Token {
53
55
  continue;
54
56
  }
55
57
  else {
56
- Parser.error('<imagemap>标签内必须先包含一张合法图片!', line);
58
+ /* NOT FOR BROWSER */
59
+ index_1.default.error('<imagemap>标签内必须先包含一张合法图片!', line);
60
+ /* NOT FOR BROWSER END */
57
61
  error = true;
58
62
  }
59
63
  }
@@ -87,8 +91,8 @@ class ImagemapToken extends index_1.Token {
87
91
  }
88
92
  }
89
93
  /** @private */
90
- toString(omit) {
91
- return super.toString(omit, '\n');
94
+ toString() {
95
+ return super.toString('\n');
92
96
  }
93
97
  /** @override */
94
98
  text() {
@@ -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 { LinkToken } from './link/index';
@@ -4,16 +4,16 @@ exports.ImagemapLinkToken = void 0;
4
4
  const constants_1 = require("../util/constants");
5
5
  const fixed_1 = require("../mixin/fixed");
6
6
  const singleLine_1 = require("../mixin/singleLine");
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 noinclude_1 = require("./nowiki/noinclude");
10
- const index_2 = require("./link/index");
10
+ const index_3 = require("./link/index");
11
11
  const extLink_1 = require("./extLink");
12
12
  /**
13
13
  * `<imagemap>`内的链接
14
14
  * @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
15
15
  */
16
- class ImagemapLinkToken extends (0, fixed_1.fixedToken)((0, singleLine_1.singleLine)(index_1.Token)) {
16
+ class ImagemapLinkToken extends (0, fixed_1.fixedToken)((0, singleLine_1.singleLine)(index_2.Token)) {
17
17
  type = 'imagemap-link';
18
18
  /* NOT FOR BROWSER */
19
19
  /** 内外链接 */
@@ -29,11 +29,11 @@ class ImagemapLinkToken extends (0, fixed_1.fixedToken)((0, singleLine_1.singleL
29
29
  * @param linkStuff 内外链接
30
30
  * @param post 链接后的文本
31
31
  */
32
- constructor(pre, linkStuff, post, config = Parser.getConfig(), accum = []) {
32
+ constructor(pre, linkStuff, post, config = index_1.default.getConfig(), accum = []) {
33
33
  super(undefined, config, accum);
34
34
  this.append(pre, linkStuff.length === 2
35
35
  // @ts-expect-error abstract class
36
- ? new index_2.LinkToken(...linkStuff, config, accum)
36
+ ? new index_3.LinkToken(...linkStuff, config, accum)
37
37
  // @ts-expect-error abstract class
38
38
  : new extLink_1.ExtLinkToken(...linkStuff, config, accum),
39
39
  // @ts-expect-error abstract class
@@ -1,6 +1,6 @@
1
1
  import { BuildMethod } from '../util/constants';
2
2
  import { AstRange } from '../lib/range';
3
- import * as Parser from '../index';
3
+ import Parser from '../index';
4
4
  import { AstElement } from '../lib/element';
5
5
  import { AstText } from '../lib/text';
6
6
  import type { LintError } from '../base';
package/dist/src/index.js CHANGED
@@ -41,14 +41,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.Token = void 0;
42
42
  const assert = require("assert/strict");
43
43
  const string_1 = require("../util/string");
44
- const debug_1 = require("../util/debug");
45
44
  const constants_1 = require("../util/constants");
45
+ const debug_1 = require("../util/debug");
46
46
  const lint_1 = require("../util/lint");
47
47
  const ranges_1 = require("../lib/ranges");
48
48
  const range_1 = require("../lib/range");
49
- const Parser = require("../index");
49
+ const index_1 = require("../index");
50
50
  const element_1 = require("../lib/element");
51
51
  const text_1 = require("../lib/text");
52
+ /* NOT FOR BROWSER END */
52
53
  /**
53
54
  * 所有节点的基类
54
55
  * @classdesc `{childNodes: ...(AstText|Token)}`
@@ -78,14 +79,16 @@ class Token extends element_1.AstElement {
78
79
  }
79
80
  /* NOT FOR BROWSER END */
80
81
  /** @class */
81
- constructor(wikitext, config = Parser.getConfig(), accum = [], acceptable) {
82
+ constructor(wikitext, config = index_1.default.getConfig(), accum = [], acceptable) {
82
83
  super();
83
84
  if (typeof wikitext === 'string') {
84
85
  this.insertAt(wikitext);
85
86
  }
86
87
  this.#config = config;
87
88
  this.#accum = accum;
89
+ /* NOT FOR BROWSER */
88
90
  this.setAttribute('acceptable', acceptable);
91
+ /* NOT FOR BROWSER END */
89
92
  accum.push(this);
90
93
  }
91
94
  /** @private */
@@ -94,9 +97,11 @@ class Token extends element_1.AstElement {
94
97
  return this;
95
98
  }
96
99
  else if (this.#stage >= constants_1.MAX_STAGE) {
100
+ /* NOt FOR BROWSER */
97
101
  if (this.type === 'root') {
98
- Parser.error('已完全解析!');
102
+ index_1.default.error('已完全解析!');
99
103
  }
104
+ /* NOT FOR BROWSER END */
100
105
  return this;
101
106
  }
102
107
  switch (n) {
@@ -306,12 +311,14 @@ class Token extends element_1.AstElement {
306
311
  const root = this.getRootNode();
307
312
  return (root !== this && root.getAttribute('include'));
308
313
  }
314
+ /* NOT FOR BROWSER */
309
315
  case 'stage':
310
316
  return this.#stage;
311
317
  case 'acceptable':
312
318
  return (this.#acceptable ? { ...this.#acceptable } : undefined);
313
319
  case 'protectedChildren':
314
320
  return new ranges_1.Ranges(this.#protectedChildren);
321
+ /* NOT FOR BROWSER END */
315
322
  default:
316
323
  return super.getAttribute(key);
317
324
  }
@@ -325,6 +332,7 @@ class Token extends element_1.AstElement {
325
332
  }
326
333
  this.#stage = value;
327
334
  break;
335
+ /* NOT FOR BROWSER */
328
336
  case 'acceptable': {
329
337
  const acceptable = {};
330
338
  if (value) {
@@ -347,14 +355,16 @@ class Token extends element_1.AstElement {
347
355
  this.#acceptable = value && acceptable;
348
356
  break;
349
357
  }
358
+ /* NOT FOR BROWSER END */
350
359
  default:
351
360
  super.setAttribute(key, value);
352
361
  }
353
362
  }
354
363
  insertAt(child, i = this.length) {
355
364
  const token = typeof child === 'string' ? new text_1.AstText(child) : child;
365
+ /* NOT FOR BROWSER */
356
366
  if (!debug_1.Shadow.running && this.#acceptable) {
357
- const acceptableIndices = Object.fromEntries(Object.entries(this.#acceptable).map(([str, ranges]) => [str, ranges.applyTo(this.length + 1)])), nodesAfter = this.childNodes.slice(i), { constructor: { name: insertedName } } = token;
367
+ const acceptableIndices = Object.fromEntries(Object.entries(this.#acceptable).map(([str, ranges]) => [str, ranges.applyTo(this.length + 1)])), nodesAfter = this.childNodes.slice(i), insertedName = token.constructor.name;
358
368
  i += i < 0 ? this.length : 0;
359
369
  if (!acceptableIndices[insertedName]?.includes(i)) {
360
370
  this.constructorError(`的第 ${i} 个子节点不能为 ${insertedName}`);
@@ -363,12 +373,15 @@ class Token extends element_1.AstElement {
363
373
  this.constructorError(`插入新的第 ${i} 个子节点会破坏规定的顺序`);
364
374
  }
365
375
  }
376
+ /* NOT FOR BROWSER END */
366
377
  super.insertAt(token, i);
378
+ /* NOT FOR BROWSER */
367
379
  const e = new Event('insert', { bubbles: true });
368
380
  this.dispatchEvent(e, { type: 'insert', position: i < 0 ? i + this.length - 1 : i });
369
381
  if (token.constructor === Token && this.getAttribute('plain')) {
370
- Parser.warn('您正将一个普通节点作为另一个普通节点的子节点,请考虑要不要执行 flatten 方法。');
382
+ index_1.default.warn('您正将一个普通节点作为另一个普通节点的子节点,请考虑要不要执行 flatten 方法。');
371
383
  }
384
+ /* NOT FOR BROWSER END */
372
385
  if (token.type === 'root') {
373
386
  token.type = 'plain';
374
387
  }
@@ -383,7 +396,7 @@ class Token extends element_1.AstElement {
383
396
  * @param selfLink 是否允许selfLink
384
397
  */
385
398
  normalizeTitle(title, defaultNs = 0, halfParsed = false, decode = false, selfLink = false) {
386
- return Parser.normalizeTitle(title, defaultNs, this.#include, this.#config, halfParsed, decode, selfLink);
399
+ return index_1.default.normalizeTitle(title, defaultNs, this.#include, this.#config, halfParsed, decode, selfLink);
387
400
  }
388
401
  /* NOT FOR BROWSER */
389
402
  /** @override */
@@ -537,7 +550,7 @@ class Token extends element_1.AstElement {
537
550
  const { childNodes } = self;
538
551
  acc += self.getAttribute('padding');
539
552
  for (let i = 0; acc <= index && i < childNodes.length; i++) {
540
- const cur = childNodes[i], { length: l } = String(cur);
553
+ const cur = childNodes[i], l = String(cur).length;
541
554
  acc += l;
542
555
  if (acc > index) {
543
556
  self = cur;
@@ -597,7 +610,7 @@ class Token extends element_1.AstElement {
597
610
  * @param title 标题
598
611
  */
599
612
  isInterwiki(title) {
600
- return Parser.isInterwiki(title, this.#config);
613
+ return index_1.default.isInterwiki(title, this.#config);
601
614
  }
602
615
  /** @private */
603
616
  cloneChildNodes() {
@@ -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';
@@ -2,16 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LinkBaseToken = void 0;
4
4
  const lint_1 = require("../../util/lint");
5
- const debug_1 = require("../../util/debug");
6
5
  const constants_1 = require("../../util/constants");
7
- const Parser = require("../../index");
8
- const index_1 = require("../index");
6
+ const debug_1 = require("../../util/debug");
7
+ const index_1 = require("../../index");
8
+ const index_2 = require("../index");
9
9
  const atom_1 = require("../atom");
10
10
  /**
11
11
  * 内链
12
12
  * @classdesc `{childNodes: [AtomToken, ...Token]}`
13
13
  */
14
- class LinkBaseToken extends index_1.Token {
14
+ class LinkBaseToken extends index_2.Token {
15
+ /* NOT FOR BROWSER END */
15
16
  #bracket = true;
16
17
  #delimiter;
17
18
  #title;
@@ -38,7 +39,7 @@ class LinkBaseToken extends index_1.Token {
38
39
  * @param linkText 链接显示文字
39
40
  * @param delimiter `|`
40
41
  */
41
- constructor(link, linkText, config = Parser.getConfig(), accum = [], delimiter = '|') {
42
+ constructor(link, linkText, config = index_1.default.getConfig(), accum = [], delimiter = '|') {
42
43
  super(undefined, config, accum, {
43
44
  AtomToken: 0, Token: 1,
44
45
  });
@@ -46,7 +47,7 @@ class LinkBaseToken extends index_1.Token {
46
47
  'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '',
47
48
  }));
48
49
  if (linkText !== undefined) {
49
- const inner = new index_1.Token(linkText, config, accum, {
50
+ const inner = new index_2.Token(linkText, config, accum, {
50
51
  'Stage-5': ':', QuoteToken: ':', ConverterToken: ':',
51
52
  });
52
53
  inner.type = 'link-text';
@@ -54,15 +55,19 @@ class LinkBaseToken extends index_1.Token {
54
55
  this.insertAt(inner);
55
56
  }
56
57
  this.#delimiter = delimiter;
58
+ /* NOT FOR BROWSER */
57
59
  this.protectChildren(0);
58
60
  }
59
61
  /** @private */
60
62
  afterBuild() {
61
63
  this.#title = this.getTitle();
64
+ /* NOT FOR BROWSER */
62
65
  this.setAttribute('name', this.#title.title);
66
+ /* NOT FOR BROWSER END */
63
67
  if (this.#delimiter.includes('\0')) {
64
68
  this.#delimiter = this.buildFromStr(this.#delimiter, constants_1.BuildMethod.String);
65
69
  }
70
+ /* NOT FOR BROWSER */
66
71
  const /** @implements */ linkListener = (e, data) => {
67
72
  const { prevTarget } = e;
68
73
  if (prevTarget?.type === 'link-target') {
@@ -107,12 +112,9 @@ class LinkBaseToken extends index_1.Token {
107
112
  }
108
113
  }
109
114
  /** @private */
110
- toString(omit) {
111
- const str = super.toString(omit, this.#delimiter);
112
- return this.#bracket
113
- && !(omit && this.matchesTypes(omit))
114
- ? `[[${str}]]`
115
- : str;
115
+ toString() {
116
+ const str = super.toString(this.#delimiter);
117
+ return this.#bracket ? `[[${str}]]` : str;
116
118
  }
117
119
  /** @override */
118
120
  text() {
@@ -142,7 +144,8 @@ class LinkBaseToken extends index_1.Token {
142
144
  rect ??= { start, ...this.getRootNode().posFromIndex(start) };
143
145
  errors.push((0, lint_1.generateForChild)(target, rect, 'unnecessary URL encoding in an internal link'));
144
146
  }
145
- if ((linkType === 'link' || linkType === 'category') && linkText?.childNodes.some(({ type, data }) => type === 'text' && data.includes('|'))) {
147
+ if ((linkType === 'link' || linkType === 'category')
148
+ && linkText?.childNodes.some(({ type, data }) => type === 'text' && data.includes('|'))) {
146
149
  rect ??= { start, ...this.getRootNode().posFromIndex(start) };
147
150
  errors.push((0, lint_1.generateForChild)(linkText, rect, 'additional "|" in the link text', 'warning'));
148
151
  }
@@ -177,7 +180,7 @@ class LinkBaseToken extends index_1.Token {
177
180
  * @param link 链接目标
178
181
  */
179
182
  setTarget(link) {
180
- const config = this.getAttribute('config'), { childNodes } = Parser.parse(String(link), this.getAttribute('include'), 2, config), token = debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'link-target', config, [], {
183
+ const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(String(link), this.getAttribute('include'), 2, config), token = debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'link-target', config, [], {
181
184
  'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '',
182
185
  }));
183
186
  token.append(...childNodes);
@@ -192,7 +195,7 @@ class LinkBaseToken extends index_1.Token {
192
195
  this.childNodes[1]?.remove();
193
196
  return;
194
197
  }
195
- const root = Parser.parse(linkStr, this.getAttribute('include'), undefined, this.getAttribute('config'));
198
+ const root = index_1.default.parse(linkStr, this.getAttribute('include'), undefined, this.getAttribute('config'));
196
199
  if (this.length === 1) {
197
200
  root.type = 'link-text';
198
201
  root.setAttribute('acceptable', {
@@ -1,4 +1,4 @@
1
- import * as Parser from '../../index';
1
+ import Parser from '../../index';
2
2
  import { LinkBaseToken } from './base';
3
3
  import { ImageParameterToken } from '../imageParameter';
4
4
  import type { Title } from '../../lib/title';
@@ -5,7 +5,7 @@ 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");
8
+ const index_1 = require("../../index");
9
9
  const base_1 = require("./base");
10
10
  const imageParameter_1 = require("../imageParameter");
11
11
  const frame = new Set(['manualthumb', 'frameless', 'framed', 'thumbnail']), horizAlign = new Set(['left', 'right', 'center', 'none']), vertAlign = new Set(['baseline', 'sub', 'super', 'top', 'text-top', 'middle', 'bottom', 'text-bottom']);
@@ -89,9 +89,11 @@ class FileToken extends base_1.LinkBaseToken {
89
89
  * @param text 图片参数
90
90
  * @param delimiter `|`
91
91
  */
92
- constructor(link, text, config = Parser.getConfig(), accum = [], delimiter = '|') {
92
+ constructor(link, text, config = index_1.default.getConfig(), accum = [], delimiter = '|') {
93
93
  super(link, undefined, config, accum, delimiter);
94
+ /* NOT FOR BROWSER */
94
95
  this.setAttribute('acceptable', { AtomToken: 0, ImageParameterToken: '1:' });
96
+ /* NOT FOR BROWSER END */
95
97
  this.append(...explode('-{', '}-', '|', text).map(
96
98
  // @ts-expect-error abstract class
97
99
  part => new imageParameter_1.ImageParameterToken(part, config, accum)));
@@ -117,7 +119,7 @@ class FileToken extends base_1.LinkBaseToken {
117
119
  * @param msg 消息键
118
120
  * @param p1 替换$1
119
121
  */
120
- const generate = (msg, p1) => (arg) => (0, lint_1.generateForChild)(arg, rect, Parser.msg(`${msg} image $1 parameter`, p1));
122
+ const generate = (msg, p1) => (arg) => (0, lint_1.generateForChild)(arg, rect, index_1.default.msg(`${msg} image $1 parameter`, p1));
121
123
  for (const key of keys) {
122
124
  let relevantArgs = args.filter(({ name }) => name === key);
123
125
  if (key === 'caption') {
@@ -156,9 +158,11 @@ class FileToken extends base_1.LinkBaseToken {
156
158
  */
157
159
  #getTypedArgs(keys, type) {
158
160
  const args = this.getAllArgs().filter(({ name }) => keys.has(name));
161
+ /* NOT FOR BROWSER */
159
162
  if (args.length > 1) {
160
- Parser.warn(`图片 ${this.name} 带有 ${args.length} 个${type}参数,只有最后 1 个 ${args[0].name} 会生效!`);
163
+ index_1.default.warn(`图片 ${this.name} 带有 ${args.length} 个${type}参数,只有最后 1 个 ${args[0].name} 会生效!`);
161
164
  }
165
+ /* NOT FOR BROWSER END */
162
166
  return args;
163
167
  }
164
168
  /** 获取图片框架属性参数节点 */
@@ -244,7 +248,7 @@ class FileToken extends base_1.LinkBaseToken {
244
248
  // @ts-expect-error abstract class
245
249
  () => new imageParameter_1.ImageParameterToken(syntax.replace('$1', ''), config));
246
250
  if (free) {
247
- const { childNodes } = Parser.parse(value, this.getAttribute('include'), undefined, config);
251
+ const { childNodes } = index_1.default.parse(value, this.getAttribute('include'), undefined, config);
248
252
  parameter.replaceChildren(...childNodes);
249
253
  }
250
254
  parameter.afterBuild();
@@ -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 { Title } from '../../lib/title';
4
4
  import type { LintError } from '../../base';
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GalleryImageToken = void 0;
4
4
  const lint_1 = require("../../util/lint");
5
- const debug_1 = require("../../util/debug");
6
5
  const constants_1 = require("../../util/constants");
6
+ const debug_1 = require("../../util/debug");
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 file_1 = require("./file");
11
11
  const imageParameter_1 = require("../imageParameter");
12
12
  /** 图库图片 */
@@ -27,10 +27,10 @@ class GalleryImageToken extends (0, singleLine_1.singleLine)(file_1.FileToken) {
27
27
  * @param link 图片文件名
28
28
  * @param text 图片参数
29
29
  */
30
- constructor(type, link, text, config = Parser.getConfig(), accum = []) {
30
+ constructor(type, link, text, config = index_1.default.getConfig(), accum = []) {
31
31
  let token;
32
32
  if (text !== undefined) {
33
- token = new index_1.Token(text, config, accum);
33
+ token = new index_2.Token(text, config, accum);
34
34
  token.type = 'plain';
35
35
  for (let n = 1; n < constants_1.MAX_STAGE; n++) {
36
36
  token.parseOnce();
@@ -52,7 +52,9 @@ class GalleryImageToken extends (0, singleLine_1.singleLine)(file_1.FileToken) {
52
52
  }
53
53
  /** @override */
54
54
  lint(start = this.getAbsoluteIndex()) {
55
- const errors = super.lint(start), { interwiki, ns, } = this.getAttribute('title');
55
+ const errors = super.lint(start), { ns,
56
+ /* NOT FOR BROWSER */
57
+ interwiki, } = this.getAttribute('title');
56
58
  if (interwiki || ns !== 6) {
57
59
  errors.push((0, lint_1.generateForSelf)(this, { start }, 'invalid gallery image'));
58
60
  }
@@ -64,11 +66,13 @@ class GalleryImageToken extends (0, singleLine_1.singleLine)(file_1.FileToken) {
64
66
  */
65
67
  #setName(title) {
66
68
  this.setAttribute('title', title);
69
+ /* NOT FOR BROWSER */
67
70
  this.setAttribute('name', title.title);
68
71
  }
69
72
  /** @private */
70
73
  afterBuild() {
71
74
  this.#setName(this.getTitle());
75
+ /* NOT FOR BROWSER */
72
76
  const /** @implements */ linkListener = (e, data) => {
73
77
  const { prevTarget } = e;
74
78
  if (prevTarget?.type === 'link-target') {
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LinkToken = void 0;
4
- const constants_1 = require("../../util/constants");
5
4
  const lint_1 = require("../../util/lint");
5
+ const constants_1 = require("../../util/constants");
6
6
  const base_1 = require("./base");
7
7
  /**
8
8
  * 内链
@@ -1,7 +1,7 @@
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
- import type { AstNodes, AstText, CommentToken, IncludeToken, NoincludeToken, TranscludeToken } from '../internal';
4
+ import type { AstText, CommentToken, IncludeToken, NoincludeToken, TranscludeToken, AstNodes } from '../internal';
5
5
  export declare abstract class MagicLinkToken extends Token {
6
6
  type: 'free-ext-link' | 'ext-link-url';
7
7
  readonly childNodes: readonly (AstText | CommentToken | IncludeToken | NoincludeToken | TranscludeToken)[];
@@ -6,13 +6,13 @@ const debug_1 = require("../util/debug");
6
6
  const constants_1 = require("../util/constants");
7
7
  const string_1 = require("../util/string");
8
8
  const syntax_1 = require("../mixin/syntax");
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
  * @classdesc `{childNodes: ...AstText|CommentToken|IncludeToken|NoincludeToken}`
14
14
  */
15
- class MagicLinkToken extends (0, syntax_1.syntax)(index_1.Token) {
15
+ class MagicLinkToken extends (0, syntax_1.syntax)(index_2.Token) {
16
16
  /* NOT FOR BROWSER */
17
17
  /** 协议 */
18
18
  get protocol() {
@@ -45,11 +45,12 @@ class MagicLinkToken extends (0, syntax_1.syntax)(index_1.Token) {
45
45
  * @param url 网址
46
46
  * @param doubleSlash 是否接受"//"作为协议
47
47
  */
48
- constructor(url, doubleSlash = false, config = Parser.getConfig(), accum = []) {
48
+ constructor(url, doubleSlash = false, config = index_1.default.getConfig(), accum = []) {
49
49
  super(url, config, accum, {
50
50
  'Stage-1': '1:', '!ExtToken': '', AstText: ':', TranscludeToken: ':',
51
51
  });
52
52
  this.type = doubleSlash ? 'ext-link-url' : 'free-ext-link';
53
+ /* NOT FOR BROWSER */
53
54
  this.setAttribute('pattern', new RegExp(`^(?:${config.protocol}${doubleSlash ? '|//' : ''})`, 'iu'));
54
55
  }
55
56
  /** @override */
@@ -65,10 +66,10 @@ class MagicLinkToken extends (0, syntax_1.syntax)(index_1.Token) {
65
66
  const refError = (0, lint_1.generateForChild)(child, rect, '', 'warning');
66
67
  regexGlobal.lastIndex = 0;
67
68
  for (let mt = regexGlobal.exec(data); mt; mt = regexGlobal.exec(data)) {
68
- const { index, 0: s } = mt, lines = data.slice(0, index).split('\n'), { length: top } = lines, { length: left } = lines[lines.length - 1], startIndex = refError.startIndex + index, startLine = refError.startLine + top - 1, startCol = top === 1 ? refError.startCol + left : left;
69
+ const { index, 0: s } = mt, lines = data.slice(0, index).split('\n'), top = lines.length, left = lines[top - 1].length, startIndex = refError.startIndex + index, startLine = refError.startLine + top - 1, startCol = top === 1 ? refError.startCol + left : left;
69
70
  errors.push({
70
71
  ...refError,
71
- message: Parser.msg('$1 in URL', s.startsWith('|') ? '"|"' : 'full-width punctuation'),
72
+ message: index_1.default.msg('$1 in URL', s.startsWith('|') ? '"|"' : 'full-width punctuation'),
72
73
  startIndex,
73
74
  endIndex: startIndex + s.length,
74
75
  startLine,
@@ -128,7 +129,7 @@ class MagicLinkToken extends (0, syntax_1.syntax)(index_1.Token) {
128
129
  * @param url 含协议的网址
129
130
  */
130
131
  setTarget(url) {
131
- const { childNodes } = Parser.parse(url, this.getAttribute('include'), 2, this.getAttribute('config'));
132
+ const { childNodes } = index_1.default.parse(url, this.getAttribute('include'), 2, this.getAttribute('config'));
132
133
  this.replaceChildren(...childNodes);
133
134
  }
134
135
  /** 是否是模板或魔术字参数 */
@@ -1,4 +1,4 @@
1
- import * as Parser from '../index';
1
+ import Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { ExtToken } from './tagPair/ext';
4
4
  import { NoincludeToken } from './nowiki/noinclude';
@@ -4,8 +4,8 @@ exports.NestedToken = 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 ext_1 = require("./tagPair/ext");
10
10
  const noinclude_1 = require("./nowiki/noinclude");
11
11
  const comment_1 = require("./nowiki/comment");
@@ -13,7 +13,7 @@ const comment_1 = require("./nowiki/comment");
13
13
  * 嵌套式的扩展标签
14
14
  * @classdesc `{childNodes: ...ExtToken|NoincludeToken|CommentToken}`
15
15
  */
16
- class NestedToken extends index_1.Token {
16
+ class NestedToken extends index_2.Token {
17
17
  type = 'ext-inner';
18
18
  /* NOT FOR BROWSER */
19
19
  #tags;
@@ -22,7 +22,7 @@ class NestedToken extends index_1.Token {
22
22
  * @param regex 内层正则
23
23
  * @param tags 内层标签名
24
24
  */
25
- constructor(wikitext, regex, tags, config = Parser.getConfig(), accum = []) {
25
+ constructor(wikitext, regex, tags, config = index_1.default.getConfig(), accum = []) {
26
26
  wikitext = wikitext?.replace(regex, (comment, name, attr, inner, closing) => {
27
27
  const str = `\0${accum.length + 1}${name ? 'e' : 'c'}\x7F`;
28
28
  if (name) {
@@ -43,6 +43,7 @@ class NestedToken extends index_1.Token {
43
43
  super(wikitext, config, accum, {
44
44
  NoincludeToken: ':', ExtToken: ':',
45
45
  });
46
+ /* NOT FOR BROWSER */
46
47
  this.#tags = [...tags];
47
48
  this.#regex = regex;
48
49
  }
@@ -59,7 +60,7 @@ class NestedToken extends index_1.Token {
59
60
  return str && !/^<!--.*-->$/su.test(str);
60
61
  }).map(child => {
61
62
  rect ??= { start, ...this.getRootNode().posFromIndex(start) };
62
- return (0, lint_1.generateForChild)(child, rect, Parser.msg('invalid content in <$1>', this.name));
63
+ return (0, lint_1.generateForChild)(child, rect, index_1.default.msg('invalid content in <$1>', this.name));
63
64
  }),
64
65
  ];
65
66
  }
@@ -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 { AstText } from '../../lib/text';
4
4
  declare type NowikiTypes = 'ext-inner' | 'comment' | 'dd' | 'double-underscore' | 'hr' | 'list' | 'noinclude' | 'quote';
@@ -4,19 +4,19 @@ exports.NowikiBaseToken = void 0;
4
4
  const debug_1 = require("../../util/debug");
5
5
  const constants_1 = require("../../util/constants");
6
6
  const fixed_1 = require("../../mixin/fixed");
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
  /**
10
10
  * 纯文字Token,不会被解析
11
11
  * @classdesc `{childNodes: [AstText]}`
12
12
  */
13
- class NowikiBaseToken extends (0, fixed_1.fixedToken)(index_1.Token) {
13
+ class NowikiBaseToken extends (0, fixed_1.fixedToken)(index_2.Token) {
14
14
  /** 纯文本部分 */
15
15
  get innerText() {
16
16
  return this.firstChild.data;
17
17
  }
18
18
  /** @param wikitext default: `''` */
19
- constructor(wikitext = '', config = Parser.getConfig(), accum = []) {
19
+ constructor(wikitext = '', config = index_1.default.getConfig(), accum = []) {
20
20
  super(wikitext, config, accum);
21
21
  }
22
22
  /* NOT FOR BROWSER */
@@ -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 { LintError } from '../../base';
4
4
  import type { Token } from '../index';