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