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
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseBraces = void 0;
4
4
  const string_1 = require("../util/string");
5
5
  const constants_1 = require("../util/constants");
6
- const Parser = require("../index");
6
+ const index_1 = require("../index");
7
7
  const heading_1 = require("../src/heading");
8
8
  const transclude_1 = require("../src/transclude");
9
9
  const arg_1 = require("../src/arg");
@@ -14,7 +14,7 @@ const arg_1 = require("../src/arg");
14
14
  * @param accum
15
15
  * @throws TranscludeToken.constructor()
16
16
  */
17
- const parseBraces = (wikitext, config = Parser.getConfig(), accum = []) => {
17
+ const parseBraces = (wikitext, config = index_1.default.getConfig(), accum = []) => {
18
18
  const source = `${config.excludes?.includes('heading') ? '' : '^(\0\\d+c\x7F)*={1,6}|'}\\[\\[|\\{{2,}|-\\{(?!\\{)`, { parserFunction: [, , , subst] } = config, stack = [], closes = { '=': '\n', '{': '\\}{2,}|\\|', '-': '\\}-', '[': '\\]\\]' }, marks = new Map([['!', '!'], ['!!', '+'], ['(!', '{'], ['!)', '}'], ['!-', '-'], ['=', '~']]);
19
19
  let regex = new RegExp(source, 'gmu'), mt = regex.exec(wikitext), moreBraces = wikitext.includes('}}'), lastIndex;
20
20
  while (mt
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseCommentAndExt = void 0;
4
4
  const constants_1 = require("../util/constants");
5
- const Parser = require("../index");
5
+ const index_1 = require("../index");
6
6
  const onlyinclude_1 = require("../src/onlyinclude");
7
7
  const noinclude_1 = require("../src/nowiki/noinclude");
8
8
  const include_1 = require("../src/tagPair/include");
@@ -15,7 +15,7 @@ const comment_1 = require("../src/nowiki/comment");
15
15
  * @param accum
16
16
  * @param includeOnly 是否嵌入
17
17
  */
18
- const parseCommentAndExt = (wikitext, config = Parser.getConfig(), accum = [], includeOnly = false) => {
18
+ const parseCommentAndExt = (wikitext, config = index_1.default.getConfig(), accum = [], includeOnly = false) => {
19
19
  const onlyincludeLeft = '<onlyinclude>', onlyincludeRight = '</onlyinclude>', { length } = onlyincludeLeft;
20
20
  /** 更新`<onlyinclude>`和`</onlyinclude>`的位置 */
21
21
  const update = () => {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseConverter = void 0;
4
4
  const constants_1 = require("../util/constants");
5
- const Parser = require("../index");
5
+ const index_1 = require("../index");
6
6
  const converter_1 = require("../src/converter");
7
7
  /**
8
8
  * 解析语言变体转换
@@ -10,7 +10,7 @@ const converter_1 = require("../src/converter");
10
10
  * @param config
11
11
  * @param accum
12
12
  */
13
- const parseConverter = (text, config = Parser.getConfig(), accum = []) => {
13
+ const parseConverter = (text, config = index_1.default.getConfig(), accum = []) => {
14
14
  const regex1 = /-\{/gu, regex2 = /-\{|\}-/gu, stack = [];
15
15
  let regex = regex1, mt = regex.exec(text);
16
16
  while (mt) {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseExternalLinks = void 0;
4
4
  const string_1 = require("../util/string");
5
5
  const constants_1 = require("../util/constants");
6
- const Parser = require("../index");
6
+ const index_1 = require("../index");
7
7
  const extLink_1 = require("../src/extLink");
8
8
  /**
9
9
  * 解析外部链接
@@ -11,7 +11,7 @@ const extLink_1 = require("../src/extLink");
11
11
  * @param config
12
12
  * @param accum
13
13
  */
14
- const parseExternalLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
14
+ const parseExternalLinks = (wikitext, config = index_1.default.getConfig(), accum = []) => {
15
15
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
16
16
  /\[((?:\[[\da-f:.]+\]|[^[\]\t\n\p{Zs}])[^[\]\t\n\p{Zs}]*(?=[[\]\t\p{Zs}]|\0\d))(\p{Zs}*(?=\P{Zs}))([^\]\n]*)\]/giu;
17
17
  const regex = new RegExp(`\\[((?:(?:${config.protocol}|//)${string_1.extUrlCharFirst}|\0\\d+m\x7F)${string_1.extUrlChar}(?=[[\\]<>"\\t\\p{Zs}]|\0\\d))`
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseHrAndDoubleUnderscore = void 0;
4
4
  const constants_1 = require("../util/constants");
5
- const Parser = require("../index");
5
+ const index_1 = require("../index");
6
6
  const hr_1 = require("../src/nowiki/hr");
7
7
  const doubleUnderscore_1 = require("../src/nowiki/doubleUnderscore");
8
8
  const heading_1 = require("../src/heading");
@@ -12,7 +12,7 @@ const heading_1 = require("../src/heading");
12
12
  * @param config
13
13
  * @param accum
14
14
  */
15
- const parseHrAndDoubleUnderscore = ({ firstChild: { data }, type, name }, config = Parser.getConfig(), accum = []) => {
15
+ const parseHrAndDoubleUnderscore = ({ firstChild: { data }, type, name }, config = index_1.default.getConfig(), accum = []) => {
16
16
  const { doubleUnderscore } = config, insensitive = new Set(doubleUnderscore[0]), sensitive = new Set(doubleUnderscore[1]);
17
17
  if (type !== 'root' && (type !== 'ext-inner' || name !== 'poem')) {
18
18
  data = `\0${data}`;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseHtml = void 0;
4
4
  const constants_1 = require("../util/constants");
5
- const Parser = require("../index");
5
+ const index_1 = require("../index");
6
6
  const attributes_1 = require("../src/attributes");
7
7
  const html_1 = require("../src/html");
8
8
  /**
@@ -11,7 +11,7 @@ const html_1 = require("../src/html");
11
11
  * @param config
12
12
  * @param accum
13
13
  */
14
- const parseHtml = (wikitext, config = Parser.getConfig(), accum = []) => {
14
+ const parseHtml = (wikitext, config = index_1.default.getConfig(), accum = []) => {
15
15
  const regex = /^(\/?)([a-z][^\s/>]*)((?:\s|\/(?!>))[^>]*?)?(\/?>)([^<]*)$/iu, elements = new Set(config.html.flat()), bits = wikitext.split('<');
16
16
  let text = bits.shift();
17
17
  for (const x of bits) {
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseLinks = void 0;
4
4
  const constants_1 = require("../util/constants");
5
- const Parser = require("../index");
6
- const index_1 = require("../src/link/index");
5
+ const index_1 = require("../index");
6
+ const index_2 = require("../src/link/index");
7
7
  const file_1 = require("../src/link/file");
8
8
  const category_1 = require("../src/link/category");
9
9
  /**
@@ -12,7 +12,7 @@ const category_1 = require("../src/link/category");
12
12
  * @param config
13
13
  * @param accum
14
14
  */
15
- const parseLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
15
+ const parseLinks = (wikitext, config = index_1.default.getConfig(), accum = []) => {
16
16
  const { parseQuotes } = require('./quotes');
17
17
  const regex = /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(?:(\||\0\d+!\x7F)(.*?[^\]]))?\]\](.*)$/su, regexImg = /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(\||\0\d+!\x7F)(.*)$/su, regexExt = new RegExp(`^\\s*(?:${config.protocol}|//)`, 'iu'), bits = wikitext.split('[[');
18
18
  let s = bits.shift();
@@ -42,7 +42,9 @@ const parseLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
42
42
  s += `[[${x}`;
43
43
  continue;
44
44
  }
45
- const title = Parser.normalizeTitle(link, 0, false, config, true, true, true), { ns, interwiki, valid, } = title;
45
+ const title = index_1.default.normalizeTitle(link, 0, false, config, true, true, true), { ns, valid,
46
+ /* NOT FOR BROWSER */
47
+ interwiki, } = title;
46
48
  if (!valid) {
47
49
  s += `[[${x}`;
48
50
  continue;
@@ -77,7 +79,7 @@ const parseLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
77
79
  }
78
80
  text &&= parseQuotes(text, config, accum);
79
81
  s += `\0${accum.length}l\x7F${after}`;
80
- let SomeLinkToken = index_1.LinkToken;
82
+ let SomeLinkToken = index_2.LinkToken;
81
83
  if (!force) {
82
84
  if (!interwiki && ns === 6) {
83
85
  SomeLinkToken = file_1.FileToken;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseList = void 0;
4
4
  const constants_1 = require("../util/constants");
5
- const Parser = require("../index");
5
+ const index_1 = require("../index");
6
6
  const list_1 = require("../src/nowiki/list");
7
7
  const dd_1 = require("../src/nowiki/dd");
8
8
  /**
@@ -11,7 +11,7 @@ const dd_1 = require("../src/nowiki/dd");
11
11
  * @param config
12
12
  * @param accum
13
13
  */
14
- const parseList = (wikitext, config = Parser.getConfig(), accum = []) => {
14
+ const parseList = (wikitext, config = index_1.default.getConfig(), accum = []) => {
15
15
  const mt = /^((?:\0\d+c\x7F)*)([;:*#]+)/u.exec(wikitext);
16
16
  if (!mt) {
17
17
  return wikitext;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseMagicLinks = void 0;
4
4
  const string_1 = require("../util/string");
5
5
  const constants_1 = require("../util/constants");
6
- const Parser = require("../index");
6
+ const index_1 = require("../index");
7
7
  const magicLink_1 = require("../src/magicLink");
8
8
  /**
9
9
  * 解析自由外链
@@ -11,7 +11,7 @@ const magicLink_1 = require("../src/magicLink");
11
11
  * @param config
12
12
  * @param accum
13
13
  */
14
- const parseMagicLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
14
+ const parseMagicLinks = (wikitext, config = index_1.default.getConfig(), accum = []) => {
15
15
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
16
16
  /(^|[^\p{L}\d_])((?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])(?:[^[\]<>"\0\t\n\p{Zs}]|\0\d+c\x7F)*)/giu;
17
17
  const regex = new RegExp(`(^|[^\\p{L}\\d_])(?:${config.protocol})(${string_1.extUrlCharFirst}${string_1.extUrlChar})`, 'giu');
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseQuotes = void 0;
4
4
  const constants_1 = require("../util/constants");
5
- const Parser = require("../index");
5
+ const index_1 = require("../index");
6
6
  const quote_1 = require("../src/nowiki/quote");
7
7
  /**
8
8
  * 解析单引号
@@ -10,14 +10,14 @@ const quote_1 = require("../src/nowiki/quote");
10
10
  * @param config
11
11
  * @param accum
12
12
  */
13
- const parseQuotes = (wikitext, config = Parser.getConfig(), accum = []) => {
13
+ const parseQuotes = (wikitext, config = index_1.default.getConfig(), accum = []) => {
14
14
  const arr = wikitext.split(/('{2,})/u), { length } = arr;
15
15
  if (length === 1) {
16
16
  return wikitext;
17
17
  }
18
18
  let nBold = 0, nItalic = 0, firstSingle, firstMulti, firstSpace;
19
19
  for (let i = 1; i < length; i += 2) {
20
- const { length: len } = arr[i];
20
+ const len = arr[i].length;
21
21
  switch (len) {
22
22
  case 2:
23
23
  nItalic++;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseSelector = void 0;
4
4
  const constants_1 = require("../util/constants");
5
5
  const string_1 = require("../util/string");
6
- const Parser = require("../index");
6
+ const index_1 = require("../index");
7
7
  const simplePseudos = new Set([
8
8
  'root',
9
9
  'first-child',
@@ -152,7 +152,7 @@ const parseSelector = (selector) => {
152
152
  pushSimple(Infinity);
153
153
  const pseudos = new Set(stack.flat(2).filter((e) => typeof e === 'string' && e.startsWith(':')));
154
154
  if (pseudos.size > 0) {
155
- Parser.warn('检测到伪选择器,请确认是否需要将":"转义成"\\:"。', pseudos);
155
+ index_1.default.warn('检测到伪选择器,请确认是否需要将":"转义成"\\:"。', pseudos);
156
156
  }
157
157
  return stack;
158
158
  }
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseTable = void 0;
4
4
  const constants_1 = require("../util/constants");
5
- const Parser = require("../index");
6
- const index_1 = require("../src/index");
7
- const index_2 = require("../src/table/index");
5
+ const index_1 = require("../index");
6
+ const index_2 = require("../src/index");
7
+ const index_3 = require("../src/table/index");
8
8
  const tr_1 = require("../src/table/tr");
9
9
  const td_1 = require("../src/table/td");
10
10
  const dd_1 = require("../src/nowiki/dd");
@@ -12,14 +12,14 @@ const dd_1 = require("../src/nowiki/dd");
12
12
  * 判断是否为表格行或表格
13
13
  * @param token 表格节点
14
14
  */
15
- const isTr = (token) => token.lastChild.constructor !== index_1.Token;
15
+ const isTr = (token) => token.lastChild.constructor !== index_2.Token;
16
16
  /**
17
17
  * 解析表格,注意`tr`和`td`包含开头的换行
18
18
  * @param {Token & {firstChild: AstText}} root 根节点
19
19
  * @param config
20
20
  * @param accum
21
21
  */
22
- const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getConfig(), accum = []) => {
22
+ const parseTable = ({ firstChild: { data }, type, name }, config = index_1.default.getConfig(), accum = []) => {
23
23
  const stack = [], lines = data.split('\n');
24
24
  let out = type === 'root' || type === 'parameter-value' || type === 'ext-inner' && name === 'poem'
25
25
  ? ''
@@ -36,7 +36,7 @@ const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getCon
36
36
  }
37
37
  const { lastChild } = topToken;
38
38
  if (isTr(topToken)) {
39
- const token = new index_1.Token(str, config, accum);
39
+ const token = new index_2.Token(str, config, accum);
40
40
  token.type = 'table-inter';
41
41
  token.setAttribute('stage', 3);
42
42
  topToken.insertAt(token);
@@ -62,7 +62,7 @@ const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getCon
62
62
  }
63
63
  push(`\n${spaces}${indent && `\0${accum.length - 1}d\x7F`}${moreSpaces}\0${accum.length}b\x7F`, top);
64
64
  // @ts-expect-error abstract class
65
- stack.push(...top ? [top] : [], new index_2.TableToken(tableSyntax, attr, config, accum));
65
+ stack.push(...top ? [top] : [], new index_3.TableToken(tableSyntax, attr, config, accum));
66
66
  continue;
67
67
  }
68
68
  else if (!top) {
package/dist/src/arg.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as Parser from '../index';
1
+ import Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { AtomToken } from './atom';
4
4
  import { HiddenToken } from './hidden';
package/dist/src/arg.js CHANGED
@@ -5,15 +5,15 @@ const string_1 = require("../util/string");
5
5
  const lint_1 = require("../util/lint");
6
6
  const constants_1 = require("../util/constants");
7
7
  const debug_1 = require("../util/debug");
8
- const Parser = require("../index");
9
- const index_1 = require("./index");
8
+ const index_1 = require("../index");
9
+ const index_2 = require("./index");
10
10
  const atom_1 = require("./atom");
11
11
  const hidden_1 = require("./hidden");
12
12
  /**
13
13
  * `{{{}}}`包裹的参数
14
14
  * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
15
15
  */
16
- class ArgToken extends index_1.Token {
16
+ class ArgToken extends index_2.Token {
17
17
  type = 'arg';
18
18
  /** 预设值 */
19
19
  get default() {
@@ -25,7 +25,7 @@ class ArgToken extends index_1.Token {
25
25
  }
26
26
  /* NOT FOR BROWSER END */
27
27
  /** @param parts 以'|'分隔的各部分 */
28
- constructor(parts, config = Parser.getConfig(), accum = []) {
28
+ constructor(parts, config = index_1.default.getConfig(), accum = []) {
29
29
  super(undefined, config, accum, {
30
30
  AtomToken: 0, Token: 1, HiddenToken: '2:',
31
31
  });
@@ -43,17 +43,18 @@ class ArgToken extends index_1.Token {
43
43
  super.insertAt(token);
44
44
  }
45
45
  else {
46
- const token = new index_1.Token(parts[i], config, accum);
46
+ const token = new index_2.Token(parts[i], config, accum);
47
47
  token.type = 'arg-default';
48
48
  token.setAttribute('stage', 2);
49
49
  super.insertAt(token);
50
50
  }
51
51
  }
52
+ /* NOT FOR BROWSER */
52
53
  this.protectChildren(0);
53
54
  }
54
55
  /** @private */
55
- toString(omit) {
56
- return omit && this.matchesTypes(omit) ? '' : `{{{${super.toString(omit, '|')}}}}`;
56
+ toString() {
57
+ return `{{{${super.toString('|')}}}}`;
57
58
  }
58
59
  /** @override */
59
60
  text() {
@@ -169,7 +170,7 @@ class ArgToken extends index_1.Token {
169
170
  * @param name 新参数名
170
171
  */
171
172
  setName(name) {
172
- const { childNodes } = Parser.parse(name, this.getAttribute('include'), 2, this.getAttribute('config'));
173
+ const { childNodes } = index_1.default.parse(name, this.getAttribute('include'), 2, this.getAttribute('config'));
173
174
  this.firstChild.replaceChildren(...childNodes);
174
175
  }
175
176
  /**
@@ -181,7 +182,7 @@ class ArgToken extends index_1.Token {
181
182
  this.removeAt(1);
182
183
  return;
183
184
  }
184
- const root = Parser.parse(value, this.getAttribute('include'), undefined, this.getAttribute('config')), { childNodes: [, oldDefault] } = this;
185
+ const root = index_1.default.parse(value, this.getAttribute('include'), undefined, this.getAttribute('config')), { childNodes: [, oldDefault] } = this;
185
186
  if (oldDefault) {
186
187
  oldDefault.replaceChildren(...root.childNodes);
187
188
  }
@@ -1,4 +1,4 @@
1
- import * as Parser from '../index';
1
+ import Parser from '../index';
2
2
  import { Token } from './index';
3
3
  declare type AtomTypes = 'arg-name' | 'attr-key' | 'attr-value' | 'ext-attr-dirty' | 'html-attr-dirty' | 'table-attr-dirty' | 'converter-flag' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'invoke-function' | 'invoke-module' | 'template-name' | 'link-target' | 'param-line';
4
4
  /** 不会被继续解析的plain Token */
package/dist/src/atom.js CHANGED
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AtomToken = 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
  /** 不会被继续解析的plain Token */
9
- class AtomToken extends index_1.Token {
9
+ class AtomToken extends index_2.Token {
10
10
  /** @class */
11
- constructor(wikitext, type, config = Parser.getConfig(), accum = [], acceptable) {
11
+ constructor(wikitext, type, config = index_1.default.getConfig(), accum = [], acceptable) {
12
12
  super(wikitext, config, accum, acceptable);
13
13
  this.type = type;
14
14
  }
@@ -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';
@@ -6,10 +6,12 @@ const string_1 = require("../util/string");
6
6
  const debug_1 = require("../util/debug");
7
7
  const constants_1 = require("../util/constants");
8
8
  const fixed_1 = require("../mixin/fixed");
9
- const Parser = require("../index");
10
- const index_1 = require("./index");
9
+ const index_1 = require("../index");
10
+ const index_2 = require("./index");
11
11
  const atom_1 = require("./atom");
12
+ /* NOT FOR BROWSER */
12
13
  const stages = { 'ext-attr': 0, 'html-attr': 2, 'table-attr': 3 };
14
+ /* NOT FOR BROWSER END */
13
15
  const commonHtmlAttrs = new Set([
14
16
  'id',
15
17
  'class',
@@ -176,7 +178,7 @@ const commonHtmlAttrs = new Set([
176
178
  * 扩展和HTML标签属性
177
179
  * @classdesc `{childNodes: [AtomToken, Token|AtomToken]}`
178
180
  */
179
- class AttributeToken extends (0, fixed_1.fixedToken)(index_1.Token) {
181
+ class AttributeToken extends (0, fixed_1.fixedToken)(index_2.Token) {
180
182
  tag;
181
183
  #equal;
182
184
  #quotes;
@@ -206,13 +208,13 @@ class AttributeToken extends (0, fixed_1.fixedToken)(index_1.Token) {
206
208
  * @param value 属性值
207
209
  * @param quotes 引号
208
210
  */
209
- constructor(type, tag, key, equal = '', value, quotes = [], config = Parser.getConfig(), accum = []) {
211
+ constructor(type, tag, key, equal = '', value, quotes = [], config = index_1.default.getConfig(), accum = []) {
210
212
  const keyToken = new atom_1.AtomToken(key, 'attr-key', config, accum, {
211
213
  [type === 'ext-attr' ? 'AstText' : 'Stage-1']: ':', ArgToken: ':', TranscludeToken: ':',
212
214
  });
213
215
  let valueToken;
214
216
  if (key === 'title' || tag === 'img' && key === 'alt') {
215
- valueToken = new index_1.Token(value, config, accum, {
217
+ valueToken = new index_2.Token(value, config, accum, {
216
218
  [`Stage-${stages[type]}`]: ':', ConverterToken: ':',
217
219
  });
218
220
  valueToken.type = 'attr-value';
@@ -223,7 +225,7 @@ class AttributeToken extends (0, fixed_1.fixedToken)(index_1.Token) {
223
225
  ...config,
224
226
  excludes: [...config.excludes, 'quote', 'extLink', 'magicLink', 'list'],
225
227
  };
226
- valueToken = new index_1.Token(value, newConfig, accum, {
228
+ valueToken = new index_2.Token(value, newConfig, accum, {
227
229
  AstText: ':', LinkToken: ':', FileToken: ':', CategoryToken: ':', ConverterToken: ':',
228
230
  });
229
231
  valueToken.type = 'attr-value';
@@ -234,7 +236,7 @@ class AttributeToken extends (0, fixed_1.fixedToken)(index_1.Token) {
234
236
  ...config,
235
237
  excludes: [...config.excludes, 'heading', 'html', 'table', 'hr', 'list'],
236
238
  };
237
- valueToken = new index_1.Token(value, newConfig, accum, {
239
+ valueToken = new index_2.Token(value, newConfig, accum, {
238
240
  ArgToken: ':',
239
241
  TranscludeToken: ':',
240
242
  LinkToken: ':',
@@ -259,7 +261,9 @@ class AttributeToken extends (0, fixed_1.fixedToken)(index_1.Token) {
259
261
  this.#equal = equal;
260
262
  this.#quotes = [...quotes];
261
263
  this.tag = tag;
264
+ /* NOT FOR BROWSER */
262
265
  this.seal('tag', true);
266
+ /* NOT FOR BROWSER END */
263
267
  this.setAttribute('name', (0, string_1.removeComment)(key).trim().toLowerCase());
264
268
  }
265
269
  /** @private */
@@ -273,14 +277,9 @@ class AttributeToken extends (0, fixed_1.fixedToken)(index_1.Token) {
273
277
  this.setAttribute('name', this.firstChild.text().trim().toLowerCase());
274
278
  }
275
279
  /** @private */
276
- toString(omit) {
277
- if (omit && this.matchesTypes(omit)) {
278
- return '';
279
- }
280
+ toString() {
280
281
  const [quoteStart = '', quoteEnd = ''] = this.#quotes;
281
- return this.#equal
282
- ? `${super.toString(omit, `${this.#equal}${quoteStart}`)}${quoteEnd}`
283
- : this.firstChild.toString(omit);
282
+ return this.#equal ? `${super.toString(`${this.#equal}${quoteStart}`)}${quoteEnd}` : String(this.firstChild);
284
283
  }
285
284
  /** @override */
286
285
  text() {
@@ -297,7 +296,7 @@ class AttributeToken extends (0, fixed_1.fixedToken)(index_1.Token) {
297
296
  if (!balanced) {
298
297
  const root = this.getRootNode();
299
298
  rect = { start, ...root.posFromIndex(start) };
300
- const e = (0, lint_1.generateForChild)(lastChild, rect, Parser.msg('unclosed $1', 'quotes'), 'warning');
299
+ const e = (0, lint_1.generateForChild)(lastChild, rect, index_1.default.msg('unclosed $1', 'quotes'), 'warning');
301
300
  errors.push({
302
301
  ...e,
303
302
  startIndex: e.startIndex - 1,
@@ -394,7 +393,7 @@ class AttributeToken extends (0, fixed_1.fixedToken)(index_1.Token) {
394
393
  else if (value.includes('"') && value.includes(`'`)) {
395
394
  throw new RangeError('属性值不能同时包含单引号和双引号!');
396
395
  }
397
- const config = this.getAttribute('config'), { childNodes } = Parser.parse(value, this.getAttribute('include'), stages[this.type] + 1, config);
396
+ const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(value, this.getAttribute('include'), stages[this.type] + 1, config);
398
397
  this.lastChild.replaceChildren(...childNodes);
399
398
  if (value.includes('"')) {
400
399
  this.#quotes = [`'`, `'`];
@@ -415,7 +414,7 @@ class AttributeToken extends (0, fixed_1.fixedToken)(index_1.Token) {
415
414
  if (this.name === 'title' || this.name === 'alt' && this.tag === 'img') {
416
415
  throw new Error(`${this.name} 属性不能更名!`);
417
416
  }
418
- const config = this.getAttribute('config'), { childNodes } = Parser.parse(key, this.getAttribute('include'), stages[this.type] + 1, config);
417
+ const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(key, this.getAttribute('include'), stages[this.type] + 1, config);
419
418
  this.firstChild.replaceChildren(...childNodes);
420
419
  }
421
420
  }
@@ -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 { AttributeToken } from './attribute';
@@ -5,8 +5,8 @@ const lint_1 = require("../util/lint");
5
5
  const string_1 = require("../util/string");
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
  const atom_1 = require("./atom");
11
11
  const attribute_1 = require("./attribute");
12
12
  /* NOT FOR BROWSER */
@@ -25,7 +25,7 @@ const toDirty = (type) => `${toAttributeType(type)}-dirty`;
25
25
  * 扩展和HTML标签属性
26
26
  * @classdesc `{childNodes: ...AtomToken|AttributeToken}`
27
27
  */
28
- class AttributesToken extends index_1.Token {
28
+ class AttributesToken extends index_2.Token {
29
29
  /* NOT FOR BROWSER */
30
30
  /** getAttrs()方法的getter写法 */
31
31
  get attributes() {
@@ -73,7 +73,7 @@ class AttributesToken extends index_1.Token {
73
73
  * @param type 标签类型
74
74
  * @param name 标签名
75
75
  */
76
- constructor(attr, type, name, config = Parser.getConfig(), accum = []) {
76
+ constructor(attr, type, name, config = index_1.default.getConfig(), accum = []) {
77
77
  super(undefined, config, accum, {
78
78
  AtomToken: ':', AttributeToken: ':',
79
79
  });
@@ -172,7 +172,7 @@ class AttributesToken extends index_1.Token {
172
172
  if (duplicated.size > 0) {
173
173
  rect ??= { start, ...this.getRootNode().posFromIndex(start) };
174
174
  for (const key of duplicated) {
175
- errors.push(...attrs.get(key).map(attr => (0, lint_1.generateForChild)(attr, rect, Parser.msg('duplicated $1 attribute', key))));
175
+ errors.push(...attrs.get(key).map(attr => (0, lint_1.generateForChild)(attr, rect, index_1.default.msg('duplicated $1 attribute', key))));
176
176
  }
177
177
  }
178
178
  return errors;
@@ -195,7 +195,7 @@ class AttributesToken extends index_1.Token {
195
195
  }
196
196
  }
197
197
  if (!debug_1.Shadow.running && dirty) {
198
- Parser.warn(`${this.constructor.name}.sanitize 方法将清理无效属性!`);
198
+ index_1.default.warn(`${this.constructor.name}.sanitize 方法将清理无效属性!`);
199
199
  }
200
200
  }
201
201
  /** @override */
@@ -321,11 +321,11 @@ class AttributesToken extends index_1.Token {
321
321
  return str && type !== 'table-attrs' && !leadingRegex[type].test(str) ? ' ' : '';
322
322
  }
323
323
  /** @private */
324
- toString(omit) {
324
+ toString() {
325
325
  if (this.type === 'table-attrs') {
326
326
  (0, string_1.normalizeSpace)(this);
327
327
  }
328
- const str = super.toString(omit);
328
+ const str = super.toString();
329
329
  return `${this.#leadingSpace(str)}${str}`;
330
330
  }
331
331
  /** @private */
@@ -1,4 +1,4 @@
1
- import * as Parser from '../index';
1
+ import Parser from '../index';
2
2
  import { Token } from './index';
3
3
  import { ConverterFlagsToken } from './converterFlags';
4
4
  import { ConverterRuleToken } from './converterRule';
@@ -5,15 +5,15 @@ const string_1 = require("../util/string");
5
5
  const debug_1 = require("../util/debug");
6
6
  const constants_1 = require("../util/constants");
7
7
  const flagsParent_1 = require("../mixin/flagsParent");
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 converterFlags_1 = require("./converterFlags");
11
11
  const converterRule_1 = require("./converterRule");
12
12
  /**
13
13
  * 转换
14
14
  * @classdesc `{childNodes: [ConverterFlagsToken, ...ConverterRuleToken]}`
15
15
  */
16
- class ConverterToken extends (0, flagsParent_1.flagsParent)(index_1.Token) {
16
+ class ConverterToken extends (0, flagsParent_1.flagsParent)(index_2.Token) {
17
17
  type = 'converter';
18
18
  /* NOT FOR BROWSER */
19
19
  /** 是否不转换 */
@@ -25,7 +25,7 @@ class ConverterToken extends (0, flagsParent_1.flagsParent)(index_1.Token) {
25
25
  * @param flags 转换类型标记
26
26
  * @param rules 转换规则
27
27
  */
28
- constructor(flags, rules, config = Parser.getConfig(), accum = []) {
28
+ constructor(flags, rules, config = index_1.default.getConfig(), accum = []) {
29
29
  super(undefined, config, accum);
30
30
  // @ts-expect-error abstract class
31
31
  this.append(new converterFlags_1.ConverterFlagsToken(flags, config, accum));
@@ -41,14 +41,13 @@ class ConverterToken extends (0, flagsParent_1.flagsParent)(index_1.Token) {
41
41
  // @ts-expect-error abstract class
42
42
  ...rules.slice(1).map(rule => new converterRule_1.ConverterRuleToken(rule, true, config, accum)));
43
43
  }
44
+ /* NOT FOR BROWSER */
44
45
  this.protectChildren(0);
45
46
  }
46
47
  /** @private */
47
- toString(omit) {
48
+ toString() {
48
49
  const { childNodes: [flags, ...rules] } = this;
49
- return omit && this.matchesTypes(omit)
50
- ? ''
51
- : `-{${flags.toString(omit)}${flags.length > 0 ? '|' : ''}${rules.map(rule => rule.toString(omit)).join(';')}}-`;
50
+ return `-{${String(flags)}${flags.length > 0 ? '|' : ''}${rules.map(String).join(';')}}-`;
52
51
  }
53
52
  /** @override */
54
53
  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 { AtomToken } from './atom';
4
4
  import type { LintError } from '../base';