wikiparser-node 1.11.1 → 1.12.1-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 (173) hide show
  1. package/bundle/bundle.min.js +37 -0
  2. package/config/enwiki.json +1 -814
  3. package/config/llwiki.json +1 -35
  4. package/config/moegirl.json +1 -44
  5. package/config/zhwiki.json +1 -466
  6. package/extensions/dist/base.js +162 -0
  7. package/extensions/dist/codejar.js +52 -0
  8. package/extensions/dist/editor.js +159 -0
  9. package/extensions/dist/highlight.js +30 -0
  10. package/extensions/dist/lint.js +72 -0
  11. package/extensions/editor.css +59 -0
  12. package/extensions/ui.css +159 -0
  13. package/package.json +29 -21
  14. package/config/.schema.json +0 -186
  15. package/dist/addon/table.js +0 -486
  16. package/dist/addon/token.js +0 -304
  17. package/dist/addon/transclude.js +0 -184
  18. package/dist/base.d.ts +0 -81
  19. package/dist/base.js +0 -39
  20. package/dist/index.d.ts +0 -33
  21. package/dist/index.js +0 -235
  22. package/dist/internal.d.ts +0 -46
  23. package/dist/lib/element.d.ts +0 -125
  24. package/dist/lib/element.js +0 -375
  25. package/dist/lib/node.d.ts +0 -173
  26. package/dist/lib/node.js +0 -477
  27. package/dist/lib/range.d.ts +0 -105
  28. package/dist/lib/range.js +0 -406
  29. package/dist/lib/ranges.d.ts +0 -28
  30. package/dist/lib/ranges.js +0 -126
  31. package/dist/lib/rect.d.ts +0 -18
  32. package/dist/lib/rect.js +0 -34
  33. package/dist/lib/text.d.ts +0 -58
  34. package/dist/lib/text.js +0 -400
  35. package/dist/lib/title.d.ts +0 -42
  36. package/dist/lib/title.js +0 -208
  37. package/dist/mixin/attributesParent.d.ts +0 -49
  38. package/dist/mixin/attributesParent.js +0 -79
  39. package/dist/mixin/fixed.d.ts +0 -5
  40. package/dist/mixin/fixed.js +0 -32
  41. package/dist/mixin/flagsParent.d.ts +0 -43
  42. package/dist/mixin/flagsParent.js +0 -64
  43. package/dist/mixin/hidden.d.ts +0 -7
  44. package/dist/mixin/hidden.js +0 -37
  45. package/dist/mixin/magicLinkParent.d.ts +0 -19
  46. package/dist/mixin/magicLinkParent.js +0 -43
  47. package/dist/mixin/singleLine.d.ts +0 -5
  48. package/dist/mixin/singleLine.js +0 -25
  49. package/dist/mixin/sol.d.ts +0 -6
  50. package/dist/mixin/sol.js +0 -45
  51. package/dist/mixin/syntax.d.ts +0 -8
  52. package/dist/mixin/syntax.js +0 -46
  53. package/dist/parser/braces.js +0 -150
  54. package/dist/parser/commentAndExt.js +0 -79
  55. package/dist/parser/converter.js +0 -39
  56. package/dist/parser/externalLinks.js +0 -37
  57. package/dist/parser/hrAndDoubleUnderscore.js +0 -42
  58. package/dist/parser/html.js +0 -38
  59. package/dist/parser/links.js +0 -101
  60. package/dist/parser/list.js +0 -114
  61. package/dist/parser/magicLinks.js +0 -52
  62. package/dist/parser/quotes.js +0 -67
  63. package/dist/parser/redirect.js +0 -26
  64. package/dist/parser/selector.js +0 -394
  65. package/dist/parser/table.js +0 -123
  66. package/dist/src/arg.d.ts +0 -51
  67. package/dist/src/arg.js +0 -214
  68. package/dist/src/atom.d.ts +0 -14
  69. package/dist/src/atom.js +0 -52
  70. package/dist/src/attribute.d.ts +0 -64
  71. package/dist/src/attribute.js +0 -480
  72. package/dist/src/attributes.d.ts +0 -101
  73. package/dist/src/attributes.js +0 -381
  74. package/dist/src/converter.d.ts +0 -28
  75. package/dist/src/converter.js +0 -148
  76. package/dist/src/converterFlags.d.ts +0 -80
  77. package/dist/src/converterFlags.js +0 -239
  78. package/dist/src/converterRule.d.ts +0 -71
  79. package/dist/src/converterRule.js +0 -216
  80. package/dist/src/extLink.d.ts +0 -36
  81. package/dist/src/extLink.js +0 -218
  82. package/dist/src/gallery.d.ts +0 -47
  83. package/dist/src/gallery.js +0 -143
  84. package/dist/src/heading.d.ts +0 -40
  85. package/dist/src/heading.js +0 -192
  86. package/dist/src/hidden.d.ts +0 -9
  87. package/dist/src/hidden.js +0 -80
  88. package/dist/src/html.d.ts +0 -61
  89. package/dist/src/html.js +0 -343
  90. package/dist/src/imageParameter.d.ts +0 -60
  91. package/dist/src/imageParameter.js +0 -260
  92. package/dist/src/imagemap.d.ts +0 -47
  93. package/dist/src/imagemap.js +0 -146
  94. package/dist/src/imagemapLink.d.ts +0 -31
  95. package/dist/src/imagemapLink.js +0 -97
  96. package/dist/src/index.d.ts +0 -136
  97. package/dist/src/index.js +0 -834
  98. package/dist/src/link/base.d.ts +0 -52
  99. package/dist/src/link/base.js +0 -256
  100. package/dist/src/link/category.d.ts +0 -22
  101. package/dist/src/link/category.js +0 -34
  102. package/dist/src/link/file.d.ts +0 -102
  103. package/dist/src/link/file.js +0 -333
  104. package/dist/src/link/galleryImage.d.ts +0 -29
  105. package/dist/src/link/galleryImage.js +0 -132
  106. package/dist/src/link/index.d.ts +0 -39
  107. package/dist/src/link/index.js +0 -98
  108. package/dist/src/link/redirectTarget.d.ts +0 -27
  109. package/dist/src/link/redirectTarget.js +0 -69
  110. package/dist/src/magicLink.d.ts +0 -58
  111. package/dist/src/magicLink.js +0 -256
  112. package/dist/src/nested.d.ts +0 -40
  113. package/dist/src/nested.js +0 -106
  114. package/dist/src/nowiki/base.d.ts +0 -28
  115. package/dist/src/nowiki/base.js +0 -89
  116. package/dist/src/nowiki/comment.d.ts +0 -14
  117. package/dist/src/nowiki/comment.js +0 -121
  118. package/dist/src/nowiki/dd.d.ts +0 -8
  119. package/dist/src/nowiki/dd.js +0 -72
  120. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -15
  121. package/dist/src/nowiki/doubleUnderscore.js +0 -97
  122. package/dist/src/nowiki/hr.d.ts +0 -5
  123. package/dist/src/nowiki/hr.js +0 -70
  124. package/dist/src/nowiki/index.d.ts +0 -14
  125. package/dist/src/nowiki/index.js +0 -28
  126. package/dist/src/nowiki/list.d.ts +0 -5
  127. package/dist/src/nowiki/list.js +0 -65
  128. package/dist/src/nowiki/listBase.d.ts +0 -23
  129. package/dist/src/nowiki/listBase.js +0 -99
  130. package/dist/src/nowiki/noinclude.d.ts +0 -6
  131. package/dist/src/nowiki/noinclude.js +0 -75
  132. package/dist/src/nowiki/quote.d.ts +0 -14
  133. package/dist/src/nowiki/quote.js +0 -140
  134. package/dist/src/onlyinclude.d.ts +0 -13
  135. package/dist/src/onlyinclude.js +0 -58
  136. package/dist/src/paramTag/index.d.ts +0 -28
  137. package/dist/src/paramTag/index.js +0 -78
  138. package/dist/src/paramTag/inputbox.d.ts +0 -8
  139. package/dist/src/paramTag/inputbox.js +0 -22
  140. package/dist/src/parameter.d.ts +0 -60
  141. package/dist/src/parameter.js +0 -264
  142. package/dist/src/pre.d.ts +0 -28
  143. package/dist/src/pre.js +0 -60
  144. package/dist/src/redirect.d.ts +0 -30
  145. package/dist/src/redirect.js +0 -126
  146. package/dist/src/syntax.d.ts +0 -17
  147. package/dist/src/syntax.js +0 -87
  148. package/dist/src/table/base.d.ts +0 -28
  149. package/dist/src/table/base.js +0 -81
  150. package/dist/src/table/index.d.ts +0 -230
  151. package/dist/src/table/index.js +0 -506
  152. package/dist/src/table/td.d.ts +0 -72
  153. package/dist/src/table/td.js +0 -370
  154. package/dist/src/table/tr.d.ts +0 -30
  155. package/dist/src/table/tr.js +0 -59
  156. package/dist/src/table/trBase.d.ts +0 -49
  157. package/dist/src/table/trBase.js +0 -164
  158. package/dist/src/tagPair/ext.d.ts +0 -29
  159. package/dist/src/tagPair/ext.js +0 -220
  160. package/dist/src/tagPair/include.d.ts +0 -33
  161. package/dist/src/tagPair/include.js +0 -130
  162. package/dist/src/tagPair/index.d.ts +0 -23
  163. package/dist/src/tagPair/index.js +0 -128
  164. package/dist/src/transclude.d.ts +0 -159
  165. package/dist/src/transclude.js +0 -587
  166. package/dist/util/constants.js +0 -25
  167. package/dist/util/debug.js +0 -95
  168. package/dist/util/diff.js +0 -83
  169. package/dist/util/html.js +0 -143
  170. package/dist/util/lint.js +0 -32
  171. package/dist/util/string.js +0 -87
  172. package/errors/README +0 -3
  173. package/printed/README +0 -3
@@ -1,394 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkToken = void 0;
4
- const constants_1 = require("../util/constants");
5
- const string_1 = require("../util/string");
6
- const ranges_1 = require("../lib/ranges");
7
- const title_1 = require("../lib/title");
8
- const simplePseudos = new Set([
9
- 'root',
10
- 'first-child',
11
- 'first-of-type',
12
- 'last-child',
13
- 'last-of-type',
14
- 'only-child',
15
- 'only-of-type',
16
- 'empty',
17
- 'parent',
18
- 'header',
19
- 'hidden',
20
- 'visible',
21
- 'only-whitespace',
22
- 'any-link',
23
- 'local-link',
24
- 'invalid',
25
- 'required',
26
- 'optional',
27
- ]), complexPseudos = new Set([
28
- 'is',
29
- 'not',
30
- 'nth-child',
31
- 'nth-of-type',
32
- 'nth-last-child',
33
- 'nth-last-of-type',
34
- 'contains',
35
- 'has',
36
- 'lang',
37
- 'regex',
38
- ]), specialChars = [
39
- ['[', '['],
40
- [']', ']'],
41
- ['(', '('],
42
- [')', ')'],
43
- ['"', '"'],
44
- [`'`, '''],
45
- [':', ':'],
46
- ['\\', '\'],
47
- ['&', '&'],
48
- ], 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(['>', '+', '~', '']), sanitizeRegex = specialChars.map(([c, escaped]) => [new RegExp((0, string_1.escapeRegExp)(`\\${c}`), 'gu'), escaped]), desanitizeRegex = specialChars.map(([c, escaped]) => [c, new RegExp(escaped, 'gu')]), primitives = new Set(['string', 'number', 'boolean', 'undefined']);
49
- /**
50
- * optionally convert to lower cases
51
- * @param val 属性值
52
- * @param i 是否对大小写不敏感
53
- */
54
- const toCase = (val, i) => i ? val.toLowerCase() : val;
55
- /**
56
- * 检查某个下标是否符合表达式
57
- * @param str 表达式
58
- * @param i 待检查的下标
59
- */
60
- const nth = (str, i) => new ranges_1.Ranges(str).applyTo(i + 1).includes(i);
61
- /**
62
- * 是否受保护。保护条件来自Token,这里仅提前用于:required和:optional伪选择器。
63
- * @param token 节点
64
- */
65
- const isProtected = (token) => {
66
- const { parentNode } = token;
67
- if (!parentNode) {
68
- return undefined;
69
- }
70
- const { childNodes, fixed } = parentNode;
71
- return fixed
72
- || parentNode.getAttribute('protectedChildren').applyTo(childNodes).includes(childNodes.indexOf(token));
73
- };
74
- /**
75
- * 获取属性
76
- * @param token 节点
77
- * @param key 属性键
78
- */
79
- const getAttr = (token, key) => {
80
- if (typeof token.getAttr === 'function') {
81
- const attr = token.getAttr(key);
82
- if (attr !== undefined) {
83
- return attr;
84
- }
85
- }
86
- const val = token[key];
87
- return val instanceof RegExp ? val.source : val;
88
- };
89
- /**
90
- * 检查是否符合解析后的选择器,不含节点关系
91
- * @param token 节点
92
- * @param step 解析后的选择器
93
- * @throws `SyntaxError` 错误的正则伪选择器
94
- * @throws `SyntaxError` 未定义的伪选择器
95
- */
96
- const matches = (token, step) => {
97
- const { parentNode, type, name, childNodes, link } = token, children = parentNode?.children, childrenOfType = children?.filter(({ type: t }) => t === type), siblingsCount = children?.length ?? 1, siblingsCountOfType = childrenOfType?.length ?? 1, index = (children?.indexOf(token) ?? 0) + 1, indexOfType = (childrenOfType?.indexOf(token) ?? 0) + 1, lastIndex = siblingsCount - index + 1, lastIndexOfType = siblingsCountOfType - indexOfType + 1;
98
- return step.every(selector => {
99
- if (typeof selector === 'string') {
100
- switch (selector) { // 情形1:简单伪选择器、type和name
101
- case '*':
102
- return true;
103
- case ':root':
104
- return !parentNode;
105
- case ':first-child':
106
- return index === 1;
107
- case ':first-of-type':
108
- return indexOfType === 1;
109
- case ':last-child':
110
- return lastIndex === 1;
111
- case ':last-of-type':
112
- return lastIndexOfType === 1;
113
- case ':only-child':
114
- return siblingsCount === 1;
115
- case ':only-of-type':
116
- return siblingsCountOfType === 1;
117
- case ':empty':
118
- return !childNodes.some(({ type: t, data }) => t !== 'text' || data);
119
- case ':parent':
120
- return childNodes.some(({ type: t, data }) => t !== 'text' || data);
121
- case ':header':
122
- return type === 'heading';
123
- case ':hidden':
124
- return token.text() === '';
125
- case ':visible':
126
- return token.text() !== '';
127
- case ':only-whitespace':
128
- return token.text().trim() === '';
129
- case ':any-link':
130
- return type === 'link'
131
- || type === 'redirect-target'
132
- || type === 'free-ext-link'
133
- || type === 'magic-link'
134
- || type === 'ext-link'
135
- || (type === 'file' || type === 'gallery-image') && link;
136
- case ':local-link':
137
- return (type === 'link' || type === 'file' || type === 'gallery-image')
138
- && link instanceof title_1.Title
139
- && link.title === '';
140
- case ':invalid':
141
- return type === 'table-inter' || type === 'image-parameter' && name === 'invalid';
142
- case ':required':
143
- return isProtected(token) === true;
144
- case ':optional':
145
- return isProtected(token) === false;
146
- default: {
147
- const [t, n] = selector.split('#');
148
- return (!t || t === type) && (!n || n === name);
149
- }
150
- }
151
- }
152
- else if (selector.length === 4) { // 情形2:属性选择器
153
- const [key, equal, val = '', i] = selector, isAttr = typeof token.hasAttr === 'function' && typeof token.getAttr === 'function';
154
- if (!(key in token) && (!isAttr || !token.hasAttr(key))) {
155
- return equal === '!=';
156
- }
157
- const v = toCase(val, i), thisVal = getAttr(token, key);
158
- if (!equal) {
159
- return thisVal !== undefined && thisVal !== false;
160
- }
161
- if (equal === '~=') {
162
- const thisVals = typeof thisVal === 'string' ? thisVal.split(/\s/u) : thisVal;
163
- return Boolean(thisVals?.[Symbol.iterator])
164
- && [...thisVals].some(w => typeof w === 'string' && toCase(w, i) === v);
165
- }
166
- else if (!primitives.has(typeof thisVal) && !(thisVal instanceof title_1.Title)) {
167
- throw new RangeError(`The complex attribute ${key} cannot be used in a selector!`);
168
- }
169
- const stringVal = toCase(String(thisVal), i);
170
- switch (equal) {
171
- case '|=':
172
- return stringVal === v || stringVal.startsWith(`${v}-`);
173
- case '^=':
174
- return stringVal.startsWith(v);
175
- case '$=':
176
- return stringVal.endsWith(v);
177
- case '*=':
178
- return stringVal.includes(v);
179
- case '!=':
180
- return stringVal !== v;
181
- default: // `=`
182
- return stringVal === v;
183
- }
184
- }
185
- const [s, pseudo] = selector; // 情形3:复杂伪选择器
186
- switch (pseudo) {
187
- case 'is':
188
- return token.matches(s);
189
- case 'not':
190
- return !token.matches(s);
191
- case 'nth-child':
192
- return nth(s, index);
193
- case 'nth-of-type':
194
- return nth(s, indexOfType);
195
- case 'nth-last-child':
196
- return nth(s, lastIndex);
197
- case 'nth-last-of-type':
198
- return nth(s, lastIndexOfType);
199
- case 'contains':
200
- return token.text().includes(s);
201
- case 'has':
202
- return Boolean(token.querySelector(s));
203
- case 'lang': {
204
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
205
- /^zh(?:-|$)/iu;
206
- const regex = new RegExp(`^${s}(?:-|$)`, 'iu');
207
- let node = token;
208
- for (; node; node = node.parentNode) {
209
- const lang = node.attributes?.['lang'];
210
- if (lang !== undefined) {
211
- return typeof lang === 'string' && regex.test(lang);
212
- }
213
- }
214
- return false;
215
- }
216
- case 'regex': {
217
- const mt = /^([^,]+),\s*\/(.+)\/([a-z]*)$/u.exec(s);
218
- if (!mt) {
219
- throw new SyntaxError(`Wrong usage of the regex pseudo-selector. Use ":regex('attr, /re/i')" format.`);
220
- }
221
- try {
222
- return new RegExp(mt[2], mt[3]).test(String(getAttr(token, mt[1].trim())));
223
- }
224
- catch {
225
- throw new SyntaxError(`Invalid regular expression: /${mt[2]}/${mt[3]}`);
226
- }
227
- }
228
- default:
229
- throw new SyntaxError(`Undefined pseudo-selector: ${pseudo}`);
230
- }
231
- });
232
- };
233
- /**
234
- * 检查是否符合解析后的选择器
235
- * @param token 节点
236
- * @param copy 解析后的选择器
237
- */
238
- const matchesArray = (token, copy) => {
239
- const condition = [...copy];
240
- if (matches(token, condition.pop())) {
241
- const { parentNode, previousElementSibling } = token;
242
- switch (condition.at(-1)?.relation) {
243
- case undefined:
244
- return true;
245
- case '>':
246
- return Boolean(parentNode && matchesArray(parentNode, condition));
247
- case '+':
248
- return Boolean(previousElementSibling && matchesArray(previousElementSibling, condition));
249
- case '~': {
250
- if (!parentNode) {
251
- return false;
252
- }
253
- const { children } = parentNode;
254
- return children.slice(0, children.indexOf(token)).some(child => matchesArray(child, condition));
255
- }
256
- default: // ' '
257
- return token.getAncestors().some(ancestor => matchesArray(ancestor, condition));
258
- }
259
- }
260
- return false;
261
- };
262
- /**
263
- * 还原转义符号
264
- * @param selector
265
- */
266
- const desanitize = (selector) => {
267
- for (const [c, re] of desanitizeRegex) {
268
- selector = selector.replace(re, c);
269
- }
270
- return selector.trim();
271
- };
272
- /**
273
- * 去除首尾的引号
274
- * @param val 属性值或伪选择器函数的参数
275
- */
276
- const deQuote = (val) => /^(["']).*\1$/u.test(val) ? val.slice(1, -1) : val.trim();
277
- /**
278
- * 检查节点是否符合选择器
279
- * @param selector
280
- */
281
- const checkToken = (selector) => (token) => {
282
- let sanitized = selector.trim();
283
- for (const [re, escaped] of sanitizeRegex) {
284
- sanitized = sanitized.replace(re, escaped);
285
- }
286
- const stack = [[[]]];
287
- let regex = regularRegex, mt = regex.exec(sanitized), [condition] = stack, [step] = condition;
288
- /**
289
- * 解析简单伪选择器
290
- * @param index 伪选择器的终点位置
291
- * @throws `SyntaxError` 选择器排序
292
- * @throws `SyntaxError` 非法的选择器
293
- */
294
- const pushSimple = (index) => {
295
- const str = sanitized.slice(0, index).trim();
296
- if (!str) {
297
- return;
298
- }
299
- const pieces = str.split(/(?=[:#])/u);
300
- for (let i = 0; i < pieces.length; i++) {
301
- const piece = pieces[i];
302
- if (!/^[:#]/u.test(piece)) {
303
- if (step.length > 0) {
304
- throw new SyntaxError(`Invalid selector!\n${selector}\nType selectors must come first.`);
305
- }
306
- else {
307
- step.push(piece);
308
- }
309
- }
310
- else if (piece.startsWith(':')) {
311
- if (simplePseudos.has(piece.slice(1))) {
312
- step.push(piece);
313
- }
314
- else if (pieces[i - 1]?.startsWith('#')) {
315
- pieces[i - 1] += piece;
316
- pieces.splice(i, 1);
317
- i--;
318
- }
319
- else {
320
- throw new SyntaxError(`Undefined pseudo selector!\n${desanitize(piece)}`);
321
- }
322
- }
323
- }
324
- step.push(...pieces.filter(piece => piece.startsWith('#')).map(desanitize));
325
- };
326
- /**
327
- * 检查是否需要通用选择器
328
- * @throws `SyntaxError` 非法的选择器
329
- */
330
- const needUniversal = () => {
331
- if (step.length === 0) {
332
- throw new SyntaxError(`Invalid selector!\n${selector}\nYou may need the universal selector '*'.`);
333
- }
334
- };
335
- while (mt) {
336
- let { 0: syntax, index } = mt;
337
- if (syntax.trim() === '') {
338
- index += syntax.length;
339
- const char = sanitized[index];
340
- syntax = grouping.has(char) ? char : '';
341
- }
342
- if (syntax === ',') { // 情形1:并列
343
- pushSimple(index);
344
- needUniversal();
345
- condition = [[]];
346
- [step] = condition;
347
- stack.push(condition);
348
- }
349
- else if (combinator.has(syntax)) { // 情形2:关系
350
- pushSimple(index);
351
- needUniversal();
352
- step.relation = syntax;
353
- step = [];
354
- condition.push(step);
355
- }
356
- else if (syntax === '[') { // 情形3:属性开启
357
- pushSimple(index);
358
- regex = attributeRegex;
359
- }
360
- else if (syntax.endsWith(']')) { // 情形4:属性闭合
361
- mt[3] &&= desanitize(deQuote(mt[3]));
362
- step.push(mt.slice(1));
363
- regex = regularRegex;
364
- }
365
- else if (syntax === '(') { // 情形5:伪选择器开启
366
- const i = sanitized.lastIndexOf(':', index), pseudo = sanitized.slice(i + 1, index);
367
- if (i === -1 || !complexPseudos.has(pseudo)) {
368
- throw new SyntaxError(`Undefined pseudo selector!\n${desanitize(sanitized)}`);
369
- }
370
- pushSimple(i);
371
- step.push(pseudo); // 临时存放复杂伪选择器
372
- regex = functionRegex;
373
- }
374
- else { // 情形6:伪选择器闭合
375
- mt.push(step.pop());
376
- mt[1] &&= deQuote(mt[1]);
377
- step.push(mt.slice(1));
378
- regex = regularRegex;
379
- }
380
- sanitized = sanitized.slice(index + syntax.length);
381
- if (grouping.has(syntax)) {
382
- sanitized = sanitized.trim();
383
- }
384
- mt = regex.exec(sanitized);
385
- }
386
- if (regex === regularRegex) {
387
- pushSimple();
388
- needUniversal();
389
- return stack.some(copy => matchesArray(token, copy));
390
- }
391
- throw new SyntaxError(`Unclosed '${regex === attributeRegex ? '[' : '('}' in the selector!\n${desanitize(sanitized)}`);
392
- };
393
- exports.checkToken = checkToken;
394
- constants_1.parsers['parseSelector'] = __filename;
@@ -1,123 +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 index_1 = require("../src/index");
6
- const index_2 = require("../src/table/index");
7
- const tr_1 = require("../src/table/tr");
8
- const td_1 = require("../src/table/td");
9
- const dd_1 = require("../src/nowiki/dd");
10
- /**
11
- * 判断是否为表格行或表格
12
- * @param token 表格节点
13
- */
14
- const isTr = (token) => token.lastChild.constructor !== index_1.Token;
15
- /**
16
- * 解析表格,注意`tr`和`td`包含开头的换行
17
- * @param {Token & {firstChild: AstText}} root 根节点
18
- * @param config
19
- * @param accum
20
- */
21
- const parseTable = ({ firstChild: { data }, type, name }, config, accum) => {
22
- const stack = [], lines = data.split('\n');
23
- let out = type === 'root' || type === 'parameter-value' || type === 'ext-inner' && name === 'poem'
24
- ? ''
25
- : `\n${lines.shift()}`, top;
26
- /**
27
- * 向表格中插入纯文本
28
- * @param str 待插入的文本
29
- * @param topToken 当前解析的表格或表格行
30
- */
31
- const push = (str, topToken) => {
32
- if (!topToken) {
33
- out += str;
34
- return;
35
- }
36
- const { lastChild } = topToken;
37
- if (isTr(topToken)) {
38
- const token = new index_1.Token(str, config, accum);
39
- token.type = 'table-inter';
40
- token.setAttribute('stage', 3);
41
- topToken.insertAt(token);
42
- }
43
- else {
44
- lastChild.setText(lastChild.toString() + str);
45
- }
46
- },
47
- /** 取出最近的表格行 */
48
- pop = () => top.type === 'td' ? stack.pop() : top;
49
- for (const outLine of lines) {
50
- top = stack.pop();
51
- 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
52
- .exec(line);
53
- if (matchesStart) {
54
- while (top && top.type !== 'td') {
55
- top = stack.pop();
56
- }
57
- const [, indent, moreSpaces, tableSyntax, attr] = matchesStart;
58
- if (indent) {
59
- // @ts-expect-error abstract class
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
- // @ts-expect-error abstract class
64
- stack.push(...top ? [top] : [], new index_2.TableToken(tableSyntax, attr, config, accum));
65
- continue;
66
- }
67
- else if (!top) {
68
- out += `\n${outLine}`;
69
- continue;
70
- }
71
- const matches = // eslint-disable-line @stylistic/operator-linebreak
72
- /^(?:(\|\}|\0\d+!\x7F\}|\0\d+\}\x7F)|(\|-+|\0\d+!\x7F-+|\0\d+-\x7F-*)(?!-)|(!|(?:\||\0\d+!\x7F)\+?))(.*)$/u
73
- .exec(line);
74
- if (!matches) {
75
- push(`\n${outLine}`, top);
76
- stack.push(top);
77
- continue;
78
- }
79
- const [, closing, row, cell, attr] = matches;
80
- if (closing) {
81
- while (top.type !== 'table') {
82
- top = stack.pop();
83
- }
84
- top.close(`\n${spaces}${closing}`, true);
85
- push(attr, stack[stack.length - 1]);
86
- }
87
- else if (row) {
88
- top = pop();
89
- if (top.type === 'tr') {
90
- top = stack.pop();
91
- }
92
- // @ts-expect-error abstract class
93
- const tr = new tr_1.TrToken(`\n${spaces}${row}`, attr, config, accum);
94
- stack.push(top, tr);
95
- top.insertAt(tr);
96
- }
97
- else {
98
- top = pop();
99
- const regex = cell === '!' ? /!!|(?:\||\0\d+!\x7F){2}|\0\d+\+\x7F/gu : /(?:\||\0\d+!\x7F){2}|\0\d+\+\x7F/gu;
100
- let mt = regex.exec(attr), lastIndex = 0, lastSyntax = `\n${spaces}${cell}`;
101
- /**
102
- * 创建表格单元格
103
- * @param tr 当前表格行
104
- */
105
- const newTd = (tr) => {
106
- // @ts-expect-error abstract class
107
- const td = new td_1.TdToken(lastSyntax, attr.slice(lastIndex, mt?.index), config, accum);
108
- tr.insertAt(td);
109
- return td;
110
- };
111
- while (mt) {
112
- newTd(top);
113
- ({ lastIndex } = regex);
114
- [lastSyntax] = mt;
115
- mt = regex.exec(attr);
116
- }
117
- stack.push(top, newTd(top));
118
- }
119
- }
120
- return out.slice(1);
121
- };
122
- exports.parseTable = parseTable;
123
- constants_1.parsers['parseTable'] = __filename;
package/dist/src/arg.d.ts DELETED
@@ -1,51 +0,0 @@
1
- import Parser from '../index';
2
- import { Token } from './index';
3
- import { AtomToken } from './atom';
4
- import { HiddenToken } from './hidden';
5
- import type { LintError, AST } from '../base';
6
- /**
7
- * `{{{}}}`包裹的参数
8
- * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
9
- */
10
- export declare abstract class ArgToken extends Token {
11
- #private;
12
- readonly name: string;
13
- readonly childNodes: readonly [AtomToken] | readonly [AtomToken, Token, ...HiddenToken[]];
14
- abstract get firstChild(): AtomToken;
15
- abstract get lastChild(): Token;
16
- abstract get children(): [AtomToken] | [AtomToken, Token, ...HiddenToken[]];
17
- abstract get firstElementChild(): AtomToken;
18
- abstract get lastElementChild(): Token;
19
- get type(): 'arg';
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
- json(): AST;
27
- cloneNode(): this;
28
- /** 移除无效部分 */
29
- removeRedundant(): void;
30
- /**
31
- * @override
32
- * @param i 移除位置
33
- */
34
- removeAt(i: number): Token;
35
- /**
36
- * @override
37
- * @param token 待插入的子节点
38
- * @param i 插入位置
39
- */
40
- insertAt<T extends Token>(token: T, i?: number): T;
41
- /**
42
- * 设置参数名
43
- * @param name 新参数名
44
- */
45
- setName(name: string): void;
46
- /**
47
- * 设置预设值
48
- * @param value 预设值
49
- */
50
- setDefault(value: string | false): void;
51
- }