wikiparser-node 1.3.4 → 1.3.7-b

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 (154) hide show
  1. package/bundle/bundle.min.js +36 -0
  2. package/config/llwiki.json +1 -35
  3. package/config/moegirl.json +1 -44
  4. package/config/zhwiki.json +1 -466
  5. package/extensions/dist/base.js +68 -0
  6. package/extensions/dist/editor.js +159 -0
  7. package/extensions/dist/highlight.js +30 -0
  8. package/extensions/dist/lint.js +48 -0
  9. package/extensions/editor.css +63 -0
  10. package/extensions/ui.css +114 -0
  11. package/package.json +32 -12
  12. package/config/.schema.json +0 -172
  13. package/dist/addon/table.d.ts +0 -6
  14. package/dist/addon/table.js +0 -564
  15. package/dist/base.d.ts +0 -45
  16. package/dist/bin/toc.js +0 -18
  17. package/dist/index.d.ts +0 -31
  18. package/dist/index.js +0 -209
  19. package/dist/internal.d.ts +0 -44
  20. package/dist/lib/element.d.ts +0 -155
  21. package/dist/lib/element.js +0 -634
  22. package/dist/lib/node.d.ts +0 -146
  23. package/dist/lib/node.js +0 -419
  24. package/dist/lib/range.d.ts +0 -104
  25. package/dist/lib/range.js +0 -385
  26. package/dist/lib/ranges.d.ts +0 -26
  27. package/dist/lib/ranges.js +0 -117
  28. package/dist/lib/text.d.ts +0 -62
  29. package/dist/lib/text.js +0 -248
  30. package/dist/lib/title.d.ts +0 -38
  31. package/dist/lib/title.js +0 -162
  32. package/dist/mixin/attributesParent.js +0 -94
  33. package/dist/mixin/fixed.js +0 -32
  34. package/dist/mixin/flagsParent.js +0 -70
  35. package/dist/mixin/hidden.js +0 -26
  36. package/dist/mixin/magicLinkParent.js +0 -41
  37. package/dist/mixin/singleLine.js +0 -25
  38. package/dist/mixin/sol.js +0 -43
  39. package/dist/mixin/syntax.js +0 -56
  40. package/dist/parser/braces.js +0 -121
  41. package/dist/parser/commentAndExt.js +0 -69
  42. package/dist/parser/converter.js +0 -40
  43. package/dist/parser/externalLinks.js +0 -28
  44. package/dist/parser/hrAndDoubleUnderscore.js +0 -38
  45. package/dist/parser/html.js +0 -36
  46. package/dist/parser/links.js +0 -94
  47. package/dist/parser/list.js +0 -59
  48. package/dist/parser/magicLinks.js +0 -40
  49. package/dist/parser/quotes.js +0 -67
  50. package/dist/parser/selector.js +0 -162
  51. package/dist/parser/table.js +0 -112
  52. package/dist/src/arg.d.ts +0 -58
  53. package/dist/src/arg.js +0 -189
  54. package/dist/src/atom.d.ts +0 -12
  55. package/dist/src/atom.js +0 -27
  56. package/dist/src/attribute.d.ts +0 -87
  57. package/dist/src/attribute.js +0 -392
  58. package/dist/src/attributes.d.ts +0 -107
  59. package/dist/src/attributes.js +0 -341
  60. package/dist/src/converter.d.ts +0 -52
  61. package/dist/src/converter.js +0 -79
  62. package/dist/src/converterFlags.d.ts +0 -87
  63. package/dist/src/converterFlags.js +0 -224
  64. package/dist/src/converterRule.d.ts +0 -81
  65. package/dist/src/converterRule.js +0 -212
  66. package/dist/src/extLink.d.ts +0 -54
  67. package/dist/src/extLink.js +0 -122
  68. package/dist/src/gallery.d.ts +0 -55
  69. package/dist/src/gallery.js +0 -122
  70. package/dist/src/heading.d.ts +0 -74
  71. package/dist/src/heading.js +0 -127
  72. package/dist/src/hidden.d.ts +0 -22
  73. package/dist/src/hidden.js +0 -23
  74. package/dist/src/html.d.ts +0 -101
  75. package/dist/src/html.js +0 -227
  76. package/dist/src/imageParameter.d.ts +0 -66
  77. package/dist/src/imageParameter.js +0 -247
  78. package/dist/src/imagemap.d.ts +0 -57
  79. package/dist/src/imagemap.js +0 -148
  80. package/dist/src/imagemapLink.d.ts +0 -59
  81. package/dist/src/imagemapLink.js +0 -40
  82. package/dist/src/index.d.ts +0 -146
  83. package/dist/src/index.js +0 -777
  84. package/dist/src/link/base.d.ts +0 -52
  85. package/dist/src/link/base.js +0 -209
  86. package/dist/src/link/category.d.ts +0 -13
  87. package/dist/src/link/category.js +0 -29
  88. package/dist/src/link/file.d.ts +0 -96
  89. package/dist/src/link/file.js +0 -255
  90. package/dist/src/link/galleryImage.d.ts +0 -44
  91. package/dist/src/link/galleryImage.js +0 -106
  92. package/dist/src/link/index.d.ts +0 -53
  93. package/dist/src/link/index.js +0 -123
  94. package/dist/src/magicLink.d.ts +0 -70
  95. package/dist/src/magicLink.js +0 -147
  96. package/dist/src/nested.d.ts +0 -44
  97. package/dist/src/nested.js +0 -87
  98. package/dist/src/nowiki/base.d.ts +0 -47
  99. package/dist/src/nowiki/base.js +0 -42
  100. package/dist/src/nowiki/comment.d.ts +0 -40
  101. package/dist/src/nowiki/comment.js +0 -67
  102. package/dist/src/nowiki/dd.d.ts +0 -8
  103. package/dist/src/nowiki/dd.js +0 -25
  104. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -45
  105. package/dist/src/nowiki/doubleUnderscore.js +0 -50
  106. package/dist/src/nowiki/hr.d.ts +0 -31
  107. package/dist/src/nowiki/hr.js +0 -14
  108. package/dist/src/nowiki/index.d.ts +0 -16
  109. package/dist/src/nowiki/index.js +0 -21
  110. package/dist/src/nowiki/list.d.ts +0 -30
  111. package/dist/src/nowiki/list.js +0 -48
  112. package/dist/src/nowiki/listBase.d.ts +0 -19
  113. package/dist/src/nowiki/listBase.js +0 -12
  114. package/dist/src/nowiki/noinclude.d.ts +0 -26
  115. package/dist/src/nowiki/noinclude.js +0 -25
  116. package/dist/src/nowiki/quote.d.ts +0 -23
  117. package/dist/src/nowiki/quote.js +0 -45
  118. package/dist/src/onlyinclude.d.ts +0 -16
  119. package/dist/src/onlyinclude.js +0 -57
  120. package/dist/src/paramTag/index.d.ts +0 -37
  121. package/dist/src/paramTag/index.js +0 -68
  122. package/dist/src/paramTag/inputbox.d.ts +0 -8
  123. package/dist/src/paramTag/inputbox.js +0 -23
  124. package/dist/src/parameter.d.ts +0 -85
  125. package/dist/src/parameter.js +0 -205
  126. package/dist/src/pre.d.ts +0 -28
  127. package/dist/src/pre.js +0 -51
  128. package/dist/src/syntax.d.ts +0 -28
  129. package/dist/src/syntax.js +0 -34
  130. package/dist/src/table/base.d.ts +0 -53
  131. package/dist/src/table/base.js +0 -78
  132. package/dist/src/table/index.d.ts +0 -229
  133. package/dist/src/table/index.js +0 -379
  134. package/dist/src/table/td.d.ts +0 -104
  135. package/dist/src/table/td.js +0 -261
  136. package/dist/src/table/tr.d.ts +0 -32
  137. package/dist/src/table/tr.js +0 -56
  138. package/dist/src/table/trBase.d.ts +0 -54
  139. package/dist/src/table/trBase.js +0 -159
  140. package/dist/src/tagPair/ext.d.ts +0 -56
  141. package/dist/src/tagPair/ext.js +0 -142
  142. package/dist/src/tagPair/include.d.ts +0 -53
  143. package/dist/src/tagPair/include.js +0 -63
  144. package/dist/src/tagPair/index.d.ts +0 -48
  145. package/dist/src/tagPair/index.js +0 -93
  146. package/dist/src/transclude.d.ts +0 -167
  147. package/dist/src/transclude.js +0 -698
  148. package/dist/util/constants.js +0 -108
  149. package/dist/util/debug.js +0 -64
  150. package/dist/util/diff.js +0 -72
  151. package/dist/util/lint.js +0 -46
  152. package/dist/util/string.js +0 -61
  153. package/errors/README +0 -1
  154. package/printed/README +0 -1
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseMagicLinks = void 0;
4
- const string_1 = require("../util/string");
5
- const constants_1 = require("../util/constants");
6
- const Parser = require("../index");
7
- const magicLink_1 = require("../src/magicLink");
8
- /**
9
- * 解析自由外链
10
- * @param wikitext
11
- * @param config
12
- * @param accum
13
- */
14
- const parseMagicLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
15
- const regex = new RegExp(`(?<![\\p{L}\\d_])(?:${config.protocol})(${string_1.extUrlCharFirst}${string_1.extUrlChar})`, 'giu');
16
- return wikitext.replace(regex, (m, p1) => {
17
- let trail = '', url = m;
18
- const m2 = /&(?:lt|gt|nbsp|#x0*(?:3[ce]|a0)|#0*(?:6[02]|160));/iu.exec(url);
19
- if (m2) {
20
- trail = url.slice(m2.index);
21
- url = url.slice(0, m2.index);
22
- }
23
- const sep = new RegExp(`[,;.:!?${url.includes('(') ? '' : ')'}]+$`, 'u'), sepChars = sep.exec(url);
24
- if (sepChars) {
25
- let correction = 0;
26
- if (sepChars[0].startsWith(';') && /&(?:[a-z]+|#x[\da-f]+|#\d+)$/iu.test(url.slice(0, sepChars.index))) {
27
- correction = 1;
28
- }
29
- trail = `${url.slice(sepChars.index + correction)}${trail}`;
30
- url = url.slice(0, sepChars.index + correction);
31
- }
32
- if (trail.length >= p1.length) {
33
- return m;
34
- }
35
- new magicLink_1.MagicLinkToken(url, false, config, accum);
36
- return `\0${accum.length - 1}w\x7F${trail}`;
37
- });
38
- };
39
- exports.parseMagicLinks = parseMagicLinks;
40
- constants_1.parsers['parseMagicLinks'] = __filename;
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseQuotes = void 0;
4
- const constants_1 = require("../util/constants");
5
- const Parser = require("../index");
6
- const quote_1 = require("../src/nowiki/quote");
7
- /**
8
- * 解析单引号
9
- * @param wikitext
10
- * @param config
11
- * @param accum
12
- */
13
- const parseQuotes = (wikitext, config = Parser.getConfig(), accum = []) => {
14
- const arr = wikitext.split(/('{2,})/u), { length } = arr;
15
- if (length === 1) {
16
- return wikitext;
17
- }
18
- let nBold = 0, nItalic = 0, firstSingle, firstMulti, firstSpace;
19
- for (let i = 1; i < length; i += 2) {
20
- const { length: len } = arr[i];
21
- switch (len) {
22
- case 2:
23
- nItalic++;
24
- break;
25
- case 4:
26
- arr[i - 1] += `'`;
27
- arr[i] = `'''`;
28
- // fall through
29
- case 3:
30
- nBold++;
31
- if (firstSingle !== undefined) {
32
- break;
33
- }
34
- else if (arr[i - 1].endsWith(' ')) {
35
- if (firstMulti === undefined && firstSpace === undefined) {
36
- firstSpace = i;
37
- }
38
- }
39
- else if (arr[i - 1].at(-2) === ' ') {
40
- firstSingle = i;
41
- }
42
- else {
43
- firstMulti ??= i;
44
- }
45
- break;
46
- default:
47
- arr[i - 1] += `'`.repeat(len - 5);
48
- arr[i] = `'''''`;
49
- nItalic++;
50
- nBold++;
51
- }
52
- }
53
- if (nItalic % 2 === 1 && nBold % 2 === 1) {
54
- const i = firstSingle ?? firstMulti ?? firstSpace;
55
- if (i !== undefined) {
56
- arr[i] = `''`;
57
- arr[i - 1] += `'`;
58
- }
59
- }
60
- for (let i = 1; i < length; i += 2) {
61
- new quote_1.QuoteToken(arr[i], config, accum);
62
- arr[i] = `\0${accum.length - 1}q\x7F`;
63
- }
64
- return arr.join('');
65
- };
66
- exports.parseQuotes = parseQuotes;
67
- constants_1.parsers['parseQuotes'] = __filename;
@@ -1,162 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseSelector = void 0;
4
- const constants_1 = require("../util/constants");
5
- const Parser = require("../index");
6
- const simplePseudos = new Set([
7
- 'root',
8
- 'first-child',
9
- 'first-of-type',
10
- 'last-child',
11
- 'last-of-type',
12
- 'only-child',
13
- 'only-of-type',
14
- 'empty',
15
- 'parent',
16
- 'header',
17
- 'hidden',
18
- 'visible',
19
- 'only-whitespace',
20
- 'any-link',
21
- 'local-link',
22
- 'invalid',
23
- 'required',
24
- 'optional',
25
- ]);
26
- const complexPseudos = [
27
- 'is',
28
- 'not',
29
- 'nth-child',
30
- 'nth-of-type',
31
- 'nth-last-child',
32
- 'nth-last-of-type',
33
- 'contains',
34
- 'has',
35
- 'lang',
36
- 'regex',
37
- ];
38
- const specialChars = [
39
- ['[', '&lbrack;'],
40
- [']', '&rbrack;'],
41
- ['(', '&lpar;'],
42
- [')', '&rpar;'],
43
- ['"', '&quot;'],
44
- [`'`, '&apos;'],
45
- [':', '&colon;'],
46
- ['\\', '&bsol;'],
47
- ['&', '&amp;'],
48
- ];
49
- const pseudoRegex = new RegExp(`:(${complexPseudos.join('|')})$`, 'u'), regularRegex = /[[(,>+~]|\s+/u, attributeRegex = /^\s*(\w+)\s*(?:([~|^$*!]?=)\s*("[^"]*"|'[^']*'|[^\s[\]]+)(?:\s+(i))?\s*)?\]/u, functionRegex = /^(\s*"[^"]*"\s*|\s*'[^']*'\s*|[^()]*)\)/u, grouping = new Set([',', '>', '+', '~']), combinator = new Set(['>', '+', '~', '']);
50
- /**
51
- * 清理转义符号
52
- * @param selector
53
- */
54
- const sanitize = (selector) => {
55
- for (const [c, escaped] of specialChars) {
56
- selector = selector.replaceAll(`\\${c}`, escaped);
57
- }
58
- return selector;
59
- };
60
- /**
61
- * 还原转义符号
62
- * @param selector
63
- */
64
- const desanitize = (selector) => {
65
- for (const [c, escaped] of specialChars) {
66
- selector = selector.replaceAll(escaped, c);
67
- }
68
- return selector.trim();
69
- };
70
- /**
71
- * 去除首尾的引号
72
- * @param val 属性值或伪选择器函数的参数
73
- */
74
- const deQuote = (val) => /^(["']).*\1$/u.test(val) ? val.slice(1, -1) : val.trim();
75
- /**
76
- * 解析简单伪选择器
77
- * @param step 当前顶部
78
- * @param str 不含属性和复杂伪选择器的语句
79
- * @throws `SyntaxError` 非法的选择器
80
- */
81
- const pushSimple = (step, str) => {
82
- const pieces = str.trim().split(':'),
83
- // eslint-disable-next-line unicorn/explicit-length-check
84
- i = pieces.slice(1).findIndex(pseudo => simplePseudos.has(pseudo)) + 1 || pieces.length;
85
- if (pieces.slice(i).some(pseudo => !simplePseudos.has(pseudo))) {
86
- throw new SyntaxError(`非法的选择器!\n${str}\n可能需要将':'转义为'\\:'。`);
87
- }
88
- step.push(desanitize(pieces.slice(0, i).join(':')), ...pieces.slice(i).map(piece => `:${piece}`));
89
- };
90
- /**
91
- * 解析选择器
92
- * @param selector
93
- * @throws `SyntaxError` 非法的选择器
94
- */
95
- const parseSelector = (selector) => {
96
- selector = selector.trim();
97
- const stack = [[[]]];
98
- let sanitized = sanitize(selector), regex = regularRegex, mt = regex.exec(sanitized), [condition] = stack, [step] = condition;
99
- while (mt) {
100
- let { 0: syntax, index } = mt;
101
- if (syntax.trim() === '') {
102
- index += syntax.length;
103
- const char = sanitized[index];
104
- syntax = grouping.has(char) ? char : '';
105
- }
106
- if (syntax === ',') { // 情形1:并列
107
- pushSimple(step, sanitized.slice(0, index));
108
- condition = [[]];
109
- [step] = condition;
110
- stack.push(condition);
111
- }
112
- else if (combinator.has(syntax)) { // 情形2:关系
113
- pushSimple(step, sanitized.slice(0, index));
114
- if (!step.some(Boolean)) {
115
- throw new SyntaxError(`非法的选择器!\n${selector}\n可能需要通用选择器'*'。`);
116
- }
117
- step.relation = syntax;
118
- step = [];
119
- condition.push(step);
120
- }
121
- else if (syntax === '[') { // 情形3:属性开启
122
- pushSimple(step, sanitized.slice(0, index));
123
- regex = attributeRegex;
124
- }
125
- else if (syntax.endsWith(']')) { // 情形4:属性闭合
126
- mt[3] &&= desanitize(deQuote(mt[3]));
127
- step.push(mt.slice(1));
128
- regex = regularRegex;
129
- }
130
- else if (syntax === '(') { // 情形5:伪选择器开启
131
- const pseudoExec = pseudoRegex.exec(sanitized.slice(0, index));
132
- if (!pseudoExec) {
133
- throw new SyntaxError(`非法的选择器!\n${desanitize(sanitized)}\n请检查伪选择器是否存在。`);
134
- }
135
- pushSimple(step, sanitized.slice(0, pseudoExec.index));
136
- step.push(pseudoExec[1]); // 临时存放复杂伪选择器
137
- regex = functionRegex;
138
- }
139
- else { // 情形6:伪选择器闭合
140
- mt.push(step.pop());
141
- mt[1] &&= deQuote(mt[1]);
142
- step.push(mt.slice(1));
143
- regex = regularRegex;
144
- }
145
- sanitized = sanitized.slice(index + syntax.length);
146
- if (grouping.has(syntax)) {
147
- sanitized = sanitized.trim();
148
- }
149
- mt = regex.exec(sanitized);
150
- }
151
- if (regex === regularRegex) {
152
- pushSimple(step, sanitized);
153
- const pseudos = new Set(stack.flat(2).filter((e) => typeof e === 'string' && e.startsWith(':')));
154
- if (pseudos.size > 0) {
155
- Parser.warn('检测到伪选择器,请确认是否需要将":"转义成"\\:"。', pseudos);
156
- }
157
- return stack;
158
- }
159
- throw new SyntaxError(`非法的选择器!\n${selector}\n检测到未闭合的'${regex === attributeRegex ? '[' : '('}'`);
160
- };
161
- exports.parseSelector = parseSelector;
162
- constants_1.parsers['parseSelector'] = __filename;
@@ -1,112 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseTable = void 0;
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");
8
- const tr_1 = require("../src/table/tr");
9
- const td_1 = require("../src/table/td");
10
- const dd_1 = require("../src/nowiki/dd");
11
- /** @ignore */
12
- const isTr = (token) => token.lastChild.constructor !== index_1.Token;
13
- /**
14
- * 解析表格,注意`tr`和`td`包含开头的换行
15
- * @param {Token & {firstChild: AstText}} root 根节点
16
- * @param config
17
- * @param accum
18
- */
19
- const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getConfig(), accum = []) => {
20
- const stack = [], lines = data.split('\n');
21
- let out = type === 'root' || type === 'parameter-value' || type === 'ext-inner' && name === 'poem'
22
- ? ''
23
- : `\n${lines.shift()}`;
24
- /**
25
- * 向表格中插入纯文本
26
- * @param str 待插入的文本
27
- * @param top 当前解析的表格或表格行
28
- */
29
- const push = (str, top) => {
30
- if (!top) {
31
- out += str;
32
- return;
33
- }
34
- const { lastChild } = top;
35
- if (isTr(top)) {
36
- const token = new index_1.Token(str, config, accum);
37
- token.type = 'table-inter';
38
- token.setAttribute('stage', 3);
39
- top.insertAt(token);
40
- }
41
- else {
42
- lastChild.setText(String(lastChild) + str);
43
- }
44
- };
45
- for (const outLine of lines) {
46
- let top = stack.pop();
47
- const [spaces] = /^(?:\s|\0\d+c\x7F)*/u.exec(outLine), line = outLine.slice(spaces.length), matchesStart = /^(:*)((?:\s|\0\d+c\x7F)*)(\{\||\{(?:\0\d+c\x7F)*\0\d+!\x7F|\0\d+\{\x7F)(.*)$/u
48
- .exec(line);
49
- if (matchesStart) {
50
- while (top && top.type !== 'td') {
51
- top = stack.pop();
52
- }
53
- const [, indent, moreSpaces, tableSyntax, attr] = matchesStart;
54
- if (indent) {
55
- new dd_1.DdToken(indent, config, accum);
56
- }
57
- push(`\n${spaces}${indent && `\0${accum.length - 1}d\x7F`}${moreSpaces}\0${accum.length}b\x7F`, top);
58
- stack.push(...top ? [top] : [], new index_2.TableToken(tableSyntax, attr, config, accum));
59
- continue;
60
- }
61
- else if (!top) {
62
- out += `\n${outLine}`;
63
- continue;
64
- }
65
- // eslint-disable-next-line @stylistic/operator-linebreak
66
- const matches = /^(?:(\|\}|\0\d+!\x7F\}|\0\d+\}\x7F)|(\|-+|\0\d+!\x7F-+|\0\d+-\x7F-*)(?!-)|(!|(?:\||\0\d+!\x7F)\+?))(.*)$/u
67
- .exec(line);
68
- if (!matches) {
69
- push(`\n${outLine}`, top);
70
- stack.push(top);
71
- continue;
72
- }
73
- const [, closing, row, cell, attr] = matches;
74
- if (closing) {
75
- while (top.type !== 'table') {
76
- top = stack.pop();
77
- }
78
- top.close(`\n${spaces}${closing}`, true);
79
- push(attr, stack.at(-1));
80
- }
81
- else if (row) {
82
- if (top.type === 'td') {
83
- top = stack.pop();
84
- }
85
- if (top.type === 'tr') {
86
- top = stack.pop();
87
- }
88
- const tr = new tr_1.TrToken(`\n${spaces}${row}`, attr, config, accum);
89
- stack.push(top, tr);
90
- top.insertAt(tr);
91
- }
92
- else {
93
- if (top.type === 'td') {
94
- top = stack.pop();
95
- }
96
- const regex = cell === '!' ? /!!|(?:\||\0\d+!\x7F){2}|\0\d+\+\x7F/gu : /(?:\||\0\d+!\x7F){2}|\0\d+\+\x7F/gu;
97
- let mt = regex.exec(attr), lastIndex = 0, lastSyntax = `\n${spaces}${cell}`;
98
- while (mt) {
99
- top.insertAt(new td_1.TdToken(lastSyntax, attr.slice(lastIndex, mt.index), config, accum));
100
- ({ lastIndex } = regex);
101
- [lastSyntax] = mt;
102
- mt = regex.exec(attr);
103
- }
104
- const td = new td_1.TdToken(lastSyntax, attr.slice(lastIndex), config, accum);
105
- stack.push(top, td);
106
- top.insertAt(td);
107
- }
108
- }
109
- return out.slice(1);
110
- };
111
- exports.parseTable = parseTable;
112
- constants_1.parsers['parseTable'] = __filename;
package/dist/src/arg.d.ts DELETED
@@ -1,58 +0,0 @@
1
- import * as Parser from '../index';
2
- import { Token } from './index';
3
- import { AtomToken } from './atom';
4
- import { HiddenToken } from './hidden';
5
- import type { LintError } from '../base';
6
- /**
7
- * `{{{}}}`包裹的参数
8
- * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
9
- */
10
- export declare class ArgToken extends Token {
11
- #private;
12
- readonly type = "arg";
13
- readonly name: string;
14
- readonly childNodes: [AtomToken] | [AtomToken, Token, ...HiddenToken[]];
15
- abstract get children(): [AtomToken] | [AtomToken, Token, ...HiddenToken[]];
16
- abstract get firstChild(): AtomToken;
17
- abstract get firstElementChild(): AtomToken;
18
- abstract get lastChild(): Token;
19
- abstract get lastElementChild(): Token;
20
- /** 预设值 */
21
- get default(): string | false;
22
- set default(value: string | false);
23
- /** @param parts 以'|'分隔的各部分 */
24
- constructor(parts: readonly string[], config?: Parser.Config, accum?: Token[]);
25
- /** @override */
26
- text(): string;
27
- /** @override */
28
- lint(start?: number): LintError[];
29
- /** @override */
30
- print(): string;
31
- /** @override */
32
- cloneNode(): this;
33
- /** 移除无效部分 */
34
- removeRedundant(): void;
35
- /**
36
- * @override
37
- * @param i 移除位置
38
- */
39
- removeAt(i: number): Token;
40
- /**
41
- * @override
42
- * @param token 待插入的子节点
43
- * @param i 插入位置
44
- * @throws `RangeError` 不可插入多余子节点
45
- * @throws `TypeError` 不可插入文本节点
46
- */
47
- insertAt<T extends Token>(token: T, i?: number): T;
48
- /**
49
- * 设置参数名
50
- * @param name 新参数名
51
- */
52
- setName(name: string): void;
53
- /**
54
- * 设置预设值
55
- * @param value 预设值
56
- */
57
- setDefault(value: string | false): void;
58
- }
package/dist/src/arg.js DELETED
@@ -1,189 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArgToken = void 0;
4
- const string_1 = require("../util/string");
5
- const lint_1 = require("../util/lint");
6
- const constants_1 = require("../util/constants");
7
- const debug_1 = require("../util/debug");
8
- const Parser = require("../index");
9
- const index_1 = require("./index");
10
- const atom_1 = require("./atom");
11
- const hidden_1 = require("./hidden");
12
- /**
13
- * `{{{}}}`包裹的参数
14
- * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
15
- */
16
- class ArgToken extends index_1.Token {
17
- type = 'arg';
18
- /** 预设值 */
19
- get default() {
20
- return this.childNodes[1]?.text() ?? false;
21
- }
22
- /* NOT FOR BROWSER */
23
- set default(value) {
24
- this.setDefault(value);
25
- }
26
- /* NOT FOR BROWSER END */
27
- /** @param parts 以'|'分隔的各部分 */
28
- constructor(parts, config = Parser.getConfig(), accum = []) {
29
- super(undefined, config, accum, {
30
- AtomToken: 0, Token: 1, HiddenToken: '2:',
31
- });
32
- for (let i = 0; i < parts.length; i++) {
33
- if (i === 0) {
34
- const token = new atom_1.AtomToken(parts[i], 'arg-name', config, accum, {
35
- 'Stage-2': ':', '!HeadingToken': '',
36
- });
37
- super.insertAt(token);
38
- }
39
- else if (i > 1) {
40
- const token = new hidden_1.HiddenToken(parts[i], config, accum, {
41
- 'Stage-2': ':', '!HeadingToken': '',
42
- });
43
- super.insertAt(token);
44
- }
45
- else {
46
- const token = new index_1.Token(parts[i], config, accum);
47
- token.type = 'arg-default';
48
- token.setAttribute('stage', 2);
49
- super.insertAt(token);
50
- }
51
- }
52
- this.protectChildren(0);
53
- }
54
- /** @private */
55
- toString(omit) {
56
- return omit && this.matchesTypes(omit) ? '' : `{{{${super.toString(omit, '|')}}}}`;
57
- }
58
- /** @override */
59
- text() {
60
- return `{{{${(0, string_1.text)(this.childNodes.slice(0, 2), '|')}}}}`;
61
- }
62
- /** @private */
63
- getAttribute(key) {
64
- return key === 'padding' ? 3 : super.getAttribute(key);
65
- }
66
- /** @private */
67
- getGaps() {
68
- return 1;
69
- }
70
- /** @override */
71
- lint(start = this.getAbsoluteIndex()) {
72
- if (!this.getAttribute('include')) {
73
- return [(0, lint_1.generateForSelf)(this, { start }, 'unexpected template argument')];
74
- }
75
- const { childNodes: [argName, argDefault, ...rest] } = this, errors = argName.lint(start + 3);
76
- if (argDefault) {
77
- errors.push(...argDefault.lint(start + 4 + String(argName).length));
78
- }
79
- if (rest.length > 0) {
80
- const rect = { start, ...this.getRootNode().posFromIndex(start) };
81
- errors.push(...rest.map(child => {
82
- const error = (0, lint_1.generateForChild)(child, rect, 'invisible content inside triple braces');
83
- return {
84
- ...error,
85
- startIndex: error.startIndex - 1,
86
- startCol: error.startCol - 1,
87
- };
88
- }));
89
- }
90
- return errors;
91
- }
92
- /** @override */
93
- print() {
94
- return super.print({ pre: '{{{', post: '}}}', sep: '|' });
95
- }
96
- /* NOT FOR BROWSER */
97
- /** @override */
98
- cloneNode() {
99
- const [name, ...cloned] = this.cloneChildNodes();
100
- return debug_1.Shadow.run(() => {
101
- const token = new ArgToken([''], this.getAttribute('config'));
102
- token.firstChild.safeReplaceWith(name);
103
- token.append(...cloned);
104
- token.afterBuild();
105
- return token;
106
- });
107
- }
108
- /** 设置name */
109
- #setName() {
110
- this.setAttribute('name', this.firstChild.text().trim());
111
- }
112
- /** @private */
113
- afterBuild() {
114
- this.#setName();
115
- const /** @implements */ argListener = ({ prevTarget }) => {
116
- if (prevTarget === this.firstChild) {
117
- this.#setName();
118
- }
119
- };
120
- this.addEventListener(['remove', 'insert', 'replace', 'text'], argListener);
121
- }
122
- /** 移除无效部分 */
123
- removeRedundant() {
124
- debug_1.Shadow.run(() => {
125
- for (let i = this.length - 1; i > 1; i--) {
126
- super.removeAt(i);
127
- }
128
- });
129
- }
130
- /**
131
- * @override
132
- * @param i 移除位置
133
- */
134
- removeAt(i) {
135
- if (i === 1) {
136
- this.removeRedundant();
137
- }
138
- return super.removeAt(i);
139
- }
140
- /**
141
- * @override
142
- * @param token 待插入的子节点
143
- * @param i 插入位置
144
- * @throws `RangeError` 不可插入多余子节点
145
- * @throws `TypeError` 不可插入文本节点
146
- */
147
- insertAt(token, i = this.length) {
148
- i += i < 0 ? this.length : 0;
149
- if (i > 1) {
150
- throw new RangeError(`${this.constructor.name}不可插入多余的子节点!`);
151
- }
152
- else if (typeof token === 'string') {
153
- throw new TypeError(`${this.constructor.name}不可插入文本节点!`);
154
- }
155
- super.insertAt(token, i);
156
- if (i === 1) {
157
- token.type = 'arg-default';
158
- }
159
- return token;
160
- }
161
- /**
162
- * 设置参数名
163
- * @param name 新参数名
164
- */
165
- setName(name) {
166
- const { childNodes } = Parser.parse(name, this.getAttribute('include'), 2, this.getAttribute('config'));
167
- this.firstChild.replaceChildren(...childNodes);
168
- }
169
- /**
170
- * 设置预设值
171
- * @param value 预设值
172
- */
173
- setDefault(value) {
174
- if (value === false) {
175
- this.removeAt(1);
176
- return;
177
- }
178
- const root = Parser.parse(value, this.getAttribute('include'), undefined, this.getAttribute('config')), { childNodes: [, oldDefault] } = this;
179
- if (oldDefault) {
180
- oldDefault.replaceChildren(...root.childNodes);
181
- }
182
- else {
183
- root.type = 'arg-default';
184
- this.insertAt(root);
185
- }
186
- }
187
- }
188
- exports.ArgToken = ArgToken;
189
- constants_1.classes['ArgToken'] = __filename;
@@ -1,12 +0,0 @@
1
- import * as Parser from '../index';
2
- import { Token } from './index';
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
- /** 不会被继续解析的plain Token */
5
- export declare class AtomToken extends Token {
6
- type: AtomTypes;
7
- /** @class */
8
- constructor(wikitext: string | undefined, type: AtomTypes, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
9
- /** @override */
10
- cloneNode(): this;
11
- }
12
- export {};
package/dist/src/atom.js DELETED
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AtomToken = void 0;
4
- const debug_1 = require("../util/debug");
5
- const constants_1 = require("../util/constants");
6
- const Parser = require("../index");
7
- const index_1 = require("./index");
8
- /** 不会被继续解析的plain Token */
9
- class AtomToken extends index_1.Token {
10
- /** @class */
11
- constructor(wikitext, type, config = Parser.getConfig(), accum = [], acceptable) {
12
- super(wikitext, config, accum, acceptable);
13
- this.type = type;
14
- }
15
- /* NOT FOR BROWSER */
16
- /** @override */
17
- cloneNode() {
18
- const cloned = this.cloneChildNodes(), config = this.getAttribute('config'), acceptable = this.getAttribute('acceptable');
19
- return debug_1.Shadow.run(() => {
20
- const token = new AtomToken(undefined, this.type, config, [], acceptable);
21
- token.append(...cloned);
22
- return token;
23
- });
24
- }
25
- }
26
- exports.AtomToken = AtomToken;
27
- constants_1.classes['AtomToken'] = __filename;