wikiparser-node 1.0.0-beta.2 → 1.0.0-beta.4

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 (127) hide show
  1. package/config/minimum.json +136 -0
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +4 -4
  4. package/dist/internal.d.ts +1 -1
  5. package/dist/lib/element.d.ts +12 -8
  6. package/dist/lib/element.js +72 -57
  7. package/dist/lib/node.js +4 -5
  8. package/dist/lib/range.js +5 -8
  9. package/dist/lib/ranges.js +2 -2
  10. package/dist/lib/text.d.ts +2 -2
  11. package/dist/lib/text.js +5 -5
  12. package/dist/lib/title.d.ts +3 -2
  13. package/dist/lib/title.js +11 -10
  14. package/dist/mixin/attributesParent.js +2 -2
  15. package/dist/mixin/fixed.js +3 -3
  16. package/dist/mixin/hidden.js +2 -2
  17. package/dist/mixin/singleLine.js +4 -4
  18. package/dist/mixin/sol.js +6 -6
  19. package/dist/parser/braces.js +4 -9
  20. package/dist/parser/commentAndExt.js +24 -18
  21. package/dist/parser/converter.js +8 -7
  22. package/dist/parser/externalLinks.js +3 -4
  23. package/dist/parser/hrAndDoubleUnderscore.js +4 -7
  24. package/dist/parser/html.js +4 -7
  25. package/dist/parser/links.js +4 -5
  26. package/dist/parser/list.js +3 -6
  27. package/dist/parser/magicLinks.js +3 -3
  28. package/dist/parser/quotes.js +4 -5
  29. package/dist/parser/selector.js +4 -7
  30. package/dist/parser/table.js +6 -15
  31. package/dist/src/arg.d.ts +6 -5
  32. package/dist/src/arg.js +31 -27
  33. package/dist/src/atom.d.ts +2 -1
  34. package/dist/src/atom.js +4 -4
  35. package/dist/src/attribute.d.ts +14 -13
  36. package/dist/src/attribute.js +41 -31
  37. package/dist/src/attributes.d.ts +4 -3
  38. package/dist/src/attributes.js +15 -21
  39. package/dist/src/converter.d.ts +4 -3
  40. package/dist/src/converter.js +10 -17
  41. package/dist/src/converterFlags.d.ts +9 -8
  42. package/dist/src/converterFlags.js +14 -15
  43. package/dist/src/converterRule.d.ts +4 -3
  44. package/dist/src/converterRule.js +20 -22
  45. package/dist/src/extLink.d.ts +5 -4
  46. package/dist/src/extLink.js +16 -17
  47. package/dist/src/gallery.d.ts +7 -5
  48. package/dist/src/gallery.js +15 -19
  49. package/dist/src/heading.d.ts +12 -10
  50. package/dist/src/heading.js +17 -18
  51. package/dist/src/hidden.d.ts +4 -3
  52. package/dist/src/hidden.js +4 -4
  53. package/dist/src/html.d.ts +17 -15
  54. package/dist/src/html.js +25 -23
  55. package/dist/src/imageParameter.d.ts +5 -4
  56. package/dist/src/imageParameter.js +22 -23
  57. package/dist/src/imagemap.d.ts +7 -5
  58. package/dist/src/imagemap.js +14 -19
  59. package/dist/src/imagemapLink.d.ts +8 -7
  60. package/dist/src/imagemapLink.js +4 -8
  61. package/dist/src/index.d.ts +2 -1
  62. package/dist/src/index.js +48 -46
  63. package/dist/src/link/base.d.ts +5 -4
  64. package/dist/src/link/base.js +26 -28
  65. package/dist/src/link/category.d.ts +1 -1
  66. package/dist/src/link/category.js +3 -2
  67. package/dist/src/link/file.d.ts +5 -4
  68. package/dist/src/link/file.js +22 -20
  69. package/dist/src/link/galleryImage.d.ts +5 -5
  70. package/dist/src/link/galleryImage.js +11 -10
  71. package/dist/src/link/index.d.ts +1 -1
  72. package/dist/src/link/index.js +8 -6
  73. package/dist/src/magicLink.d.ts +3 -2
  74. package/dist/src/magicLink.js +10 -11
  75. package/dist/src/nested.d.ts +4 -2
  76. package/dist/src/nested.js +5 -9
  77. package/dist/src/nowiki/base.d.ts +6 -5
  78. package/dist/src/nowiki/base.js +4 -4
  79. package/dist/src/nowiki/comment.d.ts +6 -5
  80. package/dist/src/nowiki/comment.js +8 -10
  81. package/dist/src/nowiki/dd.d.ts +1 -1
  82. package/dist/src/nowiki/dd.js +3 -2
  83. package/dist/src/nowiki/doubleUnderscore.d.ts +8 -6
  84. package/dist/src/nowiki/doubleUnderscore.js +13 -13
  85. package/dist/src/nowiki/hr.d.ts +2 -8
  86. package/dist/src/nowiki/hr.js +4 -11
  87. package/dist/src/nowiki/index.d.ts +2 -1
  88. package/dist/src/nowiki/index.js +6 -5
  89. package/dist/src/nowiki/list.d.ts +4 -4
  90. package/dist/src/nowiki/list.js +3 -2
  91. package/dist/src/nowiki/noinclude.d.ts +2 -2
  92. package/dist/src/nowiki/noinclude.js +3 -2
  93. package/dist/src/nowiki/quote.d.ts +1 -8
  94. package/dist/src/nowiki/quote.js +25 -17
  95. package/dist/src/onlyinclude.d.ts +5 -4
  96. package/dist/src/onlyinclude.js +13 -13
  97. package/dist/src/paramTag/index.d.ts +5 -3
  98. package/dist/src/paramTag/index.js +7 -7
  99. package/dist/src/paramTag/inputbox.d.ts +3 -2
  100. package/dist/src/paramTag/inputbox.js +6 -5
  101. package/dist/src/parameter.d.ts +11 -10
  102. package/dist/src/parameter.js +29 -30
  103. package/dist/src/pre.d.ts +4 -2
  104. package/dist/src/pre.js +19 -14
  105. package/dist/src/syntax.d.ts +2 -1
  106. package/dist/src/syntax.js +7 -7
  107. package/dist/src/table/base.d.ts +6 -5
  108. package/dist/src/table/base.js +6 -8
  109. package/dist/src/table/index.d.ts +9 -8
  110. package/dist/src/table/index.js +23 -24
  111. package/dist/src/table/td.d.ts +12 -10
  112. package/dist/src/table/td.js +19 -20
  113. package/dist/src/table/tr.d.ts +3 -2
  114. package/dist/src/table/tr.js +4 -3
  115. package/dist/src/table/trBase.d.ts +3 -3
  116. package/dist/src/table/trBase.js +10 -10
  117. package/dist/src/tagPair/ext.d.ts +7 -6
  118. package/dist/src/tagPair/ext.js +5 -17
  119. package/dist/src/tagPair/include.d.ts +5 -5
  120. package/dist/src/tagPair/include.js +4 -5
  121. package/dist/src/tagPair/index.d.ts +7 -7
  122. package/dist/src/tagPair/index.js +13 -19
  123. package/dist/src/transclude.d.ts +10 -9
  124. package/dist/src/transclude.js +41 -46
  125. package/dist/util/lint.js +14 -4
  126. package/dist/util/string.js +21 -20
  127. package/package.json +11 -9
@@ -1,6 +1,6 @@
1
1
  import { LinkToken } from '.';
2
2
  /** 分类 */
3
- export declare abstract class CategoryToken extends LinkToken {
3
+ export declare class CategoryToken extends LinkToken {
4
4
  /** @browser */
5
5
  readonly type = "category";
6
6
  /** 分类排序关键字 */
@@ -2,9 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CategoryToken = void 0;
4
4
  const string_1 = require("../../util/string");
5
- const index_1 = require("../../index");
5
+ const Parser = require("../../index");
6
6
  const _1 = require(".");
7
7
  /** 分类 */
8
+ // @ts-expect-error not implementing all abstract methods
8
9
  class CategoryToken extends _1.LinkToken {
9
10
  /** @browser */
10
11
  type = 'category';
@@ -25,4 +26,4 @@ class CategoryToken extends _1.LinkToken {
25
26
  }
26
27
  }
27
28
  exports.CategoryToken = CategoryToken;
28
- index_1.default.classes['CategoryToken'] = __filename;
29
+ Parser.classes['CategoryToken'] = __filename;
@@ -1,3 +1,4 @@
1
+ import * as Parser from '../../index';
1
2
  import { LinkBaseToken } from './base';
2
3
  import { ImageParameterToken } from '../imageParameter';
3
4
  import type { Title } from '../../lib/title';
@@ -7,14 +8,14 @@ import type { Token, AtomToken } from '../../internal';
7
8
  * 图片
8
9
  * @classdesc `{childNodes: [AtomToken, ...ImageParameterToken]}`
9
10
  */
10
- export declare abstract class FileToken extends LinkBaseToken {
11
+ export declare class FileToken extends LinkBaseToken {
11
12
  #private;
12
13
  /** @browser */
13
14
  readonly type: 'file' | 'gallery-image' | 'imagemap-image';
14
15
  childNodes: [AtomToken, ...ImageParameterToken[]];
15
16
  abstract get children(): [AtomToken, ...ImageParameterToken[]];
16
- abstract get lastChild(): ImageParameterToken;
17
- abstract get lastElementChild(): ImageParameterToken;
17
+ abstract get lastChild(): AtomToken | ImageParameterToken;
18
+ abstract get lastElementChild(): AtomToken | ImageParameterToken;
18
19
  /** 图片链接 */
19
20
  get link(): string | Title;
20
21
  set link(value: string | Title);
@@ -35,7 +36,7 @@ export declare abstract class FileToken extends LinkBaseToken {
35
36
  * @param text 图片参数
36
37
  * @param delimiter `|`
37
38
  */
38
- constructor(link: string, text?: string, config?: import("../../index").Config, accum?: Token[], delimiter?: string);
39
+ constructor(link: string, text?: string, config?: Parser.Config, accum?: Token[], delimiter?: string);
39
40
  /**
40
41
  * @override
41
42
  * @browser
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FileToken = void 0;
4
4
  const string_1 = require("../../util/string");
5
5
  const lint_1 = require("../../util/lint");
6
- const index_1 = require("../../index");
6
+ const Parser = require("../../index");
7
7
  const base_1 = require("./base");
8
8
  const imageParameter_1 = require("../imageParameter");
9
9
  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']);
@@ -39,6 +39,7 @@ const explode = (start, end, separator, str) => {
39
39
  * 图片
40
40
  * @classdesc `{childNodes: [AtomToken, ...ImageParameterToken]}`
41
41
  */
42
+ // @ts-expect-error not implementing all abstract methods
42
43
  class FileToken extends base_1.LinkBaseToken {
43
44
  /** @browser */
44
45
  type = 'file';
@@ -85,12 +86,10 @@ class FileToken extends base_1.LinkBaseToken {
85
86
  * @param text 图片参数
86
87
  * @param delimiter `|`
87
88
  */
88
- constructor(link, text, config = index_1.default.getConfig(), accum = [], delimiter = '|') {
89
+ constructor(link, text, config = Parser.getConfig(), accum = [], delimiter = '|') {
89
90
  super(link, undefined, config, accum, delimiter);
90
91
  this.setAttribute('acceptable', { AtomToken: 0, ImageParameterToken: '1:' });
91
- this.append(...explode('-{', '}-', '|', text).map(
92
- // @ts-expect-error abstract class
93
- part => new imageParameter_1.ImageParameterToken(part, config, accum)));
92
+ this.append(...explode('-{', '}-', '|', text).map(part => new imageParameter_1.ImageParameterToken(part, config, accum)));
94
93
  }
95
94
  /**
96
95
  * @override
@@ -106,6 +105,12 @@ class FileToken extends base_1.LinkBaseToken {
106
105
  return errors;
107
106
  }
108
107
  const rect = { start, ...this.getRootNode().posFromIndex(start) };
108
+ /**
109
+ * 图片参数到语法错误的映射
110
+ * @param msg 消息键
111
+ * @param p1 替换$1
112
+ */
113
+ const generate = (msg, p1) => (arg) => (0, lint_1.generateForChild)(arg, rect, Parser.msg(`${msg} image $1 parameter`, p1));
109
114
  for (const key of keys) {
110
115
  let relevantArgs = args.filter(({ name }) => name === key);
111
116
  if (key === 'caption') {
@@ -115,17 +120,17 @@ class FileToken extends base_1.LinkBaseToken {
115
120
  ];
116
121
  }
117
122
  if (relevantArgs.length > 1) {
118
- errors.push(...relevantArgs.map(arg => (0, lint_1.generateForChild)(arg, rect, index_1.default.msg('duplicated image $1 parameter', key))));
123
+ errors.push(...relevantArgs.map(generate('duplicated', key)));
119
124
  }
120
125
  }
121
126
  if (frameKeys.length > 1) {
122
- errors.push(...args.filter(({ name }) => frame.has(name)).map(arg => (0, lint_1.generateForChild)(arg, rect, index_1.default.msg('conflicting image $1 parameter', 'frame'))));
127
+ errors.push(...args.filter(({ name }) => frame.has(name)).map(generate('conflicting', 'frame')));
123
128
  }
124
129
  if (horizAlignKeys.length > 1) {
125
- errors.push(...args.filter(({ name }) => horizAlign.has(name)).map(arg => (0, lint_1.generateForChild)(arg, rect, index_1.default.msg('conflicting image $1 parameter', 'horizontal-alignment'))));
130
+ errors.push(...args.filter(({ name }) => horizAlign.has(name)).map(generate('conflicting', 'horizontal-alignment')));
126
131
  }
127
132
  if (vertAlignKeys.length > 1) {
128
- errors.push(...args.filter(({ name }) => vertAlign.has(name)).map(arg => (0, lint_1.generateForChild)(arg, rect, index_1.default.msg('conflicting image $1 parameter', 'vertical-alignment'))));
133
+ errors.push(...args.filter(({ name }) => vertAlign.has(name)).map(generate('conflicting', 'vertical-alignment')));
129
134
  }
130
135
  return errors;
131
136
  }
@@ -134,8 +139,7 @@ class FileToken extends base_1.LinkBaseToken {
134
139
  * @browser
135
140
  */
136
141
  getAllArgs() {
137
- const { childNodes: [, ...args] } = this;
138
- return args;
142
+ return this.childNodes.slice(1);
139
143
  }
140
144
  /**
141
145
  * 获取指定图片参数
@@ -154,7 +158,7 @@ class FileToken extends base_1.LinkBaseToken {
154
158
  #getTypedArgs(keys, type) {
155
159
  const args = this.getAllArgs().filter(({ name }) => keys.has(name));
156
160
  if (args.length > 1) {
157
- index_1.default.warn(`图片 ${this.name} 带有 ${args.length} 个${type}参数,只有最后 1 个 ${args[0].name} 会生效!`);
161
+ Parser.warn(`图片 ${this.name} 带有 ${args.length} 个${type}参数,只有最后 1 个 ${args[0].name} 会生效!`);
158
162
  }
159
163
  return args;
160
164
  }
@@ -249,21 +253,19 @@ class FileToken extends base_1.LinkBaseToken {
249
253
  if (syntax.includes('$1')) {
250
254
  this.typeError('setValue', 'Boolean');
251
255
  }
252
- // @ts-expect-error abstract class
253
- const newArg = index_1.default.run(() => new imageParameter_1.ImageParameterToken(syntax, config));
254
- this.insertAt(newArg);
256
+ this.insertAt(Parser.run(() => new imageParameter_1.ImageParameterToken(syntax, config)));
255
257
  return;
256
258
  }
257
- const wikitext = `[[File:F|${syntax ? syntax.replace('$1', value) : value}]]`, root = index_1.default.parse(wikitext, this.getAttribute('include'), 6, config), { length, firstChild: file } = root;
259
+ const wikitext = `[[File:F|${syntax ? syntax.replace('$1', value) : value}]]`, root = Parser.parse(wikitext, this.getAttribute('include'), 6, config), { length, firstChild: file } = root;
258
260
  if (length !== 1 || file.type !== 'file' || file.length !== 2) {
259
261
  throw new SyntaxError(`非法的 ${key} 参数:${(0, string_1.noWrap)(value)}`);
260
262
  }
261
263
  const { name, lastChild: imageParameter } = file;
262
- if (name === 'File:F' && imageParameter.name === key) {
263
- this.insertAt(imageParameter);
264
+ if (name !== 'File:F' || imageParameter.name !== key) {
265
+ throw new SyntaxError(`非法的 ${key} 参数:${(0, string_1.noWrap)(value)}`);
264
266
  }
265
- throw new SyntaxError(`非法的 ${key} 参数:${(0, string_1.noWrap)(value)}`);
267
+ this.insertAt(imageParameter);
266
268
  }
267
269
  }
268
270
  exports.FileToken = FileToken;
269
- index_1.default.classes['FileToken'] = __filename;
271
+ Parser.classes['FileToken'] = __filename;
@@ -1,15 +1,15 @@
1
+ import * as Parser from '../../index';
1
2
  import { Token } from '..';
2
- import { FileToken } from './file';
3
3
  import type { Title } from '../../lib/title';
4
4
  import type { LintError } from '../../index';
5
5
  declare const GalleryImageToken_base: (abstract new (...args: any[]) => {
6
- toString(selector?: string | undefined): string;
6
+ toString(omit?: Set<string> | undefined): string;
7
7
  text(): string;
8
8
  length: number;
9
9
  insertAt(token: unknown, i?: number | undefined): unknown;
10
- }) & typeof FileToken;
10
+ }) & typeof Parser.FileToken;
11
11
  /** 图库图片 */
12
- export declare abstract class GalleryImageToken extends GalleryImageToken_base {
12
+ export declare class GalleryImageToken extends GalleryImageToken_base {
13
13
  #private;
14
14
  type: 'gallery-image' | 'imagemap-image';
15
15
  /** 图片链接 */
@@ -21,7 +21,7 @@ export declare abstract class GalleryImageToken extends GalleryImageToken_base {
21
21
  * @param link 图片文件名
22
22
  * @param text 图片参数
23
23
  */
24
- constructor(type: 'gallery' | 'imagemap', link: string, text?: string, config?: import("../../index").Config, accum?: Token[]);
24
+ constructor(type: 'gallery' | 'imagemap', link: string, text?: string, config?: Parser.Config, accum?: Token[]);
25
25
  /**
26
26
  * @override
27
27
  * @browser
@@ -4,10 +4,11 @@ exports.GalleryImageToken = void 0;
4
4
  const lint_1 = require("../../util/lint");
5
5
  const debug_1 = require("../../util/debug");
6
6
  const singleLine_1 = require("../../mixin/singleLine");
7
- const index_1 = require("../../index");
7
+ const Parser = require("../../index");
8
8
  const __1 = require("..");
9
9
  const file_1 = require("./file");
10
10
  /** 图库图片 */
11
+ // @ts-expect-error not implementing all abstract methods
11
12
  class GalleryImageToken extends (0, singleLine_1.singleLine)(file_1.FileToken) {
12
13
  /** @browser */
13
14
  #invalid = false;
@@ -26,12 +27,12 @@ class GalleryImageToken extends (0, singleLine_1.singleLine)(file_1.FileToken) {
26
27
  * @param link 图片文件名
27
28
  * @param text 图片参数
28
29
  */
29
- constructor(type, link, text, config = index_1.default.getConfig(), accum = []) {
30
+ constructor(type, link, text, config = Parser.getConfig(), accum = []) {
30
31
  let token;
31
32
  if (text !== undefined) {
32
33
  token = new __1.Token(text, config, true, accum);
33
34
  token.type = 'plain';
34
- for (let n = 1; n < index_1.default.MAX_STAGE; n++) {
35
+ for (let n = 1; n < Parser.MAX_STAGE; n++) {
35
36
  token.parseOnce();
36
37
  }
37
38
  accum.splice(accum.indexOf(token), 1);
@@ -83,18 +84,18 @@ class GalleryImageToken extends (0, singleLine_1.singleLine)(file_1.FileToken) {
83
84
  * @throws `SyntaxError` 非法的链接目标
84
85
  */
85
86
  setTarget(link) {
86
- const include = this.getAttribute('include'), config = this.getAttribute('config'), root = index_1.default.parse(`<gallery>${link}</gallery>`, include, 1, config), { length, firstChild: ext } = root;
87
+ const include = this.getAttribute('include'), config = this.getAttribute('config'), root = Parser.parse(`<gallery>${link}</gallery>`, include, 1, config), { length, firstChild: ext } = root;
87
88
  if (length !== 1 || ext.type !== 'ext') {
88
89
  throw new SyntaxError(`非法的图库文件名:${link}`);
89
90
  }
90
91
  const { lastChild: gallery } = ext, { firstChild: image } = gallery;
91
- if (gallery.length === 1 && image.type === 'gallery-image') {
92
- const { firstChild } = image;
93
- image.destroy();
94
- this.firstChild.safeReplaceWith(firstChild);
92
+ if (gallery.length !== 1 || image.type !== 'gallery-image') {
93
+ throw new SyntaxError(`非法的图库文件名:${link}`);
95
94
  }
96
- throw new SyntaxError(`非法的图库文件名:${link}`);
95
+ const { firstChild } = image;
96
+ image.destroy();
97
+ this.firstChild.safeReplaceWith(firstChild);
97
98
  }
98
99
  }
99
100
  exports.GalleryImageToken = GalleryImageToken;
100
- index_1.default.classes['GalleryImageToken'] = __filename;
101
+ Parser.classes['GalleryImageToken'] = __filename;
@@ -5,7 +5,7 @@ import type { Token, AtomToken } from '../../internal';
5
5
  * 内链
6
6
  * @classdesc `{childNodes: [AtomToken, ?Token]}`
7
7
  */
8
- export declare abstract class LinkToken extends LinkBaseToken {
8
+ export declare class LinkToken extends LinkBaseToken {
9
9
  #private;
10
10
  /** @browser */
11
11
  readonly type: 'link' | 'category';
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LinkToken = void 0;
4
- const index_1 = require("../../index");
4
+ const Parser = require("../../index");
5
5
  const base_1 = require("./base");
6
6
  /**
7
7
  * 内链
8
8
  * @classdesc `{childNodes: [AtomToken, ?Token]}`
9
9
  */
10
+ // @ts-expect-error not implementing all abstract methods
10
11
  class LinkToken extends base_1.LinkBaseToken {
11
12
  /** @browser */
12
13
  type = 'link';
@@ -55,7 +56,7 @@ class LinkToken extends base_1.LinkBaseToken {
55
56
  else if (char === ':') {
56
57
  strLink = strLink.slice(1);
57
58
  }
58
- const config = this.getAttribute('config'), include = this.getAttribute('include'), root = index_1.default.parse(`[[${lang}:${strLink}]]`, include, 6, config), { length, firstChild: wikiLink } = root;
59
+ const config = this.getAttribute('config'), include = this.getAttribute('include'), root = Parser.parse(`[[${lang}:${strLink}]]`, include, 6, config), { length, firstChild: wikiLink } = root;
59
60
  if (length !== 1 || !(wikiLink instanceof LinkToken) || wikiLink.length !== 1) {
60
61
  throw new SyntaxError(`非法的跨语言链接目标:${lang}:${strLink}`);
61
62
  }
@@ -73,12 +74,13 @@ class LinkToken extends base_1.LinkBaseToken {
73
74
  * @throws `SyntaxError` 非法的fragment
74
75
  */
75
76
  #setFragment(fragment, page = true) {
76
- const frag = fragment && fragment.replace(/[<>[\]#|=]/gu, p => encodeURIComponent(p)), include = this.getAttribute('include'), config = this.getAttribute('config'), root = index_1.default.parse(`[[${page ? `:${this.name}` : ''}${frag === undefined ? '' : `#${frag}`}]]`, include, 6, config), { length, firstChild: wikiLink } = root;
77
+ fragment &&= fragment.replace(/[<>[\]#|=]/gu, p => encodeURIComponent(p));
78
+ const include = this.getAttribute('include'), config = this.getAttribute('config'), root = Parser.parse(`[[${page ? `:${this.name}` : ''}${fragment === undefined ? '' : `#${fragment}`}]]`, include, 6, config), { length, firstChild: wikiLink } = root;
77
79
  if (length !== 1 || !(wikiLink instanceof LinkToken) || wikiLink.length !== 1) {
78
- throw new SyntaxError(`非法的 fragment:${frag ?? ''}`);
80
+ throw new SyntaxError(`非法的 fragment:${fragment ?? ''}`);
79
81
  }
80
82
  else if (page) {
81
- index_1.default.warn(`${this.constructor.name}.setFragment 方法会同时规范化页面名!`);
83
+ Parser.warn(`${this.constructor.name}.setFragment 方法会同时规范化页面名!`);
82
84
  }
83
85
  const { firstChild } = wikiLink;
84
86
  wikiLink.destroy();
@@ -131,4 +133,4 @@ class LinkToken extends base_1.LinkBaseToken {
131
133
  }
132
134
  }
133
135
  exports.LinkToken = LinkToken;
134
- index_1.default.classes['LinkToken'] = __filename;
136
+ Parser.classes['LinkToken'] = __filename;
@@ -1,3 +1,4 @@
1
+ import * as Parser from '../index';
1
2
  import { Token } from '.';
2
3
  import type { LintError } from '../index';
3
4
  /**
@@ -22,7 +23,7 @@ export declare class MagicLinkToken extends Token {
22
23
  * @param url 网址
23
24
  * @param doubleSlash 是否接受"//"作为协议
24
25
  */
25
- constructor(url: string | undefined, doubleSlash: boolean, config?: import("../index").Config, accum?: Token[]);
26
+ constructor(url?: string, doubleSlash?: boolean, config?: Parser.Config, accum?: Token[]);
26
27
  /**
27
28
  * @override
28
29
  * @browser
@@ -40,7 +41,7 @@ export declare class MagicLinkToken extends Token {
40
41
  * @param url 含协议的网址
41
42
  * @throws `SyntaxError` 非法的自由外链目标
42
43
  */
43
- setTarget(url: string | URL): void;
44
+ setTarget(url: string): void;
44
45
  /** 是否是模板或魔术字参数 */
45
46
  isParamValue(): boolean;
46
47
  }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MagicLinkToken = void 0;
4
4
  const lint_1 = require("../util/lint");
5
- const index_1 = require("../index");
5
+ const Parser = require("../index");
6
6
  const _1 = require(".");
7
7
  /**
8
8
  * 自由外链
@@ -43,7 +43,7 @@ class MagicLinkToken extends _1.Token {
43
43
  * @param url 网址
44
44
  * @param doubleSlash 是否接受"//"作为协议
45
45
  */
46
- constructor(url, doubleSlash, config = index_1.default.getConfig(), accum = []) {
46
+ constructor(url, doubleSlash = false, config = Parser.getConfig(), accum = []) {
47
47
  super(url, config, true, accum, {
48
48
  'Stage-1': ':', '!ExtToken': '',
49
49
  });
@@ -67,7 +67,7 @@ class MagicLinkToken extends _1.Token {
67
67
  const lines = data.slice(0, index).split('\n'), { length: top } = lines, { length: left } = lines.at(-1), startIndex = start + index, startLine = refError.startLine + top - 1, startCol = top === 1 ? refError.startCol + left : left;
68
68
  return {
69
69
  ...refError,
70
- message: index_1.default.msg('$1 in URL', s.startsWith('|') ? '"|"' : index_1.default.msg('full-width punctuation')),
70
+ message: Parser.msg('$1 in URL', s.startsWith('|') ? '"|"' : Parser.msg('full-width punctuation')),
71
71
  startIndex,
72
72
  endIndex: startIndex + s.length,
73
73
  startLine,
@@ -83,7 +83,7 @@ class MagicLinkToken extends _1.Token {
83
83
  /** @override */
84
84
  cloneNode() {
85
85
  const cloned = this.cloneChildNodes();
86
- return index_1.default.run(() => {
86
+ return Parser.run(() => {
87
87
  const token = new MagicLinkToken(undefined, this.type === 'ext-link-url', this.getAttribute('config'));
88
88
  token.append(...cloned);
89
89
  token.afterBuild();
@@ -115,17 +115,16 @@ class MagicLinkToken extends _1.Token {
115
115
  * @throws `SyntaxError` 非法的自由外链目标
116
116
  */
117
117
  setTarget(url) {
118
- const strUrl = String(url), root = index_1.default.parse(strUrl, this.getAttribute('include'), 9, this.getAttribute('config')), { length, firstChild: freeExtLink } = root;
119
- if (length === 1 && freeExtLink.type === 'free-ext-link') {
120
- this.replaceChildren(...freeExtLink.childNodes);
118
+ const root = Parser.parse(url, this.getAttribute('include'), 9, this.getAttribute('config')), { length, firstChild: freeExtLink } = root;
119
+ if (length !== 1 || freeExtLink.type !== 'free-ext-link') {
120
+ throw new SyntaxError(`非法的自由外链目标:${url}`);
121
121
  }
122
- throw new SyntaxError(`非法的自由外链目标:${strUrl}`);
122
+ this.replaceChildren(...freeExtLink.childNodes);
123
123
  }
124
124
  /** 是否是模板或魔术字参数 */
125
125
  isParamValue() {
126
- const parameter = this.closest('parameter');
127
- return parameter?.getValue() === this.text();
126
+ return this.closest('parameter')?.getValue() === this.text();
128
127
  }
129
128
  }
130
129
  exports.MagicLinkToken = MagicLinkToken;
131
- index_1.default.classes['MagicLinkToken'] = __filename;
130
+ Parser.classes['MagicLinkToken'] = __filename;
@@ -1,3 +1,4 @@
1
+ import * as Parser from '../index';
1
2
  import { Token } from '.';
2
3
  import { ExtToken } from './tagPair/ext';
3
4
  import { NoincludeToken } from './nowiki/noinclude';
@@ -8,10 +9,11 @@ import type { AttributesToken } from './attributes';
8
9
  * 嵌套式的扩展标签
9
10
  * @classdesc `{childNodes: ...ExtToken|NoincludeToken|CommentToken}`
10
11
  */
11
- export declare abstract class NestedToken extends Token {
12
+ export declare class NestedToken extends Token {
12
13
  #private;
13
14
  /** @browser */
14
15
  readonly type = "ext-inner";
16
+ name: string;
15
17
  childNodes: (ExtToken | NoincludeToken | CommentToken)[];
16
18
  abstract get children(): (ExtToken | NoincludeToken | CommentToken)[];
17
19
  abstract get firstChild(): ExtToken | NoincludeToken | CommentToken | undefined;
@@ -29,7 +31,7 @@ export declare abstract class NestedToken extends Token {
29
31
  * @param regex 内层正则
30
32
  * @param tags 内层标签名
31
33
  */
32
- constructor(wikitext: string | undefined, regex: RegExp, tags: string[], config?: import("../index").Config, accum?: Token[]);
34
+ constructor(wikitext: string | undefined, regex: RegExp, tags: string[], config?: Parser.Config, accum?: Token[]);
33
35
  /**
34
36
  * @override
35
37
  * @browser
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NestedToken = void 0;
4
4
  const lint_1 = require("../util/lint");
5
- const index_1 = require("../index");
5
+ const Parser = require("../index");
6
6
  const _1 = require(".");
7
7
  const ext_1 = require("./tagPair/ext");
8
8
  const noinclude_1 = require("./nowiki/noinclude");
@@ -21,21 +21,18 @@ class NestedToken extends _1.Token {
21
21
  * @param regex 内层正则
22
22
  * @param tags 内层标签名
23
23
  */
24
- constructor(wikitext, regex, tags, config = index_1.default.getConfig(), accum = []) {
24
+ constructor(wikitext, regex, tags, config = Parser.getConfig(), accum = []) {
25
25
  const text = wikitext?.replace(regex, (comment, name, attr, inner, closing) => {
26
26
  const str = `\0${accum.length + 1}${name ? 'e' : 'c'}\x7F`;
27
27
  if (name) {
28
- // @ts-expect-error abstract class
29
28
  new ext_1.ExtToken(name, attr, inner, closing, config, accum);
30
29
  }
31
30
  else {
32
31
  const closed = comment.endsWith('-->');
33
- // @ts-expect-error abstract class
34
32
  new comment_1.CommentToken(comment.slice(4, closed ? -3 : undefined), closed, config, accum);
35
33
  }
36
34
  return str;
37
35
  })?.replace(/(?<=^|\0\d+[ce]\x7F)[^\0]+(?=$|\0\d+[ce]\x7F)/gu, substr => {
38
- // @ts-expect-error abstract class
39
36
  new noinclude_1.NoincludeToken(substr, config, accum);
40
37
  return `\0${accum.length}c\x7F`;
41
38
  });
@@ -61,7 +58,7 @@ class NestedToken extends _1.Token {
61
58
  return str && !/^<!--.*-->$/su.test(str);
62
59
  }).map(child => {
63
60
  rect ??= { start, ...this.getRootNode().posFromIndex(start) };
64
- return (0, lint_1.generateForChild)(child, rect, index_1.default.msg('invalid content in <$1>', this.name));
61
+ return (0, lint_1.generateForChild)(child, rect, Parser.msg('invalid content in <$1>', this.name));
65
62
  }),
66
63
  ];
67
64
  }
@@ -80,8 +77,7 @@ class NestedToken extends _1.Token {
80
77
  /** @override */
81
78
  cloneNode() {
82
79
  const cloned = this.cloneChildNodes(), config = this.getAttribute('config');
83
- return index_1.default.run(() => {
84
- // @ts-expect-error abstract class
80
+ return Parser.run(() => {
85
81
  const token = new NestedToken(undefined, this.#regex, this.#tags, config);
86
82
  token.append(...cloned);
87
83
  return token;
@@ -89,4 +85,4 @@ class NestedToken extends _1.Token {
89
85
  }
90
86
  }
91
87
  exports.NestedToken = NestedToken;
92
- index_1.default.classes['NestedToken'] = __filename;
88
+ Parser.classes['NestedToken'] = __filename;
@@ -1,16 +1,17 @@
1
+ import * as Parser from '../../index';
1
2
  import { Token } from '..';
2
3
  import type { AstText } from '../../lib/text';
3
4
  declare type NowikiTypes = 'ext-inner' | 'comment' | 'dd' | 'double-underscore' | 'hr' | 'list' | 'noinclude' | 'quote';
4
5
  declare const NowikiBaseToken_base: ((abstract new (...args: any[]) => {
5
6
  removeAt(): never;
6
- insertAt(token: string, i?: number | undefined): AstText;
7
- insertAt<T extends import("../../index").AstNodes>(token: T, i?: number | undefined): T;
7
+ insertAt(token: string, i?: number | undefined): Parser.AstText;
8
+ insertAt<T extends Parser.AstNodes>(token: T, i?: number | undefined): T;
8
9
  length: number;
9
- toString(selector?: string | undefined, separator?: string | undefined): string;
10
+ toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
10
11
  text(separator?: string | undefined): string;
11
12
  }) & {
12
13
  readonly fixed: true;
13
- }) & typeof Token;
14
+ }) & typeof Parser.Token;
14
15
  /**
15
16
  * 纯文字Token,不会被解析
16
17
  * @classdesc `{childNodes: [AstText]}`
@@ -24,7 +25,7 @@ export declare abstract class NowikiBaseToken extends NowikiBaseToken_base {
24
25
  abstract get lastChild(): AstText;
25
26
  abstract get lastElementChild(): undefined;
26
27
  /** @browser */
27
- constructor(wikitext: string, config?: import("../../index").Config, accum?: Token[]);
28
+ constructor(wikitext?: string, config?: Parser.Config, accum?: Token[]);
28
29
  /** @override */
29
30
  cloneNode(this: this & {
30
31
  constructor: new (...args: any[]) => unknown;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NowikiBaseToken = void 0;
4
4
  const fixed_1 = require("../../mixin/fixed");
5
- const index_1 = require("../../index");
5
+ const Parser = require("../../index");
6
6
  const __1 = require("..");
7
7
  /**
8
8
  * 纯文字Token,不会被解析
@@ -10,12 +10,12 @@ const __1 = require("..");
10
10
  */
11
11
  class NowikiBaseToken extends (0, fixed_1.fixed)(__1.Token) {
12
12
  /** @browser */
13
- constructor(wikitext, config = index_1.default.getConfig(), accum = []) {
13
+ constructor(wikitext = '', config = Parser.getConfig(), accum = []) {
14
14
  super(wikitext, config, true, accum);
15
15
  }
16
16
  /** @override */
17
17
  cloneNode() {
18
- const { constructor, firstChild: { data }, type } = this, token = index_1.default.run(() => new constructor(data, this.getAttribute('config')));
18
+ const { constructor, firstChild: { data }, type } = this, token = Parser.run(() => new constructor(data, this.getAttribute('config')));
19
19
  token.type = type;
20
20
  return token;
21
21
  }
@@ -28,4 +28,4 @@ class NowikiBaseToken extends (0, fixed_1.fixed)(__1.Token) {
28
28
  }
29
29
  }
30
30
  exports.NowikiBaseToken = NowikiBaseToken;
31
- index_1.default.classes['NowikiBaseToken'] = __filename;
31
+ Parser.classes['NowikiBaseToken'] = __filename;
@@ -1,16 +1,17 @@
1
+ import * as Parser from '../../index';
1
2
  import { NowikiBaseToken } from './base';
2
3
  import type { LintError } from '../../index';
3
4
  import type { Token } from '..';
4
5
  declare const CommentToken_base: ((abstract new (...args: any[]) => {
5
- text(): string;
6
+ text(): string; /** 内部wikitext */
6
7
  length: number;
7
- toString(selector?: string | undefined, separator?: string | undefined): string;
8
+ toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
8
9
  insertAt(token: unknown, i?: number | undefined): unknown;
9
10
  }) & {
10
11
  readonly hidden: true;
11
12
  }) & typeof NowikiBaseToken;
12
13
  /** HTML注释,不可见 */
13
- export declare abstract class CommentToken extends CommentToken_base {
14
+ export declare class CommentToken extends CommentToken_base {
14
15
  /** @browser */
15
16
  readonly type = "comment";
16
17
  closed: boolean;
@@ -20,7 +21,7 @@ export declare abstract class CommentToken extends CommentToken_base {
20
21
  * @browser
21
22
  * @param closed 是否闭合
22
23
  */
23
- constructor(wikitext: string, closed?: boolean, config?: import("../../index").Config, accum?: Token[]);
24
+ constructor(wikitext: string, closed?: boolean, config?: Parser.Config, accum?: Token[]);
24
25
  /**
25
26
  * @override
26
27
  * @browser
@@ -35,7 +36,7 @@ export declare abstract class CommentToken extends CommentToken_base {
35
36
  * @override
36
37
  * @browser
37
38
  */
38
- toString(selector?: string): string;
39
+ toString(omit?: Set<string>): string;
39
40
  /** @override */
40
41
  cloneNode(): this;
41
42
  }
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CommentToken = void 0;
4
4
  const lint_1 = require("../../util/lint");
5
5
  const hidden_1 = require("../../mixin/hidden");
6
- const index_1 = require("../../index");
6
+ const Parser = require("../../index");
7
7
  const base_1 = require("./base");
8
8
  /** HTML注释,不可见 */
9
+ // @ts-expect-error not implementing all abstract methods
9
10
  class CommentToken extends (0, hidden_1.hidden)(base_1.NowikiBaseToken) {
10
11
  /** @browser */
11
12
  type = 'comment';
@@ -18,7 +19,7 @@ class CommentToken extends (0, hidden_1.hidden)(base_1.NowikiBaseToken) {
18
19
  * @browser
19
20
  * @param closed 是否闭合
20
21
  */
21
- constructor(wikitext, closed = true, config = index_1.default.getConfig(), accum = []) {
22
+ constructor(wikitext, closed = true, config = Parser.getConfig(), accum = []) {
22
23
  super(wikitext, config, accum);
23
24
  this.closed = closed;
24
25
  Object.defineProperty(this, 'closed', { enumerable: false });
@@ -45,20 +46,17 @@ class CommentToken extends (0, hidden_1.hidden)(base_1.NowikiBaseToken) {
45
46
  * @override
46
47
  * @browser
47
48
  */
48
- toString(selector) {
49
+ toString(omit) {
49
50
  if (!this.closed && this.nextSibling) {
50
- index_1.default.error('自动闭合HTML注释', this);
51
+ Parser.error('自动闭合HTML注释', this);
51
52
  this.closed = true;
52
53
  }
53
- return selector && this.matches(selector)
54
- ? ''
55
- : `<!--${this.firstChild.data}${this.closed ? '-->' : ''}`;
54
+ return omit && this.matchesTypes(omit) ? '' : `<!--${this.firstChild.data}${this.closed ? '-->' : ''}`;
56
55
  }
57
56
  /** @override */
58
57
  cloneNode() {
59
- // @ts-expect-error abstract class
60
- return index_1.default.run(() => new CommentToken(this.firstChild.data, this.closed, this.getAttribute('config')));
58
+ return Parser.run(() => new CommentToken(this.firstChild.data, this.closed, this.getAttribute('config')));
61
59
  }
62
60
  }
63
61
  exports.CommentToken = CommentToken;
64
- index_1.default.classes['CommentToken'] = __filename;
62
+ Parser.classes['CommentToken'] = __filename;
@@ -1,6 +1,6 @@
1
1
  import { NowikiBaseToken } from './base';
2
2
  /** `:` */
3
- export declare abstract class DdToken extends NowikiBaseToken {
3
+ export declare class DdToken extends NowikiBaseToken {
4
4
  /** @browser */
5
5
  readonly type: 'dd' | 'list';
6
6
  /** 是否包含`;` */