wikiparser-node 1.3.4-b → 1.3.6

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/config/.schema.json +172 -0
  2. package/config/llwiki.json +35 -1
  3. package/config/moegirl.json +44 -1
  4. package/config/zhwiki.json +466 -1
  5. package/dist/addon/table.d.ts +6 -0
  6. package/dist/addon/table.js +558 -0
  7. package/dist/base.d.ts +45 -0
  8. package/dist/bin/toc.js +18 -0
  9. package/dist/index.d.ts +32 -0
  10. package/dist/index.js +209 -0
  11. package/dist/internal.d.ts +44 -0
  12. package/dist/lib/element.d.ts +154 -0
  13. package/dist/lib/element.js +625 -0
  14. package/dist/lib/node.d.ts +146 -0
  15. package/dist/lib/node.js +423 -0
  16. package/dist/lib/range.d.ts +104 -0
  17. package/dist/lib/range.js +385 -0
  18. package/dist/lib/ranges.d.ts +26 -0
  19. package/dist/lib/ranges.js +118 -0
  20. package/dist/lib/text.d.ts +62 -0
  21. package/dist/lib/text.js +247 -0
  22. package/dist/lib/title.d.ts +38 -0
  23. package/dist/lib/title.js +162 -0
  24. package/dist/mixin/attributesParent.js +89 -0
  25. package/dist/mixin/fixed.js +25 -0
  26. package/dist/mixin/flagsParent.js +70 -0
  27. package/dist/mixin/hidden.js +26 -0
  28. package/dist/mixin/magicLinkParent.js +41 -0
  29. package/dist/mixin/singleLine.js +25 -0
  30. package/dist/mixin/sol.js +43 -0
  31. package/dist/mixin/syntax.js +54 -0
  32. package/dist/parser/braces.js +128 -0
  33. package/dist/parser/commentAndExt.js +77 -0
  34. package/dist/parser/converter.js +40 -0
  35. package/dist/parser/externalLinks.js +28 -0
  36. package/dist/parser/hrAndDoubleUnderscore.js +38 -0
  37. package/dist/parser/html.js +36 -0
  38. package/dist/parser/links.js +94 -0
  39. package/dist/parser/list.js +66 -0
  40. package/dist/parser/magicLinks.js +40 -0
  41. package/dist/parser/quotes.js +67 -0
  42. package/dist/parser/selector.js +161 -0
  43. package/dist/parser/table.js +120 -0
  44. package/dist/src/arg.d.ts +56 -0
  45. package/dist/src/arg.js +187 -0
  46. package/dist/src/atom.d.ts +12 -0
  47. package/dist/src/atom.js +27 -0
  48. package/dist/src/attribute.d.ts +88 -0
  49. package/dist/src/attribute.js +392 -0
  50. package/dist/src/attributes.d.ts +109 -0
  51. package/dist/src/attributes.js +344 -0
  52. package/dist/src/converter.d.ts +53 -0
  53. package/dist/src/converter.js +79 -0
  54. package/dist/src/converterFlags.d.ts +87 -0
  55. package/dist/src/converterFlags.js +224 -0
  56. package/dist/src/converterRule.d.ts +77 -0
  57. package/dist/src/converterRule.js +208 -0
  58. package/dist/src/extLink.d.ts +55 -0
  59. package/dist/src/extLink.js +122 -0
  60. package/dist/src/gallery.d.ts +54 -0
  61. package/dist/src/gallery.js +121 -0
  62. package/dist/src/heading.d.ts +76 -0
  63. package/dist/src/heading.js +127 -0
  64. package/dist/src/hidden.d.ts +23 -0
  65. package/dist/src/hidden.js +23 -0
  66. package/dist/src/html.d.ts +104 -0
  67. package/dist/src/html.js +226 -0
  68. package/dist/src/imageParameter.d.ts +65 -0
  69. package/dist/src/imageParameter.js +245 -0
  70. package/dist/src/imagemap.d.ts +56 -0
  71. package/dist/src/imagemap.js +147 -0
  72. package/dist/src/imagemapLink.d.ts +61 -0
  73. package/dist/src/imagemapLink.js +40 -0
  74. package/dist/src/index.d.ts +139 -0
  75. package/dist/src/index.js +777 -0
  76. package/dist/src/link/base.d.ts +52 -0
  77. package/dist/src/link/base.js +209 -0
  78. package/dist/src/link/category.d.ts +13 -0
  79. package/dist/src/link/category.js +29 -0
  80. package/dist/src/link/file.d.ts +96 -0
  81. package/dist/src/link/file.js +256 -0
  82. package/dist/src/link/galleryImage.d.ts +45 -0
  83. package/dist/src/link/galleryImage.js +106 -0
  84. package/dist/src/link/index.d.ts +53 -0
  85. package/dist/src/link/index.js +123 -0
  86. package/dist/src/magicLink.d.ts +69 -0
  87. package/dist/src/magicLink.js +146 -0
  88. package/dist/src/nested.d.ts +43 -0
  89. package/dist/src/nested.js +86 -0
  90. package/dist/src/nowiki/base.d.ts +48 -0
  91. package/dist/src/nowiki/base.js +42 -0
  92. package/dist/src/nowiki/comment.d.ts +41 -0
  93. package/dist/src/nowiki/comment.js +67 -0
  94. package/dist/src/nowiki/dd.d.ts +8 -0
  95. package/dist/src/nowiki/dd.js +25 -0
  96. package/dist/src/nowiki/doubleUnderscore.d.ts +47 -0
  97. package/dist/src/nowiki/doubleUnderscore.js +50 -0
  98. package/dist/src/nowiki/hr.d.ts +33 -0
  99. package/dist/src/nowiki/hr.js +14 -0
  100. package/dist/src/nowiki/index.d.ts +16 -0
  101. package/dist/src/nowiki/index.js +21 -0
  102. package/dist/src/nowiki/list.d.ts +31 -0
  103. package/dist/src/nowiki/list.js +48 -0
  104. package/dist/src/nowiki/listBase.d.ts +20 -0
  105. package/dist/src/nowiki/listBase.js +12 -0
  106. package/dist/src/nowiki/noinclude.d.ts +26 -0
  107. package/dist/src/nowiki/noinclude.js +24 -0
  108. package/dist/src/nowiki/quote.d.ts +24 -0
  109. package/dist/src/nowiki/quote.js +45 -0
  110. package/dist/src/onlyinclude.d.ts +16 -0
  111. package/dist/src/onlyinclude.js +57 -0
  112. package/dist/src/paramTag/index.d.ts +37 -0
  113. package/dist/src/paramTag/index.js +68 -0
  114. package/dist/src/paramTag/inputbox.d.ts +8 -0
  115. package/dist/src/paramTag/inputbox.js +23 -0
  116. package/dist/src/parameter.d.ts +86 -0
  117. package/dist/src/parameter.js +205 -0
  118. package/dist/src/pre.d.ts +28 -0
  119. package/dist/src/pre.js +51 -0
  120. package/dist/src/syntax.d.ts +30 -0
  121. package/dist/src/syntax.js +34 -0
  122. package/dist/src/table/base.d.ts +55 -0
  123. package/dist/src/table/base.js +78 -0
  124. package/dist/src/table/index.d.ts +228 -0
  125. package/dist/src/table/index.js +378 -0
  126. package/dist/src/table/td.d.ts +107 -0
  127. package/dist/src/table/td.js +260 -0
  128. package/dist/src/table/tr.d.ts +32 -0
  129. package/dist/src/table/tr.js +56 -0
  130. package/dist/src/table/trBase.d.ts +53 -0
  131. package/dist/src/table/trBase.js +151 -0
  132. package/dist/src/tagPair/ext.d.ts +58 -0
  133. package/dist/src/tagPair/ext.js +142 -0
  134. package/dist/src/tagPair/include.d.ts +54 -0
  135. package/dist/src/tagPair/include.js +63 -0
  136. package/dist/src/tagPair/index.d.ts +49 -0
  137. package/dist/src/tagPair/index.js +93 -0
  138. package/dist/src/transclude.d.ts +167 -0
  139. package/dist/src/transclude.js +696 -0
  140. package/dist/util/constants.js +108 -0
  141. package/dist/util/debug.js +83 -0
  142. package/dist/util/diff.js +72 -0
  143. package/dist/util/lint.js +30 -0
  144. package/dist/util/string.js +51 -0
  145. package/errors/README +1 -0
  146. package/package.json +12 -32
  147. package/printed/README +1 -0
  148. package/bundle/bundle.min.js +0 -36
  149. package/extensions/dist/base.js +0 -68
  150. package/extensions/dist/editor.js +0 -159
  151. package/extensions/dist/highlight.js +0 -30
  152. package/extensions/dist/lint.js +0 -48
  153. package/extensions/editor.css +0 -63
  154. package/extensions/ui.css +0 -114
@@ -0,0 +1,40 @@
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;
@@ -0,0 +1,67 @@
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;
@@ -0,0 +1,161 @@
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 selector
78
+ * @throws `SyntaxError` 非法的选择器
79
+ */
80
+ const parseSelector = (selector) => {
81
+ selector = selector.trim();
82
+ const stack = [[[]]];
83
+ let sanitized = sanitize(selector), regex = regularRegex, mt = regex.exec(sanitized), [condition] = stack, [step] = condition;
84
+ /**
85
+ * 解析简单伪选择器
86
+ * @param index 伪选择器的终点位置
87
+ * @throws `SyntaxError` 非法的选择器
88
+ */
89
+ const pushSimple = (index) => {
90
+ const str = sanitized.slice(0, index), pieces = str.trim().split(':'),
91
+ // eslint-disable-next-line unicorn/explicit-length-check
92
+ i = pieces.slice(1).findIndex(pseudo => simplePseudos.has(pseudo)) + 1 || pieces.length;
93
+ if (pieces.slice(i).some(pseudo => !simplePseudos.has(pseudo))) {
94
+ throw new SyntaxError(`非法的选择器!\n${str}\n可能需要将':'转义为'\\:'。`);
95
+ }
96
+ step.push(desanitize(pieces.slice(0, i).join(':')), ...pieces.slice(i).map(piece => `:${piece}`));
97
+ };
98
+ while (mt) {
99
+ let { 0: syntax, index } = mt;
100
+ if (syntax.trim() === '') {
101
+ index += syntax.length;
102
+ const char = sanitized[index];
103
+ syntax = grouping.has(char) ? char : '';
104
+ }
105
+ if (syntax === ',') { // 情形1:并列
106
+ pushSimple(index);
107
+ condition = [[]];
108
+ [step] = condition;
109
+ stack.push(condition);
110
+ }
111
+ else if (combinator.has(syntax)) { // 情形2:关系
112
+ pushSimple(index);
113
+ if (!step.some(Boolean)) {
114
+ throw new SyntaxError(`非法的选择器!\n${selector}\n可能需要通用选择器'*'。`);
115
+ }
116
+ step.relation = syntax;
117
+ step = [];
118
+ condition.push(step);
119
+ }
120
+ else if (syntax === '[') { // 情形3:属性开启
121
+ pushSimple(index);
122
+ regex = attributeRegex;
123
+ }
124
+ else if (syntax.endsWith(']')) { // 情形4:属性闭合
125
+ mt[3] &&= desanitize(deQuote(mt[3]));
126
+ step.push(mt.slice(1));
127
+ regex = regularRegex;
128
+ }
129
+ else if (syntax === '(') { // 情形5:伪选择器开启
130
+ const pseudoExec = pseudoRegex.exec(sanitized.slice(0, index));
131
+ if (!pseudoExec) {
132
+ throw new SyntaxError(`非法的选择器!\n${desanitize(sanitized)}\n请检查伪选择器是否存在。`);
133
+ }
134
+ pushSimple(pseudoExec.index);
135
+ step.push(pseudoExec[1]); // 临时存放复杂伪选择器
136
+ regex = functionRegex;
137
+ }
138
+ else { // 情形6:伪选择器闭合
139
+ mt.push(step.pop());
140
+ mt[1] &&= deQuote(mt[1]);
141
+ step.push(mt.slice(1));
142
+ regex = regularRegex;
143
+ }
144
+ sanitized = sanitized.slice(index + syntax.length);
145
+ if (grouping.has(syntax)) {
146
+ sanitized = sanitized.trim();
147
+ }
148
+ mt = regex.exec(sanitized);
149
+ }
150
+ if (regex === regularRegex) {
151
+ pushSimple(Infinity);
152
+ const pseudos = new Set(stack.flat(2).filter((e) => typeof e === 'string' && e.startsWith(':')));
153
+ if (pseudos.size > 0) {
154
+ Parser.warn('检测到伪选择器,请确认是否需要将":"转义成"\\:"。', pseudos);
155
+ }
156
+ return stack;
157
+ }
158
+ throw new SyntaxError(`非法的选择器!\n${selector}\n检测到未闭合的'${regex === attributeRegex ? '[' : '('}'`);
159
+ };
160
+ exports.parseSelector = parseSelector;
161
+ constants_1.parsers['parseSelector'] = __filename;
@@ -0,0 +1,120 @@
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
+ /**
12
+ * 判断是否为表格行或表格
13
+ * @param token 表格节点
14
+ */
15
+ const isTr = (token) => token.lastChild.constructor !== index_1.Token;
16
+ /**
17
+ * 解析表格,注意`tr`和`td`包含开头的换行
18
+ * @param {Token & {firstChild: AstText}} root 根节点
19
+ * @param config
20
+ * @param accum
21
+ */
22
+ const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getConfig(), accum = []) => {
23
+ const stack = [], lines = data.split('\n');
24
+ let out = type === 'root' || type === 'parameter-value' || type === 'ext-inner' && name === 'poem'
25
+ ? ''
26
+ : `\n${lines.shift()}`, top;
27
+ /**
28
+ * 向表格中插入纯文本
29
+ * @param str 待插入的文本
30
+ * @param topToken 当前解析的表格或表格行
31
+ */
32
+ const push = (str, topToken) => {
33
+ if (!topToken) {
34
+ out += str;
35
+ return;
36
+ }
37
+ const { lastChild } = topToken;
38
+ if (isTr(topToken)) {
39
+ const token = new index_1.Token(str, config, accum);
40
+ token.type = 'table-inter';
41
+ token.setAttribute('stage', 3);
42
+ topToken.insertAt(token);
43
+ }
44
+ else {
45
+ lastChild.setText(String(lastChild) + str);
46
+ }
47
+ },
48
+ /** 取出最近的表格行 */
49
+ pop = () => top.type === 'td' ? stack.pop() : top;
50
+ for (const outLine of lines) {
51
+ top = stack.pop();
52
+ 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
53
+ .exec(line);
54
+ if (matchesStart) {
55
+ while (top && top.type !== 'td') {
56
+ top = stack.pop();
57
+ }
58
+ const [, indent, moreSpaces, tableSyntax, attr] = matchesStart;
59
+ if (indent) {
60
+ new dd_1.DdToken(indent, config, accum);
61
+ }
62
+ push(`\n${spaces}${indent && `\0${accum.length - 1}d\x7F`}${moreSpaces}\0${accum.length}b\x7F`, top);
63
+ stack.push(...top ? [top] : [], new index_2.TableToken(tableSyntax, attr, config, accum));
64
+ continue;
65
+ }
66
+ else if (!top) {
67
+ out += `\n${outLine}`;
68
+ continue;
69
+ }
70
+ // eslint-disable-next-line @stylistic/operator-linebreak
71
+ const matches = /^(?:(\|\}|\0\d+!\x7F\}|\0\d+\}\x7F)|(\|-+|\0\d+!\x7F-+|\0\d+-\x7F-*)(?!-)|(!|(?:\||\0\d+!\x7F)\+?))(.*)$/u
72
+ .exec(line);
73
+ if (!matches) {
74
+ push(`\n${outLine}`, top);
75
+ stack.push(top);
76
+ continue;
77
+ }
78
+ const [, closing, row, cell, attr] = matches;
79
+ if (closing) {
80
+ while (top.type !== 'table') {
81
+ top = stack.pop();
82
+ }
83
+ top.close(`\n${spaces}${closing}`, true);
84
+ push(attr, stack.at(-1));
85
+ }
86
+ else if (row) {
87
+ top = pop();
88
+ if (top.type === 'tr') {
89
+ top = stack.pop();
90
+ }
91
+ const tr = new tr_1.TrToken(`\n${spaces}${row}`, attr, config, accum);
92
+ stack.push(top, tr);
93
+ top.insertAt(tr);
94
+ }
95
+ else {
96
+ top = pop();
97
+ const regex = cell === '!' ? /!!|(?:\||\0\d+!\x7F){2}|\0\d+\+\x7F/gu : /(?:\||\0\d+!\x7F){2}|\0\d+\+\x7F/gu;
98
+ let mt = regex.exec(attr), lastIndex = 0, lastSyntax = `\n${spaces}${cell}`;
99
+ /**
100
+ * 创建表格单元格
101
+ * @param tr 当前表格行
102
+ */
103
+ const createTd = (tr) => {
104
+ const td = new td_1.TdToken(lastSyntax, attr.slice(lastIndex, mt?.index), config, accum);
105
+ tr.insertAt(td);
106
+ return td;
107
+ };
108
+ while (mt) {
109
+ createTd(top);
110
+ ({ lastIndex } = regex);
111
+ [lastSyntax] = mt;
112
+ mt = regex.exec(attr);
113
+ }
114
+ stack.push(top, createTd(top));
115
+ }
116
+ }
117
+ return out.slice(1);
118
+ };
119
+ exports.parseTable = parseTable;
120
+ constants_1.parsers['parseTable'] = __filename;
@@ -0,0 +1,56 @@
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
+ */
45
+ insertAt<T extends Token>(token: T, i?: number): T;
46
+ /**
47
+ * 设置参数名
48
+ * @param name 新参数名
49
+ */
50
+ setName(name: string): void;
51
+ /**
52
+ * 设置预设值
53
+ * @param value 预设值
54
+ */
55
+ setDefault(value: string | false): void;
56
+ }
@@ -0,0 +1,187 @@
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
+ */
145
+ insertAt(token, i = this.length) {
146
+ i += i < 0 ? this.length : 0;
147
+ if (i > 1) {
148
+ this.constructorError('不可插入多余的子节点');
149
+ }
150
+ else if (typeof token === 'string') {
151
+ this.constructorError('不可插入文本节点');
152
+ }
153
+ super.insertAt(token, i);
154
+ if (i === 1) {
155
+ token.type = 'arg-default';
156
+ }
157
+ return token;
158
+ }
159
+ /**
160
+ * 设置参数名
161
+ * @param name 新参数名
162
+ */
163
+ setName(name) {
164
+ const { childNodes } = Parser.parse(name, this.getAttribute('include'), 2, this.getAttribute('config'));
165
+ this.firstChild.replaceChildren(...childNodes);
166
+ }
167
+ /**
168
+ * 设置预设值
169
+ * @param value 预设值
170
+ */
171
+ setDefault(value) {
172
+ if (value === false) {
173
+ this.removeAt(1);
174
+ return;
175
+ }
176
+ const root = Parser.parse(value, this.getAttribute('include'), undefined, this.getAttribute('config')), { childNodes: [, oldDefault] } = this;
177
+ if (oldDefault) {
178
+ oldDefault.replaceChildren(...root.childNodes);
179
+ }
180
+ else {
181
+ root.type = 'arg-default';
182
+ this.insertAt(root);
183
+ }
184
+ }
185
+ }
186
+ exports.ArgToken = ArgToken;
187
+ constants_1.classes['ArgToken'] = __filename;
@@ -0,0 +1,12 @@
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 {};
@@ -0,0 +1,27 @@
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;