wikiparser-node 1.11.1 → 1.12.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 (175) hide show
  1. package/bundle/bundle.min.js +37 -0
  2. package/config/default.json +28 -28
  3. package/config/enwiki.json +14 -827
  4. package/config/llwiki.json +20 -54
  5. package/config/minimum.json +1 -1
  6. package/config/moegirl.json +20 -63
  7. package/config/zhwiki.json +27 -492
  8. package/extensions/dist/base.js +162 -0
  9. package/extensions/dist/codejar.js +52 -0
  10. package/extensions/dist/editor.js +159 -0
  11. package/extensions/dist/highlight.js +30 -0
  12. package/extensions/dist/lint.js +72 -0
  13. package/extensions/editor.css +59 -0
  14. package/extensions/ui.css +159 -0
  15. package/package.json +29 -21
  16. package/config/.schema.json +0 -186
  17. package/dist/addon/table.js +0 -486
  18. package/dist/addon/token.js +0 -304
  19. package/dist/addon/transclude.js +0 -184
  20. package/dist/base.d.ts +0 -81
  21. package/dist/base.js +0 -39
  22. package/dist/index.d.ts +0 -33
  23. package/dist/index.js +0 -235
  24. package/dist/internal.d.ts +0 -46
  25. package/dist/lib/element.d.ts +0 -125
  26. package/dist/lib/element.js +0 -375
  27. package/dist/lib/node.d.ts +0 -173
  28. package/dist/lib/node.js +0 -477
  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/rect.d.ts +0 -18
  34. package/dist/lib/rect.js +0 -34
  35. package/dist/lib/text.d.ts +0 -58
  36. package/dist/lib/text.js +0 -400
  37. package/dist/lib/title.d.ts +0 -42
  38. package/dist/lib/title.js +0 -208
  39. package/dist/mixin/attributesParent.d.ts +0 -49
  40. package/dist/mixin/attributesParent.js +0 -79
  41. package/dist/mixin/fixed.d.ts +0 -5
  42. package/dist/mixin/fixed.js +0 -32
  43. package/dist/mixin/flagsParent.d.ts +0 -43
  44. package/dist/mixin/flagsParent.js +0 -64
  45. package/dist/mixin/hidden.d.ts +0 -7
  46. package/dist/mixin/hidden.js +0 -37
  47. package/dist/mixin/magicLinkParent.d.ts +0 -19
  48. package/dist/mixin/magicLinkParent.js +0 -43
  49. package/dist/mixin/singleLine.d.ts +0 -5
  50. package/dist/mixin/singleLine.js +0 -25
  51. package/dist/mixin/sol.d.ts +0 -6
  52. package/dist/mixin/sol.js +0 -45
  53. package/dist/mixin/syntax.d.ts +0 -8
  54. package/dist/mixin/syntax.js +0 -46
  55. package/dist/parser/braces.js +0 -150
  56. package/dist/parser/commentAndExt.js +0 -79
  57. package/dist/parser/converter.js +0 -39
  58. package/dist/parser/externalLinks.js +0 -37
  59. package/dist/parser/hrAndDoubleUnderscore.js +0 -42
  60. package/dist/parser/html.js +0 -38
  61. package/dist/parser/links.js +0 -101
  62. package/dist/parser/list.js +0 -114
  63. package/dist/parser/magicLinks.js +0 -52
  64. package/dist/parser/quotes.js +0 -67
  65. package/dist/parser/redirect.js +0 -26
  66. package/dist/parser/selector.js +0 -394
  67. package/dist/parser/table.js +0 -123
  68. package/dist/src/arg.d.ts +0 -51
  69. package/dist/src/arg.js +0 -214
  70. package/dist/src/atom.d.ts +0 -14
  71. package/dist/src/atom.js +0 -52
  72. package/dist/src/attribute.d.ts +0 -64
  73. package/dist/src/attribute.js +0 -480
  74. package/dist/src/attributes.d.ts +0 -101
  75. package/dist/src/attributes.js +0 -381
  76. package/dist/src/converter.d.ts +0 -28
  77. package/dist/src/converter.js +0 -148
  78. package/dist/src/converterFlags.d.ts +0 -80
  79. package/dist/src/converterFlags.js +0 -239
  80. package/dist/src/converterRule.d.ts +0 -71
  81. package/dist/src/converterRule.js +0 -216
  82. package/dist/src/extLink.d.ts +0 -36
  83. package/dist/src/extLink.js +0 -218
  84. package/dist/src/gallery.d.ts +0 -47
  85. package/dist/src/gallery.js +0 -143
  86. package/dist/src/heading.d.ts +0 -40
  87. package/dist/src/heading.js +0 -192
  88. package/dist/src/hidden.d.ts +0 -9
  89. package/dist/src/hidden.js +0 -80
  90. package/dist/src/html.d.ts +0 -61
  91. package/dist/src/html.js +0 -343
  92. package/dist/src/imageParameter.d.ts +0 -60
  93. package/dist/src/imageParameter.js +0 -260
  94. package/dist/src/imagemap.d.ts +0 -47
  95. package/dist/src/imagemap.js +0 -146
  96. package/dist/src/imagemapLink.d.ts +0 -31
  97. package/dist/src/imagemapLink.js +0 -97
  98. package/dist/src/index.d.ts +0 -136
  99. package/dist/src/index.js +0 -834
  100. package/dist/src/link/base.d.ts +0 -52
  101. package/dist/src/link/base.js +0 -256
  102. package/dist/src/link/category.d.ts +0 -22
  103. package/dist/src/link/category.js +0 -34
  104. package/dist/src/link/file.d.ts +0 -102
  105. package/dist/src/link/file.js +0 -333
  106. package/dist/src/link/galleryImage.d.ts +0 -29
  107. package/dist/src/link/galleryImage.js +0 -132
  108. package/dist/src/link/index.d.ts +0 -39
  109. package/dist/src/link/index.js +0 -98
  110. package/dist/src/link/redirectTarget.d.ts +0 -27
  111. package/dist/src/link/redirectTarget.js +0 -69
  112. package/dist/src/magicLink.d.ts +0 -58
  113. package/dist/src/magicLink.js +0 -256
  114. package/dist/src/nested.d.ts +0 -40
  115. package/dist/src/nested.js +0 -106
  116. package/dist/src/nowiki/base.d.ts +0 -28
  117. package/dist/src/nowiki/base.js +0 -89
  118. package/dist/src/nowiki/comment.d.ts +0 -14
  119. package/dist/src/nowiki/comment.js +0 -121
  120. package/dist/src/nowiki/dd.d.ts +0 -8
  121. package/dist/src/nowiki/dd.js +0 -72
  122. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -15
  123. package/dist/src/nowiki/doubleUnderscore.js +0 -97
  124. package/dist/src/nowiki/hr.d.ts +0 -5
  125. package/dist/src/nowiki/hr.js +0 -70
  126. package/dist/src/nowiki/index.d.ts +0 -14
  127. package/dist/src/nowiki/index.js +0 -28
  128. package/dist/src/nowiki/list.d.ts +0 -5
  129. package/dist/src/nowiki/list.js +0 -65
  130. package/dist/src/nowiki/listBase.d.ts +0 -23
  131. package/dist/src/nowiki/listBase.js +0 -99
  132. package/dist/src/nowiki/noinclude.d.ts +0 -6
  133. package/dist/src/nowiki/noinclude.js +0 -75
  134. package/dist/src/nowiki/quote.d.ts +0 -14
  135. package/dist/src/nowiki/quote.js +0 -140
  136. package/dist/src/onlyinclude.d.ts +0 -13
  137. package/dist/src/onlyinclude.js +0 -58
  138. package/dist/src/paramTag/index.d.ts +0 -28
  139. package/dist/src/paramTag/index.js +0 -78
  140. package/dist/src/paramTag/inputbox.d.ts +0 -8
  141. package/dist/src/paramTag/inputbox.js +0 -22
  142. package/dist/src/parameter.d.ts +0 -60
  143. package/dist/src/parameter.js +0 -264
  144. package/dist/src/pre.d.ts +0 -28
  145. package/dist/src/pre.js +0 -60
  146. package/dist/src/redirect.d.ts +0 -30
  147. package/dist/src/redirect.js +0 -126
  148. package/dist/src/syntax.d.ts +0 -17
  149. package/dist/src/syntax.js +0 -87
  150. package/dist/src/table/base.d.ts +0 -28
  151. package/dist/src/table/base.js +0 -81
  152. package/dist/src/table/index.d.ts +0 -230
  153. package/dist/src/table/index.js +0 -506
  154. package/dist/src/table/td.d.ts +0 -72
  155. package/dist/src/table/td.js +0 -370
  156. package/dist/src/table/tr.d.ts +0 -30
  157. package/dist/src/table/tr.js +0 -59
  158. package/dist/src/table/trBase.d.ts +0 -49
  159. package/dist/src/table/trBase.js +0 -164
  160. package/dist/src/tagPair/ext.d.ts +0 -29
  161. package/dist/src/tagPair/ext.js +0 -220
  162. package/dist/src/tagPair/include.d.ts +0 -33
  163. package/dist/src/tagPair/include.js +0 -130
  164. package/dist/src/tagPair/index.d.ts +0 -23
  165. package/dist/src/tagPair/index.js +0 -128
  166. package/dist/src/transclude.d.ts +0 -159
  167. package/dist/src/transclude.js +0 -587
  168. package/dist/util/constants.js +0 -25
  169. package/dist/util/debug.js +0 -95
  170. package/dist/util/diff.js +0 -83
  171. package/dist/util/html.js +0 -143
  172. package/dist/util/lint.js +0 -32
  173. package/dist/util/string.js +0 -87
  174. package/errors/README +0 -3
  175. package/printed/README +0 -3
package/dist/lib/text.js DELETED
@@ -1,400 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AstText = void 0;
4
- const constants_1 = require("../util/constants");
5
- const debug_1 = require("../util/debug");
6
- const string_1 = require("../util/string");
7
- const html_1 = require("../util/html");
8
- const index_1 = require("../index");
9
- const node_1 = require("./node");
10
- /* eslint-disable @typescript-eslint/no-unused-expressions */
11
- /<\s*(?:\/\s*)?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*?\])|((?:^|\])[^[]*?)\]+|https?[:/]\/+/giu;
12
- /^https?:\/\/(?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])[^[\]<>"\t\n\p{Zs}]*\.(?:gif|png|jpg|jpeg)$/iu;
13
- /* eslint-enable @typescript-eslint/no-unused-expressions */
14
- const source = String.raw `<\s*(?:/\s*)?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*?\])|((?:^|\])[^[]*?)\]+`, errorSyntax = new RegExp(String.raw `${source}|https?[:/]/+`, 'giu'), errorSyntaxUrl = new RegExp(source, 'giu'), extImage = new RegExp(String.raw `^https?://${string_1.extUrlCharFirst}${string_1.extUrlChar}\.(?:gif|png|jpg|jpeg)$`, 'iu'), regexes = {
15
- '[': /[[\]]/u,
16
- '{': /[{}]/u,
17
- ']': /[[\]](?=[^[\]]*$)/u,
18
- '}': /[{}](?=[^{}]*$)/u,
19
- }, ruleMap = {
20
- '<': 'tag-like',
21
- '[': 'lonely-bracket',
22
- '{': 'lonely-bracket',
23
- ']': 'lonely-bracket',
24
- '}': 'lonely-bracket',
25
- h: 'lonely-http',
26
- }, disallowedTags = [
27
- 'html',
28
- 'base',
29
- 'head',
30
- 'style',
31
- 'title',
32
- 'body',
33
- 'menu',
34
- 'a',
35
- 'area',
36
- 'audio',
37
- 'img',
38
- 'map',
39
- 'track',
40
- 'video',
41
- 'embed',
42
- 'iframe',
43
- 'object',
44
- 'picture',
45
- 'source',
46
- 'canvas',
47
- 'script',
48
- 'col',
49
- 'colgroup',
50
- 'tbody',
51
- 'tfoot',
52
- 'thead',
53
- 'button',
54
- 'datalist',
55
- 'fieldset',
56
- 'form',
57
- 'input',
58
- 'label',
59
- 'legend',
60
- 'meter',
61
- 'optgroup',
62
- 'option',
63
- 'output',
64
- 'progress',
65
- 'select',
66
- 'textarea',
67
- 'details',
68
- 'dialog',
69
- 'slot',
70
- 'template',
71
- 'dir',
72
- 'frame',
73
- 'frameset',
74
- 'marquee',
75
- 'param',
76
- 'xmp',
77
- ];
78
- /** 文本节点 */
79
- class AstText extends node_1.AstNode {
80
- data = '';
81
- get type() {
82
- return 'text';
83
- }
84
- /* NOT FOR BROWSER */
85
- /** 文本长度 */
86
- get length() {
87
- return this.data.length;
88
- }
89
- set length(n) {
90
- if (n >= 0 && n < this.length) {
91
- this.replaceData(this.data.slice(0, n));
92
- }
93
- }
94
- /* NOT FOR BROWSER END */
95
- /** @param text 包含文本 */
96
- constructor(text) {
97
- super();
98
- Object.defineProperties(this, {
99
- childNodes: { enumerable: false, configurable: false },
100
- data: {
101
- value: text,
102
- /* NOT FOR BROWSER */
103
- writable: false,
104
- },
105
- });
106
- }
107
- /** @private */
108
- toString(skip) {
109
- return skip && !this.parentNode?.getAttribute('built') ? (0, string_1.removeComment)(this.data) : this.data;
110
- }
111
- /** @private */
112
- text() {
113
- return this.data;
114
- }
115
- /** @private */
116
- lint(start = this.getAbsoluteIndex(), errorRegex) {
117
- if (errorRegex === false) {
118
- return [];
119
- }
120
- const { data, parentNode, nextSibling, previousSibling } = this;
121
- if (!parentNode) {
122
- throw new Error('An isolated text node cannot be linted!');
123
- }
124
- const { type, name, parentNode: grandparent } = parentNode;
125
- let isHtmlAttrVal = false;
126
- if (type === 'attr-value') {
127
- const { type: grandType, name: grandName, tag } = grandparent;
128
- if (grandType !== 'ext-attr') {
129
- isHtmlAttrVal = true;
130
- }
131
- else if (tag === 'choose' && (grandName === 'before' || grandName === 'after')) {
132
- return [];
133
- }
134
- }
135
- errorRegex ??= type === 'free-ext-link'
136
- || type === 'ext-link-url'
137
- || type === 'image-parameter' && name === 'link'
138
- || isHtmlAttrVal
139
- ? errorSyntaxUrl
140
- : errorSyntax;
141
- if (data.search(errorRegex) === -1) {
142
- return [];
143
- }
144
- errorRegex.lastIndex = 0;
145
- const errors = [], nextType = nextSibling?.type, nextName = nextSibling?.name, previousType = previousSibling?.type, root = this.getRootNode(), { ext, html } = root.getAttribute('config'), { top, left } = root.posFromIndex(start), tags = new Set(['onlyinclude', 'noinclude', 'includeonly', ext, html, disallowedTags].flat(2));
146
- for (let mt = errorRegex.exec(data); mt; mt = errorRegex.exec(data)) {
147
- const [, tag, prefix] = mt;
148
- let { 0: error, index } = mt;
149
- if (prefix && prefix !== ']') {
150
- const { length } = prefix;
151
- index += length;
152
- error = error.slice(length);
153
- }
154
- const { 0: char, length } = error;
155
- if (char === '<' && !tags.has(tag.toLowerCase())
156
- || char === '['
157
- && type === 'ext-link-text'
158
- && (/&(?:rbrack|#93|#x5[Dd];);/u.test(data.slice(index + 1))
159
- || nextSibling?.is('ext') && nextName === 'nowiki' && nextSibling.innerText?.includes(']'))) {
160
- continue;
161
- }
162
- else if (char === ']' && (index || length > 1)) {
163
- errorRegex.lastIndex--;
164
- }
165
- else if (char === 'h' && index === 0 && type === 'ext-link-text' && extImage.test(data)) {
166
- continue;
167
- }
168
- const startIndex = start + index, endIndex = startIndex + length, rootStr = root.toString(), nextChar = rootStr[endIndex], previousChar = rootStr[startIndex - 1], severity = length > 1 && !(char === '<' && !/[\s/>]/u.test(nextChar ?? '')
169
- || isHtmlAttrVal && (char === '[' || char === ']'))
170
- || char === '{' && (nextChar === char || previousChar === '-')
171
- || char === '}' && (previousChar === char || nextChar === '-')
172
- || char === '[' && (nextChar === char
173
- || type === 'ext-link-text'
174
- || nextType === 'free-ext-link' && !data.slice(index + 1).trim())
175
- || char === ']' && (previousChar === char
176
- || previousType === 'free-ext-link' && !data.slice(0, index).includes(']'))
177
- ? 'error'
178
- : 'warning';
179
- const leftBracket = char === '{' || char === '[', rightBracket = char === ']' || char === '}';
180
- if (severity === 'warning' && (leftBracket || rightBracket)) {
181
- const regex = regexes[char], remains = leftBracket ? data.slice(index + 1) : data.slice(0, index);
182
- if (char === '{' && regex.exec(remains)?.[0] === '}'
183
- || char === '}' && regex.exec(remains)?.[0] === '{') {
184
- continue;
185
- }
186
- else if (!remains.includes(char)) {
187
- const sibling = leftBracket ? 'nextSibling' : 'previousSibling';
188
- let cur = this[sibling];
189
- while (cur && (cur.type !== 'text' || !regex.test(cur.data))) {
190
- cur = cur[sibling];
191
- }
192
- if (cur && regex.exec(cur.data)[0] !== char) {
193
- continue;
194
- }
195
- }
196
- }
197
- const lines = data.slice(0, index).split('\n'), startLine = lines.length + top - 1, line = lines[lines.length - 1], startCol = lines.length === 1 ? left + line.length : line.length, e = {
198
- rule: ruleMap[char],
199
- message: index_1.default.msg('lonely "$1"', char === 'h' ? error : char),
200
- severity,
201
- startIndex,
202
- endIndex,
203
- startLine,
204
- endLine: startLine,
205
- startCol,
206
- endCol: startCol + length,
207
- };
208
- if (char === '<') {
209
- e.suggestions = [
210
- {
211
- desc: 'escape',
212
- range: [startIndex, startIndex + 1],
213
- text: '&lt;',
214
- },
215
- ];
216
- }
217
- else if (char === 'h'
218
- && !(type === 'ext-link-text' || type === 'link-text')
219
- && /[\p{L}\d_]/u.test(previousChar || '')) {
220
- e.suggestions = [
221
- {
222
- desc: 'whitespace',
223
- range: [startIndex, startIndex],
224
- text: ' ',
225
- },
226
- ];
227
- }
228
- else if (char === '[' && type === 'ext-link-text') {
229
- const i = parentNode.getAbsoluteIndex() + parentNode.toString().length;
230
- e.suggestions = [
231
- {
232
- desc: 'escape',
233
- range: [i, i + 1],
234
- text: '&#93;',
235
- },
236
- ];
237
- }
238
- else if (char === ']' && previousType === 'free-ext-link' && severity === 'error') {
239
- const i = start - previousSibling.toString().length;
240
- e.fix = { range: [i, i], text: '[' };
241
- }
242
- errors.push(e);
243
- }
244
- return errors;
245
- }
246
- /**
247
- * 修改内容
248
- * @param text 新内容
249
- */
250
- #setData(text) {
251
- /* NOT FOR BROWSER */
252
- const { data } = this, e = new Event('text', { bubbles: true });
253
- /* NOT FOR BROWSER END */
254
- this.setAttribute('data', text);
255
- /* NOT FOR BROWSER */
256
- if (data !== text) {
257
- this.dispatchEvent(e, { type: 'text', oldText: data });
258
- }
259
- }
260
- /**
261
- * 替换字符串
262
- * @param text 替换的字符串
263
- */
264
- replaceData(text) {
265
- this.#setData(text);
266
- }
267
- /** @private */
268
- print() {
269
- return (0, string_1.escape)(this.data);
270
- }
271
- /* NOT FOR BROWSER */
272
- /** 复制 */
273
- cloneNode() {
274
- return new AstText(this.data);
275
- }
276
- /**
277
- * 在后方添加字符串
278
- * @param text 添加的字符串
279
- */
280
- appendData(text) {
281
- this.#setData(this.data + text);
282
- }
283
- /**
284
- * 删减字符串
285
- * @param offset 起始位置
286
- * @param count 删减字符数
287
- */
288
- deleteData(offset, count) {
289
- this.#setData(this.data.slice(0, offset) + (offset < 0 && offset + count >= 0 ? '' : this.data.slice(offset + count)));
290
- }
291
- /**
292
- * 插入字符串
293
- * @param offset 插入位置
294
- * @param text 待插入的字符串
295
- */
296
- insertData(offset, text) {
297
- this.#setData(this.data.slice(0, offset) + text + this.data.slice(offset));
298
- }
299
- /**
300
- * 提取子串
301
- * @param offset 起始位置
302
- * @param count 字符数
303
- */
304
- substringData(offset, count) {
305
- return this.data.substr(offset, count);
306
- }
307
- /**
308
- * 将文本子节点分裂为两部分
309
- * @param offset 分裂位置
310
- * @throws `RangeError` 错误的断开位置
311
- * @throws `Error` 没有父节点
312
- */
313
- splitText(offset) {
314
- if (offset > this.length || offset < -this.length) {
315
- throw new RangeError(`Wrong offset to split: ${offset}`);
316
- }
317
- const { parentNode, data } = this;
318
- if (!parentNode) {
319
- throw new Error('The text node to be split has no parent node!');
320
- }
321
- const newText = new AstText(data.slice(offset));
322
- (0, debug_1.setChildNodes)(parentNode, parentNode.childNodes.indexOf(this) + 1, 0, [newText]);
323
- this.setAttribute('data', data.slice(0, offset));
324
- return newText;
325
- }
326
- /** @private */
327
- getRelativeIndex(j) {
328
- if (j === undefined) {
329
- return super.getRelativeIndex();
330
- }
331
- else if (j < 0 || j > this.length) {
332
- throw new RangeError('Exceeding the text length range!');
333
- }
334
- return j;
335
- }
336
- /** 转义 `=` */
337
- escape() {
338
- const { TranscludeToken } = require('../src/transclude');
339
- for (let i = this.data.lastIndexOf('='); i >= 0; i = this.data.lastIndexOf('=', i - 1)) {
340
- if (i < this.length - 1) {
341
- this.splitText(i + 1);
342
- }
343
- this.after(debug_1.Shadow.run(
344
- // @ts-expect-error abstract class
345
- () => new TranscludeToken('=', [], this.parentNode.getAttribute('config'))));
346
- this.#setData(this.data.slice(0, i));
347
- }
348
- }
349
- /**
350
- * 生成HTML
351
- * @param nowrap 是否不换行
352
- */
353
- toHtml(nowrap) {
354
- const { data } = this;
355
- return (0, html_1.font)(this, (0, string_1.sanitize)(nowrap ? data.replaceAll('\n', ' ') : data));
356
- }
357
- /** @private */
358
- toHtmlInternal(nowrap) {
359
- const mt = /\n[^\S\n]*$/u.exec(this.data);
360
- if (mt) {
361
- const spaces = [];
362
- let { nextSibling } = this, mt2 = null;
363
- while (nextSibling
364
- && (nextSibling.type === 'comment' || nextSibling.type === 'category' || nextSibling.type === 'text')) {
365
- if (nextSibling.type === 'text') {
366
- const { data } = nextSibling;
367
- mt2 = /^[^\S\n]*(?=\n)/u.exec(data);
368
- if (mt2 || data.trim()) {
369
- break;
370
- }
371
- else {
372
- spaces.push(nextSibling);
373
- }
374
- }
375
- else if (nextSibling.type === 'category') {
376
- const trimmed = this.data.trimEnd();
377
- if (this.data !== trimmed) {
378
- const { length } = trimmed;
379
- this.deleteData(length + this.data.slice(length).indexOf('\n'), Infinity);
380
- }
381
- for (const space of spaces) {
382
- space.#setData('');
383
- }
384
- spaces.length = 0;
385
- }
386
- ({ nextSibling } = nextSibling);
387
- }
388
- if (mt2) {
389
- this.deleteData(mt.index, Infinity);
390
- nextSibling.deleteData(0, mt2[0].length);
391
- for (const space of spaces) {
392
- space.#setData('');
393
- }
394
- }
395
- }
396
- return this.toHtml(nowrap);
397
- }
398
- }
399
- exports.AstText = AstText;
400
- constants_1.classes['AstText'] = __filename;
@@ -1,42 +0,0 @@
1
- import type { Config } from '../base';
2
- /** MediaWiki页面标题对象 */
3
- export declare class Title {
4
- #private;
5
- ns: number;
6
- fragment: string | undefined;
7
- interwiki: string;
8
- readonly valid: boolean;
9
- /** 不含命名空间的标题主体部分 */
10
- get main(): string;
11
- set main(title: string);
12
- /** 命名空间前缀 */
13
- get prefix(): string;
14
- /** 完整标题 */
15
- get title(): string;
16
- /** 扩展名 */
17
- get extension(): string | undefined;
18
- set extension(extension: string | undefined);
19
- /**
20
- * @see MediaWikiTitleCodec::splitTitleString
21
- *
22
- * @param title 标题(含或不含命名空间前缀)
23
- * @param defaultNs 命名空间
24
- * @param decode 是否需要解码
25
- * @param selfLink 是否允许selfLink
26
- */
27
- constructor(title: string, defaultNs: number, config: Config, decode: boolean, selfLink: boolean);
28
- /** 执行单向转换 */
29
- autoConvert(): void;
30
- /** 转换为主页面 */
31
- toSubjectPage(): void;
32
- /** 转换为讨论页面 */
33
- toTalkPage(): void;
34
- /** 是否是讨论页 */
35
- isTalkPage(): boolean;
36
- /** 转换为上一级页面 */
37
- toBasePage(): void;
38
- /** 转换为根页面 */
39
- toRootPage(): void;
40
- /** 生成URL */
41
- getUrl(): string;
42
- }
package/dist/lib/title.js DELETED
@@ -1,208 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Title = void 0;
4
- const string_1 = require("../util/string");
5
- const constants_1 = require("../util/constants");
6
- const index_1 = require("../index");
7
- /** MediaWiki页面标题对象 */
8
- class Title {
9
- #main;
10
- #namespaces;
11
- ns;
12
- fragment;
13
- interwiki = '';
14
- valid;
15
- /** @private */
16
- encoded = false;
17
- /* NOT FOR BROWSER */
18
- #fragment;
19
- #path;
20
- /** @private */
21
- conversionTable = new Map();
22
- /** @private */
23
- redirects = new Map();
24
- /* NOT FOR BROWSER END */
25
- /** 不含命名空间的标题主体部分 */
26
- get main() {
27
- return this.#main;
28
- }
29
- set main(title) {
30
- title = title.replace(/_/gu, ' ').trim();
31
- this.#main = title && title[0].toUpperCase() + title.slice(1);
32
- }
33
- /** 命名空间前缀 */
34
- get prefix() {
35
- const namespace = this.#namespaces[this.ns];
36
- return namespace + (namespace && ':');
37
- }
38
- /** 完整标题 */
39
- get title() {
40
- const prefix = this.interwiki + (this.interwiki && ':') + this.prefix;
41
- let title = (prefix + this.main).replace(/ /gu, '_');
42
- /* NOT FOR BROWSER */
43
- let redirected = this.#redirect(title);
44
- if (redirected) {
45
- return redirected;
46
- }
47
- this.autoConvert();
48
- title = (prefix + this.main).replaceAll(' ', '_');
49
- redirected = this.#redirect(title);
50
- if (redirected) {
51
- return redirected;
52
- }
53
- /* NOT FOR BROWSER END */
54
- return title;
55
- }
56
- /** 扩展名 */
57
- get extension() {
58
- const { main } = this, i = main.lastIndexOf('.');
59
- return i === -1 ? undefined : main.slice(i + 1).toLowerCase();
60
- }
61
- /* NOT FOR BROWSER */
62
- set extension(extension) {
63
- extension ||= '';
64
- const { main } = this, i = main.lastIndexOf('.');
65
- this.main = (i === -1 ? main : main.slice(0, i)) + (extension && '.') + extension;
66
- }
67
- /* NOT FOR BROWSER END */
68
- /**
69
- * @see MediaWikiTitleCodec::splitTitleString
70
- *
71
- * @param title 标题(含或不含命名空间前缀)
72
- * @param defaultNs 命名空间
73
- * @param decode 是否需要解码
74
- * @param selfLink 是否允许selfLink
75
- */
76
- constructor(title, defaultNs, config, decode, selfLink) {
77
- const subpage = title.trim().startsWith('../');
78
- title = (0, string_1.decodeHtml)(title);
79
- if (decode && title.includes('%')) {
80
- try {
81
- const encoded = /%(?!21|3[ce]|5[bd]|7[b-d])[\da-f]{2}/iu.test(title);
82
- title = (0, string_1.rawurldecode)(title);
83
- this.encoded = encoded;
84
- }
85
- catch { }
86
- }
87
- title = title.replace(/[_ ]+/gu, ' ').trim();
88
- if (subpage) {
89
- this.ns = 0;
90
- }
91
- else {
92
- let ns = defaultNs;
93
- if (title.startsWith(':')) {
94
- ns = 0;
95
- title = title.slice(1).trim();
96
- }
97
- /* NOT FOR BROWSER */
98
- const iw = defaultNs ? null : index_1.default.isInterwiki(title, config);
99
- if (iw) {
100
- this.interwiki = iw[1].toLowerCase();
101
- title = title.slice(iw.indices[0][1]);
102
- }
103
- /* NOT FOR BROWSER END */
104
- const m = title.split(':');
105
- if (m.length > 1) {
106
- const k = m[0].trim().toLowerCase(), id = Object.prototype.hasOwnProperty.call(config.nsid, k) && config.nsid[k];
107
- if (id) {
108
- ns = id;
109
- title = m.slice(1).join(':').trim();
110
- }
111
- }
112
- this.ns = ns;
113
- }
114
- const i = title.indexOf('#');
115
- if (i !== -1) {
116
- let fragment = title.slice(i + 1).trimEnd();
117
- if (fragment.includes('%')) {
118
- try {
119
- fragment = (0, string_1.rawurldecode)(fragment);
120
- }
121
- catch { }
122
- }
123
- this.fragment = fragment;
124
- title = title.slice(0, i).trim();
125
- }
126
- this.valid = Boolean(title || this.interwiki || selfLink && this.ns === 0 && this.fragment !== undefined)
127
- && !/^:|\0\d+[eh!+-]\x7F|[<>[\]{}|\n]|%[\da-f]{2}|(?:^|\/)\.{1,2}(?:$|\/)/iu.test(subpage ? /^(?:\.\.\/)+(.*)/u.exec(title)[1] : title);
128
- this.main = title;
129
- Object.defineProperties(this, {
130
- encoded: { enumerable: false, writable: false },
131
- /* NOT FOR BROWSER */
132
- valid: { writable: false },
133
- conversionTable: { enumerable: false },
134
- redirects: { enumerable: false },
135
- });
136
- this.#namespaces = config.namespaces;
137
- this.#path = config.articlePath || '/wiki/$1';
138
- }
139
- /** @private */
140
- toString() {
141
- return `${this.title}${this.fragment === undefined
142
- && this.#fragment === undefined
143
- ? ''
144
- : `#${this.fragment
145
- ?? this.#fragment}`}`;
146
- }
147
- /* NOT FOR BROWSER */
148
- /**
149
- * 处理重定向
150
- * @param title 原标题
151
- */
152
- #redirect(title) {
153
- const redirected = this.redirects.get(title);
154
- if (redirected) {
155
- [title, this.#fragment] = redirected.split('#', 2);
156
- return title;
157
- }
158
- return '';
159
- }
160
- /** 执行单向转换 */
161
- autoConvert() {
162
- const { conversionTable } = this;
163
- if (conversionTable.size > 0) {
164
- const regex = new RegExp([...conversionTable.keys()].sort().reverse().map(string_1.escapeRegExp).join('|'), 'gu');
165
- this.main = this.main.replace(regex, p => conversionTable.get(p));
166
- }
167
- }
168
- /** 转换为主页面 */
169
- toSubjectPage() {
170
- if (this.isTalkPage()) {
171
- this.ns--;
172
- }
173
- }
174
- /** 转换为讨论页面 */
175
- toTalkPage() {
176
- if (!this.isTalkPage()) {
177
- this.ns++;
178
- }
179
- }
180
- /** 是否是讨论页 */
181
- isTalkPage() {
182
- return this.ns % 2 === 1;
183
- }
184
- /** 转换为上一级页面 */
185
- toBasePage() {
186
- this.main = this.main.replace(/\/[^/]*$/u, '');
187
- }
188
- /** 转换为根页面 */
189
- toRootPage() {
190
- this.main = this.main.replace(/\/.*/u, '');
191
- }
192
- /** 生成URL */
193
- getUrl() {
194
- const { title, fragment } = this;
195
- if (title) {
196
- return this.#path.replace('$1', `${encodeURIComponent(title)}${fragment === undefined && this.#fragment === undefined
197
- ? ''
198
- : `#${encodeURIComponent(fragment ?? this.#fragment)}`}`);
199
- }
200
- return fragment === undefined ? '' : `#${encodeURIComponent(fragment)}`;
201
- }
202
- /** @private */
203
- getTitleAttr() {
204
- return this.title.replace(/["_]/gu, p => p === '"' ? '&quot;' : ' ');
205
- }
206
- }
207
- exports.Title = Title;
208
- constants_1.classes['Title'] = __filename;
@@ -1,49 +0,0 @@
1
- export interface AttributesParentBase {
2
- /** getAttrs()方法的getter写法 */
3
- attributes: Record<string, string | true>;
4
- /** 以字符串表示的class属性 */
5
- className: string;
6
- /** 以Set表示的class属性 */
7
- classList: Set<string>;
8
- /** id属性 */
9
- id: string;
10
- /**
11
- * 获取AttributesToken子节点的属性
12
- * @param key 属性键
13
- */
14
- getAttr(key: string): string | true | undefined;
15
- /**
16
- * AttributesToken子节点是否具有某属性
17
- * @param key 属性键
18
- */
19
- hasAttr(key: string): boolean;
20
- /** 列举AttributesToken子节点的属性键 */
21
- getAttrNames(): Set<string>;
22
- /** 获取AttributesToken子节点的全部标签属性 */
23
- getAttrs(): Record<string, string | true>;
24
- /**
25
- * 对AttributesToken子节点设置属性
26
- * @param key 属性键
27
- * @param value 属性值
28
- * @param prop 属性对象
29
- */
30
- setAttr(key: string, value: string | boolean): void;
31
- setAttr(prop: Record<string, string | boolean>): void;
32
- /**
33
- * 移除AttributesToken子节点的某属性
34
- * @param key 属性键
35
- */
36
- removeAttr(key: string): void;
37
- /**
38
- * 开关AttributesToken子节点的某属性
39
- * @param key 属性键
40
- * @param force 强制开启或关闭
41
- */
42
- toggleAttr(key: string, force?: boolean): void;
43
- }
44
- /**
45
- * 子节点含有AttributesToken的类
46
- * @param i AttributesToken子节点的位置
47
- * @param constructor 基类
48
- * @param _ context
49
- */