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