wikiparser-node 1.7.0 → 1.8.0-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 (172) hide show
  1. package/bundle/bundle.min.js +38 -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 +64 -0
  7. package/extensions/dist/editor.js +159 -0
  8. package/extensions/dist/highlight.js +58 -0
  9. package/extensions/dist/lint.js +72 -0
  10. package/extensions/editor.css +64 -0
  11. package/extensions/ui.css +144 -0
  12. package/package.json +30 -18
  13. package/config/.schema.json +0 -181
  14. package/dist/addon/table.d.ts +0 -1
  15. package/dist/addon/table.js +0 -485
  16. package/dist/addon/token.d.ts +0 -1
  17. package/dist/addon/token.js +0 -220
  18. package/dist/addon/transclude.d.ts +0 -1
  19. package/dist/addon/transclude.js +0 -183
  20. package/dist/base.d.ts +0 -71
  21. package/dist/base.js +0 -38
  22. package/dist/index.d.ts +0 -31
  23. package/dist/index.js +0 -211
  24. package/dist/internal.d.ts +0 -46
  25. package/dist/lib/element.d.ts +0 -151
  26. package/dist/lib/element.js +0 -628
  27. package/dist/lib/node.d.ts +0 -145
  28. package/dist/lib/node.js +0 -420
  29. package/dist/lib/range.d.ts +0 -105
  30. package/dist/lib/range.js +0 -406
  31. package/dist/lib/ranges.d.ts +0 -28
  32. package/dist/lib/ranges.js +0 -126
  33. package/dist/lib/text.d.ts +0 -63
  34. package/dist/lib/text.js +0 -355
  35. package/dist/lib/title.d.ts +0 -40
  36. package/dist/lib/title.js +0 -197
  37. package/dist/mixin/attributesParent.d.ts +0 -50
  38. package/dist/mixin/attributesParent.js +0 -81
  39. package/dist/mixin/fixed.d.ts +0 -6
  40. package/dist/mixin/fixed.js +0 -30
  41. package/dist/mixin/flagsParent.d.ts +0 -72
  42. package/dist/mixin/flagsParent.js +0 -59
  43. package/dist/mixin/hidden.d.ts +0 -5
  44. package/dist/mixin/hidden.js +0 -24
  45. package/dist/mixin/magicLinkParent.d.ts +0 -41
  46. package/dist/mixin/magicLinkParent.js +0 -42
  47. package/dist/mixin/singleLine.d.ts +0 -6
  48. package/dist/mixin/singleLine.js +0 -26
  49. package/dist/mixin/sol.d.ts +0 -6
  50. package/dist/mixin/sol.js +0 -43
  51. package/dist/mixin/syntax.d.ts +0 -9
  52. package/dist/mixin/syntax.js +0 -50
  53. package/dist/parser/braces.js +0 -130
  54. package/dist/parser/commentAndExt.js +0 -89
  55. package/dist/parser/converter.js +0 -40
  56. package/dist/parser/externalLinks.js +0 -44
  57. package/dist/parser/hrAndDoubleUnderscore.js +0 -40
  58. package/dist/parser/html.js +0 -38
  59. package/dist/parser/links.js +0 -99
  60. package/dist/parser/list.js +0 -97
  61. package/dist/parser/magicLinks.js +0 -42
  62. package/dist/parser/quotes.js +0 -67
  63. package/dist/parser/redirect.js +0 -26
  64. package/dist/parser/selector.js +0 -190
  65. package/dist/parser/table.js +0 -123
  66. package/dist/src/arg.d.ts +0 -58
  67. package/dist/src/arg.js +0 -214
  68. package/dist/src/atom.d.ts +0 -12
  69. package/dist/src/atom.js +0 -27
  70. package/dist/src/attribute.d.ts +0 -71
  71. package/dist/src/attribute.js +0 -502
  72. package/dist/src/attributes.d.ts +0 -109
  73. package/dist/src/attributes.js +0 -356
  74. package/dist/src/converter.d.ts +0 -33
  75. package/dist/src/converter.js +0 -134
  76. package/dist/src/converterFlags.d.ts +0 -87
  77. package/dist/src/converterFlags.js +0 -242
  78. package/dist/src/converterRule.d.ts +0 -77
  79. package/dist/src/converterRule.js +0 -209
  80. package/dist/src/extLink.d.ts +0 -43
  81. package/dist/src/extLink.js +0 -191
  82. package/dist/src/gallery.d.ts +0 -54
  83. package/dist/src/gallery.js +0 -139
  84. package/dist/src/heading.d.ts +0 -47
  85. package/dist/src/heading.js +0 -190
  86. package/dist/src/hidden.d.ts +0 -7
  87. package/dist/src/hidden.js +0 -23
  88. package/dist/src/html.d.ts +0 -65
  89. package/dist/src/html.js +0 -358
  90. package/dist/src/imageParameter.d.ts +0 -65
  91. package/dist/src/imageParameter.js +0 -257
  92. package/dist/src/imagemap.d.ts +0 -54
  93. package/dist/src/imagemap.js +0 -144
  94. package/dist/src/imagemapLink.d.ts +0 -31
  95. package/dist/src/imagemapLink.js +0 -93
  96. package/dist/src/index.d.ts +0 -143
  97. package/dist/src/index.js +0 -701
  98. package/dist/src/link/base.d.ts +0 -52
  99. package/dist/src/link/base.js +0 -228
  100. package/dist/src/link/category.d.ts +0 -22
  101. package/dist/src/link/category.js +0 -30
  102. package/dist/src/link/file.d.ts +0 -98
  103. package/dist/src/link/file.js +0 -272
  104. package/dist/src/link/galleryImage.d.ts +0 -32
  105. package/dist/src/link/galleryImage.js +0 -158
  106. package/dist/src/link/index.d.ts +0 -56
  107. package/dist/src/link/index.js +0 -133
  108. package/dist/src/link/redirectTarget.d.ts +0 -51
  109. package/dist/src/link/redirectTarget.js +0 -101
  110. package/dist/src/magicLink.d.ts +0 -59
  111. package/dist/src/magicLink.js +0 -220
  112. package/dist/src/nested.d.ts +0 -43
  113. package/dist/src/nested.js +0 -105
  114. package/dist/src/nowiki/base.d.ts +0 -31
  115. package/dist/src/nowiki/base.js +0 -93
  116. package/dist/src/nowiki/comment.d.ts +0 -25
  117. package/dist/src/nowiki/comment.js +0 -76
  118. package/dist/src/nowiki/dd.d.ts +0 -8
  119. package/dist/src/nowiki/dd.js +0 -24
  120. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -18
  121. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  122. package/dist/src/nowiki/hr.d.ts +0 -5
  123. package/dist/src/nowiki/hr.js +0 -63
  124. package/dist/src/nowiki/index.d.ts +0 -16
  125. package/dist/src/nowiki/index.js +0 -27
  126. package/dist/src/nowiki/list.d.ts +0 -16
  127. package/dist/src/nowiki/list.js +0 -109
  128. package/dist/src/nowiki/listBase.d.ts +0 -5
  129. package/dist/src/nowiki/listBase.js +0 -61
  130. package/dist/src/nowiki/noinclude.d.ts +0 -10
  131. package/dist/src/nowiki/noinclude.js +0 -23
  132. package/dist/src/nowiki/quote.d.ts +0 -14
  133. package/dist/src/nowiki/quote.js +0 -131
  134. package/dist/src/onlyinclude.d.ts +0 -16
  135. package/dist/src/onlyinclude.js +0 -57
  136. package/dist/src/paramTag/index.d.ts +0 -37
  137. package/dist/src/paramTag/index.js +0 -77
  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 -70
  141. package/dist/src/parameter.js +0 -264
  142. package/dist/src/pre.d.ts +0 -31
  143. package/dist/src/pre.js +0 -59
  144. package/dist/src/redirect.d.ts +0 -34
  145. package/dist/src/redirect.js +0 -119
  146. package/dist/src/syntax.d.ts +0 -19
  147. package/dist/src/syntax.js +0 -86
  148. package/dist/src/table/base.d.ts +0 -27
  149. package/dist/src/table/base.js +0 -81
  150. package/dist/src/table/index.d.ts +0 -242
  151. package/dist/src/table/index.js +0 -498
  152. package/dist/src/table/td.d.ts +0 -86
  153. package/dist/src/table/td.js +0 -355
  154. package/dist/src/table/tr.d.ts +0 -32
  155. package/dist/src/table/tr.js +0 -58
  156. package/dist/src/table/trBase.d.ts +0 -53
  157. package/dist/src/table/trBase.js +0 -156
  158. package/dist/src/tagPair/ext.d.ts +0 -32
  159. package/dist/src/tagPair/ext.js +0 -203
  160. package/dist/src/tagPair/include.d.ts +0 -35
  161. package/dist/src/tagPair/include.js +0 -74
  162. package/dist/src/tagPair/index.d.ts +0 -27
  163. package/dist/src/tagPair/index.js +0 -128
  164. package/dist/src/transclude.d.ts +0 -166
  165. package/dist/src/transclude.js +0 -584
  166. package/dist/util/constants.js +0 -27
  167. package/dist/util/debug.js +0 -81
  168. package/dist/util/diff.js +0 -83
  169. package/dist/util/lint.js +0 -31
  170. package/dist/util/string.js +0 -60
  171. package/errors/README +0 -1
  172. package/printed/README +0 -1
@@ -1,190 +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 string_1 = require("../util/string");
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 = new Set([
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
- ['[', '['],
40
- [']', ']'],
41
- ['(', '('],
42
- [')', ')'],
43
- ['"', '"'],
44
- [`'`, '''],
45
- [':', ':'],
46
- ['\\', '\'],
47
- ['&', '&'],
48
- ];
49
- const 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.replace(new RegExp((0, string_1.escapeRegExp)(`\\${c}`), 'gu'), 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.replace(new RegExp(escaped, 'gu'), 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
- * @throws `SyntaxError` 非法的选择器
89
- */
90
- const pushSimple = (index) => {
91
- const str = sanitized.slice(0, index).trim();
92
- if (!str) {
93
- return;
94
- }
95
- const pieces = str.split(/(?=[:#])/u);
96
- for (let i = 0; i < pieces.length; i++) {
97
- const piece = pieces[i];
98
- if (!/^[:#]/u.test(piece)) {
99
- if (step.length > 0) {
100
- throw new SyntaxError(`Invalid selector!\n${selector}\nType selectors must come first.`);
101
- }
102
- else {
103
- step.push(piece);
104
- }
105
- }
106
- else if (piece.startsWith(':')) {
107
- if (simplePseudos.has(piece.slice(1))) {
108
- step.push(piece);
109
- }
110
- else if (pieces[i - 1]?.startsWith('#')) {
111
- pieces[i - 1] += piece;
112
- pieces.splice(i, 1);
113
- i--;
114
- }
115
- else {
116
- throw new SyntaxError(`Non-existing pseudo selector!\n${desanitize(piece)}`);
117
- }
118
- }
119
- }
120
- step.push(...pieces.filter(piece => piece.startsWith('#')).map(piece => desanitize(piece)));
121
- };
122
- /**
123
- * 检查是否需要通用选择器
124
- * @throws `SyntaxError` 非法的选择器
125
- */
126
- const needUniversal = () => {
127
- if (step.length === 0) {
128
- throw new SyntaxError(`Invalid selector!\n${selector}\nYou may need the universal selector '*'.`);
129
- }
130
- };
131
- while (mt) {
132
- let { 0: syntax, index } = mt;
133
- if (syntax.trim() === '') {
134
- index += syntax.length;
135
- const char = sanitized[index];
136
- syntax = grouping.has(char) ? char : '';
137
- }
138
- if (syntax === ',') { // 情形1:并列
139
- pushSimple(index);
140
- needUniversal();
141
- condition = [[]];
142
- [step] = condition;
143
- stack.push(condition);
144
- }
145
- else if (combinator.has(syntax)) { // 情形2:关系
146
- pushSimple(index);
147
- needUniversal();
148
- step.relation = syntax;
149
- step = [];
150
- condition.push(step);
151
- }
152
- else if (syntax === '[') { // 情形3:属性开启
153
- pushSimple(index);
154
- regex = attributeRegex;
155
- }
156
- else if (syntax.endsWith(']')) { // 情形4:属性闭合
157
- mt[3] &&= desanitize(deQuote(mt[3]));
158
- step.push(mt.slice(1));
159
- regex = regularRegex;
160
- }
161
- else if (syntax === '(') { // 情形5:伪选择器开启
162
- const i = sanitized.lastIndexOf(':', index), pseudo = sanitized.slice(i + 1, index);
163
- if (i === -1 || !complexPseudos.has(pseudo)) {
164
- throw new SyntaxError(`Non-existing pseudo selector!\n${desanitize(sanitized)}`);
165
- }
166
- pushSimple(i);
167
- step.push(pseudo); // 临时存放复杂伪选择器
168
- regex = functionRegex;
169
- }
170
- else { // 情形6:伪选择器闭合
171
- mt.push(step.pop());
172
- mt[1] &&= deQuote(mt[1]);
173
- step.push(mt.slice(1));
174
- regex = regularRegex;
175
- }
176
- sanitized = sanitized.slice(index + syntax.length);
177
- if (grouping.has(syntax)) {
178
- sanitized = sanitized.trim();
179
- }
180
- mt = regex.exec(sanitized);
181
- }
182
- if (regex === regularRegex) {
183
- pushSimple(Infinity);
184
- needUniversal();
185
- return stack;
186
- }
187
- throw new SyntaxError(`Unclosed '${regex === attributeRegex ? '[' : '('}' in the selector!\n${desanitize(sanitized)}`);
188
- };
189
- exports.parseSelector = parseSelector;
190
- 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(String(lastChild) + 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
- // eslint-disable-next-line @stylistic/operator-linebreak
72
- const matches = /^(?:(\|\}|\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 createTd = (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
- createTd(top);
113
- ({ lastIndex } = regex);
114
- [lastSyntax] = mt;
115
- mt = regex.exec(attr);
116
- }
117
- stack.push(top, createTd(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,58 +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 type = "arg";
13
- readonly name: string;
14
- readonly childNodes: readonly [AtomToken] | readonly [AtomToken, Token, ...HiddenToken[]];
15
- abstract get firstChild(): AtomToken;
16
- abstract get lastChild(): Token;
17
- abstract get children(): [AtomToken] | [AtomToken, Token, ...HiddenToken[]];
18
- abstract get firstElementChild(): AtomToken;
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, re?: RegExp): LintError[];
29
- /** @override */
30
- print(): string;
31
- /** @override */
32
- json(): AST;
33
- /** @override */
34
- cloneNode(): this;
35
- /** 移除无效部分 */
36
- removeRedundant(): void;
37
- /**
38
- * @override
39
- * @param i 移除位置
40
- */
41
- removeAt(i: number): Token;
42
- /**
43
- * @override
44
- * @param token 待插入的子节点
45
- * @param i 插入位置
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,214 +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 index_1 = require("../index");
9
- const index_2 = 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_2.Token {
17
- type = 'arg';
18
- /* NOT FOR BROWSER END */
19
- /** 预设值 */
20
- get default() {
21
- return this.childNodes[1]?.text() ?? false;
22
- }
23
- /* NOT FOR BROWSER */
24
- set default(value) {
25
- this.setDefault(value);
26
- }
27
- /* NOT FOR BROWSER END */
28
- /** @param parts 以'|'分隔的各部分 */
29
- constructor(parts, config = index_1.default.getConfig(), accum = []) {
30
- super(undefined, config, accum, {
31
- AtomToken: 0, Token: 1, HiddenToken: '2:',
32
- });
33
- for (let i = 0; i < parts.length; i++) {
34
- if (i === 0) {
35
- const token = new atom_1.AtomToken(parts[i], 'arg-name', config, accum, {
36
- 'Stage-2': ':', '!HeadingToken': '',
37
- });
38
- super.insertAt(token);
39
- }
40
- else if (i > 1) {
41
- const token = new hidden_1.HiddenToken(parts[i], config, accum, {
42
- 'Stage-2': ':', '!HeadingToken': '',
43
- });
44
- super.insertAt(token);
45
- }
46
- else {
47
- const token = new index_2.Token(parts[i], config, accum);
48
- token.type = 'arg-default';
49
- token.setAttribute('stage', 2);
50
- super.insertAt(token);
51
- }
52
- }
53
- /* NOT FOR BROWSER */
54
- this.protectChildren(0);
55
- }
56
- /** @private */
57
- toString() {
58
- return `{{{${super.toString('|')}}}}`;
59
- }
60
- /** @override */
61
- text() {
62
- return `{{{${(0, string_1.text)(this.childNodes.slice(0, 2), '|')}}}}`;
63
- }
64
- /** @private */
65
- getAttribute(key) {
66
- return key === 'padding' ? 3 : super.getAttribute(key);
67
- }
68
- /** @private */
69
- getGaps() {
70
- return 1;
71
- }
72
- /** @override */
73
- lint(start = this.getAbsoluteIndex(), re) {
74
- const { childNodes: [argName, argDefault, ...rest] } = this;
75
- if (!this.getAttribute('include')) {
76
- const e = (0, lint_1.generateForSelf)(this, { start }, 'no-arg', 'unexpected template argument');
77
- if (argDefault) {
78
- e.fix = {
79
- range: [start, e.endIndex],
80
- text: argDefault.text(),
81
- };
82
- }
83
- return [e];
84
- }
85
- const errors = argName.lint(start + 3, re);
86
- if (argDefault) {
87
- errors.push(...argDefault.lint(start + 4 + String(argName).length, re));
88
- }
89
- if (rest.length > 0) {
90
- const rect = { start, ...this.getRootNode().posFromIndex(start) };
91
- errors.push(...rest.map(child => {
92
- const e = (0, lint_1.generateForChild)(child, rect, 'no-ignored', 'invisible content inside triple braces');
93
- e.startIndex--;
94
- e.startCol--;
95
- e.suggestions = [
96
- {
97
- desc: 'remove',
98
- range: [e.startIndex, e.endIndex],
99
- text: '',
100
- },
101
- {
102
- desc: 'escape',
103
- range: [e.startIndex, e.startIndex + 1],
104
- text: '{{!}}',
105
- },
106
- ];
107
- return e;
108
- }));
109
- }
110
- return errors;
111
- }
112
- /** @override */
113
- print() {
114
- return super.print({ pre: '{{{', post: '}}}', sep: '|' });
115
- }
116
- /** @override */
117
- json() {
118
- const json = super.json();
119
- json['default'] = this.default;
120
- return json;
121
- }
122
- /* NOT FOR BROWSER */
123
- /** @override */
124
- cloneNode() {
125
- const [name, ...cloned] = this.cloneChildNodes();
126
- return debug_1.Shadow.run(() => {
127
- // @ts-expect-error abstract class
128
- const token = new ArgToken([''], this.getAttribute('config'));
129
- token.firstChild.safeReplaceWith(name);
130
- token.append(...cloned);
131
- token.afterBuild();
132
- return token;
133
- });
134
- }
135
- /** 设置name */
136
- #setName() {
137
- this.setAttribute('name', this.firstChild.text().trim());
138
- }
139
- /** @private */
140
- afterBuild() {
141
- this.#setName();
142
- const /** @implements */ argListener = ({ prevTarget }) => {
143
- if (prevTarget === this.firstChild) {
144
- this.#setName();
145
- }
146
- };
147
- this.addEventListener(['remove', 'insert', 'replace', 'text'], argListener);
148
- }
149
- /** 移除无效部分 */
150
- removeRedundant() {
151
- debug_1.Shadow.run(() => {
152
- for (let i = this.length - 1; i > 1; i--) {
153
- super.removeAt(i);
154
- }
155
- });
156
- }
157
- /**
158
- * @override
159
- * @param i 移除位置
160
- */
161
- removeAt(i) {
162
- if (i === 1) {
163
- this.removeRedundant();
164
- }
165
- return super.removeAt(i);
166
- }
167
- /**
168
- * @override
169
- * @param token 待插入的子节点
170
- * @param i 插入位置
171
- */
172
- insertAt(token, i = this.length) {
173
- i += i < 0 ? this.length : 0;
174
- if (i > 1) {
175
- this.constructorError('不可插入多余的子节点');
176
- }
177
- else if (typeof token === 'string') {
178
- this.constructorError('不可插入文本节点');
179
- }
180
- super.insertAt(token, i);
181
- if (i === 1) {
182
- token.type = 'arg-default';
183
- }
184
- return token;
185
- }
186
- /**
187
- * 设置参数名
188
- * @param name 新参数名
189
- */
190
- setName(name) {
191
- const { childNodes } = index_1.default.parse(name, this.getAttribute('include'), 2, this.getAttribute('config'));
192
- this.firstChild.replaceChildren(...childNodes);
193
- }
194
- /**
195
- * 设置预设值
196
- * @param value 预设值
197
- */
198
- setDefault(value) {
199
- if (value === false) {
200
- this.removeAt(1);
201
- return;
202
- }
203
- const root = index_1.default.parse(value, this.getAttribute('include'), undefined, this.getAttribute('config')), { childNodes: [, oldDefault] } = this;
204
- if (oldDefault) {
205
- oldDefault.replaceChildren(...root.childNodes);
206
- }
207
- else {
208
- root.type = 'arg-default';
209
- this.insertAt(root);
210
- }
211
- }
212
- }
213
- exports.ArgToken = ArgToken;
214
- constants_1.classes['ArgToken'] = __filename;
@@ -1,12 +0,0 @@
1
- import 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 index_1 = require("../index");
7
- const index_2 = require("./index");
8
- /** 不会被继续解析的plain Token */
9
- class AtomToken extends index_2.Token {
10
- /** @class */
11
- constructor(wikitext, type, config = index_1.default.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;
@@ -1,71 +0,0 @@
1
- import Parser from '../index';
2
- import { Token } from './index';
3
- import { AtomToken } from './atom';
4
- import type { LintError } from '../base';
5
- import type { AttributesToken } from '../internal';
6
- export type AttributeTypes = 'ext-attr' | 'html-attr' | 'table-attr';
7
- /**
8
- * 扩展和HTML标签属性
9
- * @classdesc `{childNodes: [AtomToken, Token|AtomToken]}`
10
- */
11
- export declare abstract class AttributeToken extends Token {
12
- #private;
13
- type: AttributeTypes;
14
- readonly name: string;
15
- readonly childNodes: readonly [AtomToken, Token];
16
- abstract get firstChild(): AtomToken;
17
- abstract get lastChild(): Token;
18
- abstract get parentNode(): AttributesToken | undefined;
19
- abstract get nextSibling(): AtomToken | this | undefined;
20
- abstract get previousSibling(): AtomToken | this | undefined;
21
- abstract get children(): [AtomToken, Token];
22
- abstract get firstElementChild(): AtomToken;
23
- abstract get lastElementChild(): Token;
24
- abstract get parentElement(): AttributesToken | undefined;
25
- abstract get nextElementSibling(): AtomToken | this | undefined;
26
- abstract get previousElementSibling(): AtomToken | this | undefined;
27
- /** 标签名 */
28
- get tag(): string;
29
- /** 引号是否匹配 */
30
- get balanced(): boolean;
31
- set balanced(value: boolean);
32
- /** getValue()的getter */
33
- get value(): string | true;
34
- set value(value: string | true);
35
- /**
36
- * @param type 标签类型
37
- * @param tag 标签名
38
- * @param key 属性名
39
- * @param equal 等号
40
- * @param value 属性值
41
- * @param quotes 引号
42
- */
43
- constructor(type: AttributeTypes, tag: string, key: string, equal?: string, value?: string, quotes?: readonly [string?, string?], config?: Parser.Config, accum?: Token[]);
44
- /** @override */
45
- text(): string;
46
- /** @override */
47
- lint(start?: number, re?: RegExp): LintError[];
48
- /** 获取属性值 */
49
- getValue(): string | true;
50
- /** @override */
51
- print(): string;
52
- /** @override */
53
- cloneNode(): this;
54
- /** 转义等号 */
55
- escape(): void;
56
- /** 闭合引号 */
57
- close(): void;
58
- /**
59
- * 设置属性值
60
- * @param value 参数值
61
- * @throws `RangeError` 扩展标签属性不能包含 ">"
62
- * @throws `RangeError` 同时包含单引号和双引号
63
- */
64
- setValue(value: string | boolean): void;
65
- /**
66
- * 修改属性名
67
- * @param key 新属性名
68
- * @throws `Error` title和alt属性不能更名
69
- */
70
- rename(key: string): void;
71
- }