wikiparser-node 1.6.2 → 1.7.0-beta.0

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