wikiparser-node 1.0.0-beta.3 → 1.0.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 (146) hide show
  1. package/README.md +10 -9
  2. package/bundle/bundle.min.js +37 -0
  3. package/config/llwiki.json +1 -35
  4. package/config/minimum.json +136 -0
  5. package/config/moegirl.json +1 -44
  6. package/config/zhwiki.json +1 -466
  7. package/extensions/dist/base.js +105 -0
  8. package/extensions/dist/editor.js +172 -0
  9. package/extensions/dist/highlight.js +46 -0
  10. package/extensions/dist/lint.js +43 -0
  11. package/extensions/editor.css +63 -0
  12. package/extensions/ui.css +119 -0
  13. package/package.json +35 -20
  14. package/config/.schema.json +0 -160
  15. package/dist/index.d.ts +0 -62
  16. package/dist/index.js +0 -305
  17. package/dist/internal.d.ts +0 -44
  18. package/dist/lib/element.d.ts +0 -186
  19. package/dist/lib/element.js +0 -659
  20. package/dist/lib/node.d.ts +0 -178
  21. package/dist/lib/node.js +0 -458
  22. package/dist/lib/range.d.ts +0 -132
  23. package/dist/lib/range.js +0 -387
  24. package/dist/lib/ranges.d.ts +0 -28
  25. package/dist/lib/ranges.js +0 -125
  26. package/dist/lib/text.d.ts +0 -78
  27. package/dist/lib/text.js +0 -227
  28. package/dist/lib/title.d.ts +0 -33
  29. package/dist/lib/title.js +0 -110
  30. package/dist/mixin/attributesParent.js +0 -93
  31. package/dist/mixin/fixed.js +0 -32
  32. package/dist/mixin/hidden.js +0 -23
  33. package/dist/mixin/singleLine.js +0 -26
  34. package/dist/mixin/sol.js +0 -44
  35. package/dist/parser/braces.js +0 -125
  36. package/dist/parser/commentAndExt.js +0 -58
  37. package/dist/parser/converter.js +0 -38
  38. package/dist/parser/externalLinks.js +0 -28
  39. package/dist/parser/hrAndDoubleUnderscore.js +0 -40
  40. package/dist/parser/html.js +0 -38
  41. package/dist/parser/links.js +0 -94
  42. package/dist/parser/list.js +0 -61
  43. package/dist/parser/magicLinks.js +0 -39
  44. package/dist/parser/quotes.js +0 -67
  45. package/dist/parser/selector.js +0 -165
  46. package/dist/parser/table.js +0 -117
  47. package/dist/src/arg.d.ts +0 -77
  48. package/dist/src/arg.js +0 -199
  49. package/dist/src/atom.d.ts +0 -11
  50. package/dist/src/atom.js +0 -24
  51. package/dist/src/attribute.d.ts +0 -106
  52. package/dist/src/attribute.js +0 -436
  53. package/dist/src/attributes.d.ts +0 -119
  54. package/dist/src/attributes.js +0 -366
  55. package/dist/src/converter.d.ts +0 -75
  56. package/dist/src/converter.js +0 -141
  57. package/dist/src/converterFlags.d.ts +0 -107
  58. package/dist/src/converterFlags.js +0 -238
  59. package/dist/src/converterRule.d.ts +0 -96
  60. package/dist/src/converterRule.js +0 -255
  61. package/dist/src/extLink.d.ts +0 -63
  62. package/dist/src/extLink.js +0 -157
  63. package/dist/src/gallery.d.ts +0 -70
  64. package/dist/src/gallery.js +0 -137
  65. package/dist/src/heading.d.ts +0 -82
  66. package/dist/src/heading.js +0 -135
  67. package/dist/src/hidden.d.ts +0 -19
  68. package/dist/src/hidden.js +0 -26
  69. package/dist/src/html.d.ts +0 -113
  70. package/dist/src/html.js +0 -245
  71. package/dist/src/imageParameter.d.ts +0 -82
  72. package/dist/src/imageParameter.js +0 -256
  73. package/dist/src/imagemap.d.ts +0 -77
  74. package/dist/src/imagemap.js +0 -169
  75. package/dist/src/imagemapLink.d.ts +0 -48
  76. package/dist/src/imagemapLink.js +0 -43
  77. package/dist/src/index.d.ts +0 -156
  78. package/dist/src/index.js +0 -819
  79. package/dist/src/link/base.d.ts +0 -69
  80. package/dist/src/link/base.js +0 -231
  81. package/dist/src/link/category.d.ts +0 -14
  82. package/dist/src/link/category.js +0 -28
  83. package/dist/src/link/file.d.ts +0 -105
  84. package/dist/src/link/file.js +0 -269
  85. package/dist/src/link/galleryImage.d.ts +0 -37
  86. package/dist/src/link/galleryImage.js +0 -100
  87. package/dist/src/link/index.d.ts +0 -50
  88. package/dist/src/link/index.js +0 -134
  89. package/dist/src/magicLink.d.ts +0 -46
  90. package/dist/src/magicLink.js +0 -131
  91. package/dist/src/nested.d.ts +0 -47
  92. package/dist/src/nested.js +0 -92
  93. package/dist/src/nowiki/base.d.ts +0 -38
  94. package/dist/src/nowiki/base.js +0 -31
  95. package/dist/src/nowiki/comment.d.ts +0 -42
  96. package/dist/src/nowiki/comment.js +0 -64
  97. package/dist/src/nowiki/dd.d.ts +0 -22
  98. package/dist/src/nowiki/dd.js +0 -46
  99. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -35
  100. package/dist/src/nowiki/doubleUnderscore.js +0 -48
  101. package/dist/src/nowiki/hr.d.ts +0 -30
  102. package/dist/src/nowiki/hr.js +0 -36
  103. package/dist/src/nowiki/index.d.ts +0 -19
  104. package/dist/src/nowiki/index.js +0 -23
  105. package/dist/src/nowiki/list.d.ts +0 -16
  106. package/dist/src/nowiki/list.js +0 -13
  107. package/dist/src/nowiki/noinclude.d.ts +0 -21
  108. package/dist/src/nowiki/noinclude.js +0 -24
  109. package/dist/src/nowiki/quote.d.ts +0 -27
  110. package/dist/src/nowiki/quote.js +0 -58
  111. package/dist/src/onlyinclude.d.ts +0 -38
  112. package/dist/src/onlyinclude.js +0 -66
  113. package/dist/src/paramTag/index.d.ts +0 -50
  114. package/dist/src/paramTag/index.js +0 -78
  115. package/dist/src/paramTag/inputbox.d.ts +0 -7
  116. package/dist/src/paramTag/inputbox.js +0 -21
  117. package/dist/src/parameter.d.ts +0 -95
  118. package/dist/src/parameter.js +0 -204
  119. package/dist/src/pre.d.ts +0 -27
  120. package/dist/src/pre.js +0 -44
  121. package/dist/src/syntax.d.ts +0 -22
  122. package/dist/src/syntax.js +0 -67
  123. package/dist/src/table/base.d.ts +0 -60
  124. package/dist/src/table/base.js +0 -80
  125. package/dist/src/table/index.d.ts +0 -247
  126. package/dist/src/table/index.js +0 -783
  127. package/dist/src/table/td.d.ts +0 -119
  128. package/dist/src/table/td.js +0 -268
  129. package/dist/src/table/tr.d.ts +0 -31
  130. package/dist/src/table/tr.js +0 -50
  131. package/dist/src/table/trBase.d.ts +0 -62
  132. package/dist/src/table/trBase.js +0 -157
  133. package/dist/src/tagPair/ext.d.ts +0 -54
  134. package/dist/src/tagPair/ext.js +0 -150
  135. package/dist/src/tagPair/include.d.ts +0 -43
  136. package/dist/src/tagPair/include.js +0 -43
  137. package/dist/src/tagPair/index.d.ts +0 -57
  138. package/dist/src/tagPair/index.js +0 -113
  139. package/dist/src/transclude.d.ts +0 -200
  140. package/dist/src/transclude.js +0 -732
  141. package/dist/util/debug.js +0 -42
  142. package/dist/util/diff.js +0 -71
  143. package/dist/util/lint.js +0 -38
  144. package/dist/util/string.js +0 -74
  145. package/errors/README +0 -1
  146. package/printed/README +0 -1
@@ -1,165 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseSelector = void 0;
4
- const index_1 = require("../index");
5
- const simplePseudos = new Set([
6
- 'root',
7
- 'first-child',
8
- 'first-of-type',
9
- 'last-child',
10
- 'last-of-type',
11
- 'only-child',
12
- 'only-of-type',
13
- 'empty',
14
- 'parent',
15
- 'header',
16
- 'hidden',
17
- 'visible',
18
- 'only-whitespace',
19
- 'local-link',
20
- 'read-only',
21
- 'read-write',
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
- ['[', '['],
40
- [']', ']'],
41
- ['(', '('],
42
- [')', ')'],
43
- ['"', '"'],
44
- [`'`, '''],
45
- [':', ':'],
46
- ['\\', '\'],
47
- ['&', '&'],
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) => {
75
- const quotes = /^(["']).*\1$/u.exec(val)?.[1];
76
- return quotes ? val.slice(1, -1) : val.trim();
77
- };
78
- /**
79
- * 解析简单伪选择器
80
- * @param step 当前顶部
81
- * @param str 不含属性和复杂伪选择器的语句
82
- * @throws `SyntaxError` 非法的选择器
83
- */
84
- const pushSimple = (step, str) => {
85
- const pieces = str.trim().split(':'),
86
- // eslint-disable-next-line unicorn/explicit-length-check
87
- i = pieces.slice(1).findIndex(pseudo => simplePseudos.has(pseudo)) + 1 || pieces.length;
88
- if (pieces.slice(i).some(pseudo => !simplePseudos.has(pseudo))) {
89
- throw new SyntaxError(`非法的选择器!\n${str}\n可能需要将':'转义为'\\:'。`);
90
- }
91
- step.push(desanitize(pieces.slice(0, i).join(':')), ...pieces.slice(i).map(piece => `:${piece}`));
92
- };
93
- /**
94
- * 解析选择器
95
- * @param selector
96
- * @throws `SyntaxError` 非法的选择器
97
- */
98
- const parseSelector = (selector) => {
99
- const s = selector.trim(), stack = [[[]]];
100
- let sanitized = sanitize(s), regex = regularRegex, mt = regex.exec(sanitized), [condition] = stack, [step] = condition;
101
- while (mt) {
102
- let { 0: syntax, index } = mt;
103
- if (syntax.trim() === '') {
104
- index += syntax.length;
105
- const char = sanitized[index];
106
- syntax = grouping.has(char) ? char : '';
107
- }
108
- if (syntax === ',') { // 情形1:并列
109
- pushSimple(step, sanitized.slice(0, index));
110
- condition = [[]];
111
- [step] = condition;
112
- stack.push(condition);
113
- }
114
- else if (combinator.has(syntax)) { // 情形2:关系
115
- pushSimple(step, sanitized.slice(0, index));
116
- if (!step.some(Boolean)) {
117
- throw new SyntaxError(`非法的选择器!\n${s}\n可能需要通用选择器'*'。`);
118
- }
119
- step.relation = syntax;
120
- step = [];
121
- condition.push(step);
122
- }
123
- else if (syntax === '[') { // 情形3:属性开启
124
- pushSimple(step, sanitized.slice(0, index));
125
- regex = attributeRegex;
126
- }
127
- else if (syntax.endsWith(']')) { // 情形4:属性闭合
128
- mt[3] &&= desanitize(deQuote(mt[3]));
129
- step.push(mt.slice(1));
130
- regex = regularRegex;
131
- }
132
- else if (syntax === '(') { // 情形5:伪选择器开启
133
- const pseudoExec = pseudoRegex.exec(sanitized.slice(0, index));
134
- if (!pseudoExec) {
135
- throw new SyntaxError(`非法的选择器!\n${desanitize(sanitized)}\n请检查伪选择器是否存在。`);
136
- }
137
- pushSimple(step, sanitized.slice(0, pseudoExec.index));
138
- step.push(pseudoExec[1]); // 临时存放复杂伪选择器
139
- regex = functionRegex;
140
- }
141
- else { // 情形6:伪选择器闭合
142
- const pseudo = step.pop();
143
- mt.push(pseudo);
144
- mt[1] &&= deQuote(mt[1]);
145
- step.push(mt.slice(1));
146
- regex = regularRegex;
147
- }
148
- sanitized = sanitized.slice(index + syntax.length);
149
- if (grouping.has(syntax)) {
150
- sanitized = sanitized.trim();
151
- }
152
- mt = regex.exec(sanitized);
153
- }
154
- if (regex === regularRegex) {
155
- pushSimple(step, sanitized);
156
- const pseudos = new Set(stack.flat(2).filter(e => typeof e === 'string' && e.startsWith(':')));
157
- if (pseudos.size > 0) {
158
- index_1.default.warn('检测到伪选择器,请确认是否需要将":"转义成"\\:"。', pseudos);
159
- }
160
- return stack;
161
- }
162
- throw new SyntaxError(`非法的选择器!\n${s}\n检测到未闭合的'${regex === attributeRegex ? '[' : '('}'`);
163
- };
164
- exports.parseSelector = parseSelector;
165
- index_1.default.parsers['parseSelector'] = __filename;
@@ -1,117 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseTable = void 0;
4
- const index_1 = require("../index");
5
- const src_1 = require("../src");
6
- const table_1 = require("../src/table");
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
- * 解析表格,注意`tr`和`td`包含开头的换行
12
- * @param {Token & {firstChild: AstText}} root 根节点
13
- * @param config
14
- * @param accum
15
- */
16
- const parseTable = ({ firstChild: { data }, type, name }, config = index_1.default.getConfig(), accum = []) => {
17
- const stack = [], lines = data.split('\n');
18
- let out = type === 'root' || type === 'parameter-value' || type === 'ext-inner' && name === 'poem'
19
- ? ''
20
- : `\n${lines.shift()}`;
21
- /**
22
- * 向表格中插入纯文本
23
- * @param str 待插入的文本
24
- * @param top 当前解析的表格或表格行
25
- */
26
- const push = (str, top) => {
27
- if (!top) {
28
- out += str;
29
- return;
30
- }
31
- const { lastChild } = top;
32
- if (lastChild.constructor === src_1.Token) {
33
- lastChild.setText(String(lastChild) + str);
34
- }
35
- else {
36
- const token = new src_1.Token(str, config, true, accum);
37
- token.type = 'table-inter';
38
- top.insertAt(token.setAttribute('stage', 3));
39
- }
40
- };
41
- for (const outLine of lines) {
42
- let top = stack.pop();
43
- 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
44
- .exec(line);
45
- if (matchesStart) {
46
- while (top && top.type !== 'td') {
47
- top = stack.pop();
48
- }
49
- const [, indent, moreSpaces, tableSyntax, attr] = matchesStart;
50
- if (indent) {
51
- // @ts-expect-error abstract class
52
- new dd_1.DdToken(indent, config, accum);
53
- }
54
- push(`\n${spaces}${indent && `\0${accum.length - 1}d\x7F`}${moreSpaces}\0${accum.length}b\x7F`, top);
55
- // @ts-expect-error abstract class
56
- const table = new table_1.TableToken(tableSyntax, attr, config, accum);
57
- stack.push(...top ? [top] : [], table);
58
- continue;
59
- }
60
- else if (!top) {
61
- out += `\n${outLine}`;
62
- continue;
63
- }
64
- // eslint-disable-next-line operator-linebreak
65
- const matches = /^(?:(\|\}|\0\d+!\x7F\}|\0\d+\}\x7F)|(\|-+|\0\d+!\x7F-+|\0\d+-\x7F-*)(?!-)|(!|(?:\||\0\d+!\x7F)\+?))(.*)$/u
66
- .exec(line);
67
- if (!matches) {
68
- push(`\n${outLine}`, top);
69
- stack.push(top);
70
- continue;
71
- }
72
- const [, closing, row, cell, attr] = matches;
73
- if (closing) {
74
- while (top.type !== 'table') {
75
- top = stack.pop();
76
- }
77
- top.close(`\n${spaces}${closing}`, true);
78
- push(attr, stack.at(-1));
79
- }
80
- else if (row) {
81
- if (top.type === 'td') {
82
- top = stack.pop();
83
- }
84
- if (top.type === 'tr') {
85
- top = stack.pop();
86
- }
87
- // @ts-expect-error abstract class
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 === '!'
97
- ? /!!|(?:\||\0\d+!\x7F){2}|\0\d+\+\x7F/gu
98
- : /(?:\||\0\d+!\x7F){2}|\0\d+\+\x7F/gu;
99
- let mt = regex.exec(attr), lastIndex = 0, lastSyntax = `\n${spaces}${cell}`;
100
- while (mt) {
101
- // @ts-expect-error abstract class
102
- const td = new td_1.TdToken(lastSyntax, attr.slice(lastIndex, mt.index), config, accum);
103
- top.insertAt(td);
104
- ({ lastIndex } = regex);
105
- [lastSyntax] = mt;
106
- mt = regex.exec(attr);
107
- }
108
- // @ts-expect-error abstract class
109
- const td = new td_1.TdToken(lastSyntax, attr.slice(lastIndex), config, accum);
110
- stack.push(top, td);
111
- top.insertAt(td);
112
- }
113
- }
114
- return out.slice(1);
115
- };
116
- exports.parseTable = parseTable;
117
- index_1.default.parsers['parseTable'] = __filename;
package/dist/src/arg.d.ts DELETED
@@ -1,77 +0,0 @@
1
- import { Token } from '.';
2
- import { AtomToken } from './atom';
3
- import { HiddenToken } from './hidden';
4
- import type { LintError } from '../index';
5
- /**
6
- * `{{{}}}`包裹的参数
7
- * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
8
- */
9
- export declare abstract class ArgToken extends Token {
10
- /** @browser */
11
- readonly type = "arg";
12
- name: string;
13
- childNodes: [AtomToken] | [AtomToken, Token, ...HiddenToken[]];
14
- abstract get firstChild(): AtomToken;
15
- abstract get firstElementChild(): AtomToken;
16
- abstract get lastChild(): Token;
17
- abstract get lastElementChild(): Token;
18
- /**
19
- * 预设值
20
- * @browser
21
- */
22
- get default(): string | false;
23
- /**
24
- * @browser
25
- * @param parts 以'|'分隔的各部分
26
- */
27
- constructor(parts: string[], config?: import("../index").Config, accum?: Token[]);
28
- /**
29
- * @override
30
- * @browser
31
- */
32
- toString(selector?: string): string;
33
- /**
34
- * @override
35
- * @browser
36
- */
37
- text(): string;
38
- /**
39
- * @override
40
- * @browser
41
- */
42
- print(): string;
43
- /**
44
- * @override
45
- * @browser
46
- */
47
- lint(start?: number): LintError[];
48
- /** @override */
49
- cloneNode(): this;
50
- /** 移除无效部分 */
51
- removeRedundant(): void;
52
- /**
53
- * @override
54
- * @param i 移除位置
55
- */
56
- removeAt(i: number): Token;
57
- /**
58
- * @override
59
- * @param token 待插入的子节点
60
- * @param i 插入位置
61
- * @throws `RangeError` 不可插入多余子节点
62
- * @throws `TypeError` 不可插入文本节点
63
- */
64
- insertAt<T extends Token>(token: T, i?: number): T;
65
- /**
66
- * 设置参数名
67
- * @param name 新参数名
68
- * @throws `SyntaxError` 非法的参数名
69
- */
70
- setName(name: string): void;
71
- /**
72
- * 设置预设值
73
- * @param value 预设值
74
- * @throws `SyntaxError` 非法的参数预设值
75
- */
76
- setDefault(value: string): void;
77
- }
package/dist/src/arg.js DELETED
@@ -1,199 +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 index_1 = require("../index");
7
- const _1 = require(".");
8
- const atom_1 = require("./atom");
9
- const hidden_1 = require("./hidden");
10
- /**
11
- * `{{{}}}`包裹的参数
12
- * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
13
- */
14
- class ArgToken extends _1.Token {
15
- /** @browser */
16
- type = 'arg';
17
- /**
18
- * 预设值
19
- * @browser
20
- */
21
- get default() {
22
- return this.childNodes[1]?.text() ?? false;
23
- }
24
- /**
25
- * @browser
26
- * @param parts 以'|'分隔的各部分
27
- */
28
- constructor(parts, config = index_1.default.getConfig(), accum = []) {
29
- super(undefined, config, true, 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 _1.Token(parts[i], config, true, accum);
47
- token.type = 'arg-default';
48
- super.insertAt(token.setAttribute('stage', 2));
49
- }
50
- }
51
- this.protectChildren(0);
52
- }
53
- /**
54
- * @override
55
- * @browser
56
- */
57
- toString(selector) {
58
- return selector && this.matches(selector) ? '' : `{{{${super.toString(selector, '|')}}}}`;
59
- }
60
- /**
61
- * @override
62
- * @browser
63
- */
64
- text() {
65
- return `{{{${(0, string_1.text)(this.childNodes.slice(0, 2), '|')}}}}`;
66
- }
67
- /** @private */
68
- getPadding() {
69
- return 3;
70
- }
71
- /** @private */
72
- getGaps(i) {
73
- return i < this.length - 1 ? 1 : 0;
74
- }
75
- /**
76
- * @override
77
- * @browser
78
- */
79
- print() {
80
- return super.print({ pre: '{{{', post: '}}}', sep: '|' });
81
- }
82
- /**
83
- * @override
84
- * @browser
85
- */
86
- lint(start = this.getAbsoluteIndex()) {
87
- if (!this.getAttribute('include')) {
88
- return [(0, lint_1.generateForSelf)(this, { start }, 'unexpected template argument')];
89
- }
90
- const { childNodes: [argName, argDefault, ...rest] } = this, errors = argName.lint(start + 3);
91
- if (argDefault) {
92
- errors.push(...argDefault.lint(start + 4 + String(argName).length));
93
- }
94
- if (rest.length > 0) {
95
- const rect = { start, ...this.getRootNode().posFromIndex(start) };
96
- errors.push(...rest.map(child => {
97
- const error = (0, lint_1.generateForChild)(child, rect, 'invisible content inside triple braces'), { startIndex, startCol, excerpt } = error;
98
- return { ...error, startIndex: startIndex - 1, startCol: startCol - 1, excerpt: `|${excerpt}` };
99
- }));
100
- }
101
- return errors;
102
- }
103
- /** @override */
104
- cloneNode() {
105
- const [name, ...cloned] = this.cloneChildNodes();
106
- return index_1.default.run(() => {
107
- // @ts-expect-error abstract class
108
- const token = new ArgToken([''], this.getAttribute('config'));
109
- token.firstChild.safeReplaceWith(name);
110
- token.append(...cloned);
111
- token.afterBuild();
112
- return token;
113
- });
114
- }
115
- /** @private */
116
- afterBuild() {
117
- this.setAttribute('name', this.firstChild.text().trim());
118
- const /** @implements */ argListener = ({ prevTarget }) => {
119
- if (prevTarget === this.firstChild) {
120
- this.setAttribute('name', prevTarget.text().trim());
121
- }
122
- };
123
- this.addEventListener(['remove', 'insert', 'replace', 'text'], argListener);
124
- }
125
- /** 移除无效部分 */
126
- removeRedundant() {
127
- index_1.default.run(() => {
128
- for (let i = this.length - 1; i > 1; i--) {
129
- super.removeAt(i);
130
- }
131
- });
132
- }
133
- /**
134
- * @override
135
- * @param i 移除位置
136
- */
137
- removeAt(i) {
138
- if (i === 1) {
139
- this.removeRedundant();
140
- }
141
- return super.removeAt(i);
142
- }
143
- /**
144
- * @override
145
- * @param token 待插入的子节点
146
- * @param i 插入位置
147
- * @throws `RangeError` 不可插入多余子节点
148
- * @throws `TypeError` 不可插入文本节点
149
- */
150
- insertAt(token, i = this.length) {
151
- const j = i < 0 ? i + this.length : i;
152
- if (j > 1) {
153
- throw new RangeError(`${this.constructor.name}不可插入多余的子节点!`);
154
- }
155
- else if (typeof token === 'string') {
156
- throw new TypeError(`${this.constructor.name}不可插入文本节点!`);
157
- }
158
- super.insertAt(token, i);
159
- if (j === 1) {
160
- token.type = 'arg-default';
161
- }
162
- return token;
163
- }
164
- /**
165
- * 设置参数名
166
- * @param name 新参数名
167
- * @throws `SyntaxError` 非法的参数名
168
- */
169
- setName(name) {
170
- const root = index_1.default.parse(`{{{${name}}}}`, this.getAttribute('include'), 2, this.getAttribute('config')), { length, firstChild: arg } = root;
171
- if (length !== 1 || !(arg instanceof ArgToken) || arg.length !== 1) {
172
- throw new SyntaxError(`非法的参数名称:${(0, string_1.noWrap)(name)}`);
173
- }
174
- const { firstChild } = arg;
175
- arg.destroy();
176
- this.firstChild.safeReplaceWith(firstChild);
177
- }
178
- /**
179
- * 设置预设值
180
- * @param value 预设值
181
- * @throws `SyntaxError` 非法的参数预设值
182
- */
183
- setDefault(value) {
184
- const root = index_1.default.parse(`{{{|${value}}}}`, this.getAttribute('include'), 2, this.getAttribute('config')), { length, firstChild: arg } = root;
185
- if (length !== 1 || !(arg instanceof ArgToken) || arg.length !== 2) {
186
- throw new SyntaxError(`非法的参数预设值:${(0, string_1.noWrap)(value)}`);
187
- }
188
- const { childNodes: [, oldDefault] } = this, { lastChild } = arg;
189
- arg.destroy();
190
- if (oldDefault) {
191
- oldDefault.safeReplaceWith(lastChild);
192
- }
193
- else {
194
- this.insertAt(lastChild);
195
- }
196
- }
197
- }
198
- exports.ArgToken = ArgToken;
199
- index_1.default.classes['ArgToken'] = __filename;
@@ -1,11 +0,0 @@
1
- import { Token } from '.';
2
- 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' | 'converter-rule-noconvert' | 'invoke-function' | 'invoke-module' | 'template-name' | 'link-target' | 'param-line';
3
- /** 不会被继续解析的plain Token */
4
- export declare class AtomToken extends Token {
5
- type: AtomTypes;
6
- /** @browser */
7
- constructor(wikitext: string | undefined, type: AtomTypes, config?: import("../index").Config, accum?: Token[], acceptable?: Acceptable);
8
- /** @override */
9
- cloneNode(): this;
10
- }
11
- export {};
package/dist/src/atom.js DELETED
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AtomToken = void 0;
4
- const index_1 = require("../index");
5
- const _1 = require(".");
6
- /** 不会被继续解析的plain Token */
7
- class AtomToken extends _1.Token {
8
- /** @browser */
9
- constructor(wikitext, type, config = index_1.default.getConfig(), accum = [], acceptable) {
10
- super(wikitext, config, true, accum, acceptable);
11
- this.type = type;
12
- }
13
- /** @override */
14
- cloneNode() {
15
- const cloned = this.cloneChildNodes(), config = this.getAttribute('config'), acceptable = this.getAttribute('acceptable');
16
- return index_1.default.run(() => {
17
- const token = new AtomToken(undefined, this.type, config, [], acceptable);
18
- token.append(...cloned);
19
- return token;
20
- });
21
- }
22
- }
23
- exports.AtomToken = AtomToken;
24
- index_1.default.classes['AtomToken'] = __filename;