wikiparser-node 0.10.0 → 0.11.0-m

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/README.md +44 -32
  2. package/config/.schema.json +1 -8
  3. package/config/default.json +1 -2
  4. package/config/llwiki.json +1 -36
  5. package/config/moegirl.json +1 -45
  6. package/config/zhwiki.json +1 -467
  7. package/dist/index.d.ts +110 -0
  8. package/dist/lib/element.d.ts +48 -0
  9. package/dist/lib/node.d.ts +108 -0
  10. package/dist/lib/text.d.ts +30 -0
  11. package/dist/lib/title.d.ts +15 -0
  12. package/dist/mixin/hidden.d.ts +8 -0
  13. package/dist/parser/brackets.d.ts +12 -0
  14. package/dist/parser/commentAndExt.d.ts +8 -0
  15. package/dist/parser/converter.d.ts +7 -0
  16. package/dist/parser/externalLinks.d.ts +7 -0
  17. package/dist/parser/hrAndDoubleUnderscore.d.ts +11 -0
  18. package/dist/parser/html.d.ts +7 -0
  19. package/dist/parser/links.d.ts +7 -0
  20. package/dist/parser/list.d.ts +7 -0
  21. package/dist/parser/magicLinks.d.ts +7 -0
  22. package/dist/parser/quotes.d.ts +7 -0
  23. package/dist/parser/table.d.ts +11 -0
  24. package/dist/src/arg.d.ts +25 -0
  25. package/dist/src/atom/hidden.d.ts +5 -0
  26. package/dist/src/atom/index.d.ts +14 -0
  27. package/dist/src/attribute.d.ts +42 -0
  28. package/dist/src/attributes.d.ts +33 -0
  29. package/dist/src/converter.d.ts +29 -0
  30. package/dist/src/converterFlags.d.ts +27 -0
  31. package/dist/src/converterRule.d.ts +29 -0
  32. package/dist/src/extLink.d.ts +22 -0
  33. package/dist/src/gallery.d.ts +19 -0
  34. package/dist/src/hasNowiki/index.d.ts +14 -0
  35. package/dist/src/hasNowiki/pre.d.ts +13 -0
  36. package/dist/src/heading.d.ts +24 -0
  37. package/dist/src/html.d.ts +33 -0
  38. package/dist/src/imageParameter.d.ts +23 -0
  39. package/dist/src/imagemap.d.ts +26 -0
  40. package/dist/src/imagemapLink.d.ts +16 -0
  41. package/dist/src/index.d.ts +53 -0
  42. package/dist/src/link/category.d.ts +8 -0
  43. package/dist/src/link/file.d.ts +27 -0
  44. package/dist/src/link/galleryImage.d.ts +15 -0
  45. package/dist/src/link/index.d.ts +29 -0
  46. package/dist/src/magicLink.d.ts +14 -0
  47. package/dist/src/nested/choose.d.ts +13 -0
  48. package/dist/src/nested/combobox.d.ts +13 -0
  49. package/dist/src/nested/index.d.ts +20 -0
  50. package/dist/src/nested/references.d.ts +13 -0
  51. package/dist/src/nowiki/comment.d.ts +19 -0
  52. package/dist/src/nowiki/dd.d.ts +8 -0
  53. package/dist/src/nowiki/doubleUnderscore.d.ts +12 -0
  54. package/dist/src/nowiki/hr.d.ts +13 -0
  55. package/dist/src/nowiki/index.d.ts +18 -0
  56. package/dist/src/nowiki/list.d.ts +8 -0
  57. package/dist/src/nowiki/noinclude.d.ts +8 -0
  58. package/dist/src/nowiki/quote.d.ts +20 -0
  59. package/dist/src/onlyinclude.d.ts +17 -0
  60. package/dist/src/paramTag/index.d.ts +24 -0
  61. package/dist/src/paramTag/inputbox.d.ts +8 -0
  62. package/dist/src/parameter.d.ts +28 -0
  63. package/dist/src/syntax.d.ts +15 -0
  64. package/dist/src/table/index.d.ts +16 -0
  65. package/dist/src/table/td.d.ts +39 -0
  66. package/dist/src/table/tr.d.ts +17 -0
  67. package/dist/src/tagPair/ext.d.ts +17 -0
  68. package/dist/src/tagPair/include.d.ts +16 -0
  69. package/dist/src/tagPair/index.d.ts +28 -0
  70. package/dist/src/transclude.d.ts +75 -0
  71. package/dist/util/lint.d.ts +28 -0
  72. package/dist/util/string.d.ts +31 -0
  73. package/i18n/zh-hans.json +1 -1
  74. package/i18n/zh-hant.json +1 -1
  75. package/index.js +5 -257
  76. package/lib/element.js +7 -482
  77. package/lib/node.js +11 -540
  78. package/lib/text.js +3 -96
  79. package/lib/title.js +1 -28
  80. package/mixin/hidden.js +0 -3
  81. package/package.json +11 -5
  82. package/parser/brackets.js +3 -2
  83. package/parser/commentAndExt.js +8 -6
  84. package/parser/converter.js +1 -2
  85. package/parser/externalLinks.js +1 -2
  86. package/parser/hrAndDoubleUnderscore.js +1 -2
  87. package/parser/html.js +1 -2
  88. package/parser/links.js +5 -6
  89. package/parser/list.js +1 -2
  90. package/parser/magicLinks.js +1 -2
  91. package/parser/quotes.js +1 -2
  92. package/parser/table.js +1 -2
  93. package/src/arg.js +4 -118
  94. package/src/atom/hidden.js +0 -2
  95. package/src/atom/index.js +1 -18
  96. package/src/attribute.js +6 -190
  97. package/src/attributes.js +5 -308
  98. package/src/converter.js +3 -109
  99. package/src/converterFlags.js +1 -188
  100. package/src/converterRule.js +2 -184
  101. package/src/extLink.js +2 -122
  102. package/src/gallery.js +2 -56
  103. package/src/hasNowiki/index.js +1 -13
  104. package/src/hasNowiki/pre.js +1 -13
  105. package/src/heading.js +4 -55
  106. package/src/html.js +5 -120
  107. package/src/imageParameter.js +3 -165
  108. package/src/imagemap.js +3 -62
  109. package/src/imagemapLink.js +2 -14
  110. package/src/index.js +9 -530
  111. package/src/link/category.js +1 -32
  112. package/src/link/file.js +3 -158
  113. package/src/link/galleryImage.js +3 -61
  114. package/src/link/index.js +4 -273
  115. package/src/magicLink.js +6 -87
  116. package/src/nested/choose.js +1 -2
  117. package/src/nested/combobox.js +1 -2
  118. package/src/nested/index.js +8 -32
  119. package/src/nested/references.js +1 -2
  120. package/src/nowiki/comment.js +2 -26
  121. package/src/nowiki/dd.js +1 -47
  122. package/src/nowiki/doubleUnderscore.js +1 -31
  123. package/src/nowiki/hr.js +2 -21
  124. package/src/nowiki/index.js +2 -24
  125. package/src/nowiki/list.js +2 -5
  126. package/src/nowiki/noinclude.js +0 -14
  127. package/src/nowiki/quote.js +2 -16
  128. package/src/onlyinclude.js +2 -27
  129. package/src/paramTag/index.js +2 -25
  130. package/src/paramTag/inputbox.js +2 -5
  131. package/src/parameter.js +6 -148
  132. package/src/syntax.js +1 -69
  133. package/src/table/index.js +2 -939
  134. package/src/table/td.js +6 -226
  135. package/src/table/tr.js +3 -248
  136. package/src/tagPair/ext.js +4 -23
  137. package/src/tagPair/include.js +1 -25
  138. package/src/tagPair/index.js +3 -52
  139. package/src/transclude.js +6 -513
  140. package/typings/api.d.ts +9 -0
  141. package/typings/index.d.ts +51 -0
  142. package/typings/node.d.ts +16 -0
  143. package/typings/parser.d.ts +5 -0
  144. package/typings/token.d.ts +28 -0
  145. package/util/lint.js +2 -0
  146. package/util/string.js +0 -51
  147. package/lib/ranges.js +0 -130
  148. package/mixin/attributeParent.js +0 -117
  149. package/mixin/fixedToken.js +0 -40
  150. package/mixin/singleLine.js +0 -31
  151. package/mixin/sol.js +0 -54
  152. package/parser/selector.js +0 -177
  153. package/src/charinsert.js +0 -97
  154. package/tool/index.js +0 -1202
  155. package/util/debug.js +0 -73
@@ -1,177 +0,0 @@
1
- 'use strict';
2
-
3
- const Parser = require('..');
4
-
5
- const /** @type {Set<pseudo>} */ 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
- /** @type {pseudo[]} */ 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
- ],
37
- specialChars = [
38
- ['[', '&lbrack;'],
39
- [']', '&rbrack;'],
40
- ['(', '&lpar;'],
41
- [')', '&rpar;'],
42
- ['"', '&quot;'],
43
- [`'`, '&apos;'],
44
- [':', '&colon;'],
45
- ['\\', '&bsol;'],
46
- ['&', '&amp;'],
47
- ],
48
- pseudoRegex = new RegExp(`:(${complexPseudos.join('|')})$`, 'u'),
49
- regularRegex = /[[(,>+~]|\s+/u,
50
- attributeRegex = /^\s*(\w+)\s*(?:([~|^$*!]?=)\s*("[^"]*"|'[^']*'|[^\s[\]]+)(?:\s+(i))?\s*)?\]/u,
51
- functionRegex = /^(\s*"[^"]*"\s*|\s*'[^']*'\s*|[^()]*)\)/u,
52
- grouping = new Set([',', '>', '+', '~']),
53
- combinator = new Set(['>', '+', '~', '']);
54
-
55
- /**
56
- * 清理转义符号
57
- * @param {string} selector
58
- */
59
- const sanitize = selector => {
60
- for (const [c, escaped] of specialChars) {
61
- selector = selector.replaceAll(`\\${c}`, escaped);
62
- }
63
- return selector;
64
- };
65
-
66
- /**
67
- * 还原转义符号
68
- * @param {string|undefined} selector
69
- */
70
- const desanitize = selector => {
71
- if (selector === undefined) {
72
- return undefined;
73
- }
74
- for (const [c, escaped] of specialChars) {
75
- selector = selector.replaceAll(escaped, c);
76
- }
77
- return selector.trim();
78
- };
79
-
80
- /**
81
- * 去除首尾的引号
82
- * @param {string|undefined} val 属性值或伪选择器函数的参数
83
- */
84
- const deQuote = val => {
85
- if (val === undefined) {
86
- return undefined;
87
- }
88
- const quotes = /^(["']).*\1$/u.exec(val)?.[1];
89
- return quotes ? val.slice(1, -1) : val;
90
- };
91
-
92
- /**
93
- * 解析简单伪选择器
94
- * @param {SelectorArray} step 当前顶部
95
- * @param {string} str 不含属性和复杂伪选择器的语句
96
- * @throws `SyntaxError` 非法的选择器
97
- */
98
- const pushSimple = (step, str) => {
99
- const pieces = str.trim().split(':'),
100
- // eslint-disable-next-line unicorn/explicit-length-check
101
- i = pieces.slice(1).findIndex(pseudo => simplePseudos.has(pseudo)) + 1 || pieces.length;
102
- if (pieces.slice(i).some(pseudo => !simplePseudos.has(pseudo))) {
103
- throw new SyntaxError(`非法的选择器!\n${str}\n可能需要将':'转义为'\\:'。`);
104
- }
105
- step.push(desanitize(pieces.slice(0, i).join(':')), ...pieces.slice(i).map(piece => `:${piece}`));
106
- };
107
-
108
- /**
109
- * 解析选择器
110
- * @param {string} selector
111
- * @throws `SyntaxError` 非法的选择器
112
- */
113
- const parseSelector = selector => {
114
- selector = selector.trim();
115
- const /** @type {SelectorArray[][]} */ stack = [[[]]];
116
- let sanitized = sanitize(selector),
117
- regex = regularRegex,
118
- mt = regex.exec(sanitized),
119
- [condition] = stack,
120
- [step] = condition;
121
- while (mt) {
122
- let {0: syntax, index} = mt;
123
- if (syntax.trim() === '') {
124
- index += syntax.length;
125
- const char = sanitized[index];
126
- syntax = grouping.has(char) ? char : '';
127
- }
128
- if (syntax === ',') { // 情形1:并列
129
- pushSimple(step, sanitized.slice(0, index));
130
- condition = [[]];
131
- [step] = condition;
132
- stack.push(condition);
133
- } else if (combinator.has(syntax)) { // 情形2:关系
134
- pushSimple(step, sanitized.slice(0, index));
135
- if (!step.some(Boolean)) {
136
- throw new SyntaxError(`非法的选择器!\n${selector}\n可能需要通用选择器'*'。`);
137
- }
138
- step.relation = syntax;
139
- step = [];
140
- condition.push(step);
141
- } else if (syntax === '[') { // 情形3:属性开启
142
- pushSimple(step, sanitized.slice(0, index));
143
- regex = attributeRegex;
144
- } else if (syntax.endsWith(']')) { // 情形4:属性闭合
145
- mt[3] = desanitize(deQuote(mt[3]));
146
- step.push(mt.slice(1));
147
- regex = regularRegex;
148
- } else if (syntax === '(') { // 情形5:伪选择器开启
149
- const pseudoExec = pseudoRegex.exec(sanitized.slice(0, index));
150
- if (!pseudoExec) {
151
- throw new SyntaxError(`非法的选择器!\n${desanitize(sanitized)}\n请检查伪选择器是否存在。`);
152
- }
153
- pushSimple(step, sanitized.slice(0, pseudoExec.index));
154
- step.push(pseudoExec[1]); // 临时存放复杂伪选择器
155
- regex = functionRegex;
156
- } else { // 情形6:伪选择器闭合
157
- const /** @type {pseudo} */ pseudo = step.pop();
158
- mt.push(pseudo);
159
- mt[1] = deQuote(mt[1]);
160
- step.push(mt.slice(1));
161
- regex = regularRegex;
162
- }
163
- sanitized = sanitized.slice(index + syntax.length);
164
- if (grouping.has(syntax)) {
165
- sanitized = sanitized.trim();
166
- }
167
- mt = regex.exec(sanitized);
168
- }
169
- if (regex === regularRegex) {
170
- pushSimple(step, sanitized);
171
- return stack;
172
- }
173
- throw new SyntaxError(`非法的选择器!\n${selector}\n检测到未闭合的'${regex === attributeRegex ? '[' : '('}'`);
174
- };
175
-
176
- Parser.parsers.parseSelector = __filename;
177
- module.exports = parseSelector;
package/src/charinsert.js DELETED
@@ -1,97 +0,0 @@
1
- 'use strict';
2
-
3
- const Parser = require('..'),
4
- singleLine = require('../mixin/singleLine'),
5
- Token = require('.'),
6
- HasNowikiToken = require('./hasNowiki');
7
-
8
- /**
9
- * `<charinsert>`
10
- * @classdesc `{childNodes: [...HasNowikiToken]}`
11
- */
12
- class CharinsertToken extends Token {
13
- type = 'ext-inner';
14
- name = 'charinsert';
15
-
16
- /**
17
- * @param {string} wikitext wikitext
18
- * @param {accum} accum
19
- */
20
- constructor(wikitext, config = Parser.getConfig(), accum = []) {
21
- super(undefined, config, true, accum, {
22
- SingleLineHasNowikiToken: ':',
23
- });
24
- const SingleLineHasNowikiToken = singleLine(HasNowikiToken);
25
- this.append(
26
- ...wikitext.split('\n').map(str => new SingleLineHasNowikiToken(str, 'charinsert-line', config, accum)),
27
- );
28
- }
29
-
30
- /**
31
- * @override
32
- * @param {string} selector
33
- */
34
- toString(selector) {
35
- return super.toString(selector, '\n');
36
- }
37
-
38
- /** @override */
39
- getGaps() {
40
- return 1;
41
- }
42
-
43
- /** @override */
44
- print() {
45
- return super.print({sep: '\n'});
46
- }
47
-
48
- /** @override */
49
- cloneNode() {
50
- const cloned = this.cloneChildNodes();
51
- return Parser.run(() => {
52
- const token = new CharinsertToken(undefined, this.getAttribute('config'));
53
- token.append(...cloned);
54
- return token;
55
- });
56
- }
57
-
58
- /**
59
- * 获取某一行的插入选项
60
- * @param {number|HasNowikiToken} child 行号或子节点
61
- */
62
- getLineItems(child) {
63
- if (Number.isInteger(child)) {
64
- child = this.childNodes.at(child);
65
- }
66
- if (!(child instanceof HasNowikiToken)) {
67
- this.typeError('getLineItems', 'Number', 'HasNowikiToken');
68
- }
69
- const entities = {'\t': '&#9;', '\r': '&#12;', ' ': '&#32;'};
70
- return String(child).replace(
71
- /<nowiki>(.+?)<\/nowiki>/giu,
72
- /** @param {string} inner */ (_, inner) => inner.replace(/[\t\r ]/gu, s => entities[s]),
73
- ).split(/\s/u).filter(Boolean)
74
- .map(item => {
75
- const parts = item.split('+');
76
- if (parts.length === 1) {
77
- return parts[0];
78
- }
79
- return parts[0] ? parts.slice(0, 2) : '+';
80
- });
81
- }
82
-
83
- /** 获取所有插入选项 */
84
- getAllItems() {
85
- return this.childNodes.flatMap(child => this.getLineItems(child));
86
- }
87
-
88
- /** @override */
89
- text() {
90
- return this.childNodes.map(
91
- child => this.getLineItems(child).map(str => Array.isArray(str) ? str.join('+') : str).join(' '),
92
- ).join('\n');
93
- }
94
- }
95
-
96
- Parser.classes.CharinsertToken = __filename;
97
- module.exports = CharinsertToken;