wikiparser-node 1.9.0 → 1.9.1-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 (170) hide show
  1. package/README.en.md +2 -2
  2. package/bundle/bundle.min.js +38 -0
  3. package/config/enwiki.json +1 -814
  4. package/config/llwiki.json +1 -35
  5. package/config/moegirl.json +1 -44
  6. package/config/zhwiki.json +1 -466
  7. package/extensions/dist/base.js +64 -0
  8. package/extensions/dist/editor.js +159 -0
  9. package/extensions/dist/highlight.js +58 -0
  10. package/extensions/dist/lint.js +72 -0
  11. package/extensions/editor.css +64 -0
  12. package/extensions/ui.css +144 -0
  13. package/package.json +38 -28
  14. package/config/.schema.json +0 -181
  15. package/dist/addon/table.js +0 -485
  16. package/dist/addon/token.js +0 -236
  17. package/dist/addon/transclude.js +0 -183
  18. package/dist/base.d.ts +0 -71
  19. package/dist/base.js +0 -39
  20. package/dist/index.d.ts +0 -33
  21. package/dist/index.js +0 -218
  22. package/dist/internal.d.ts +0 -46
  23. package/dist/lib/element.d.ts +0 -129
  24. package/dist/lib/element.js +0 -593
  25. package/dist/lib/node.d.ts +0 -166
  26. package/dist/lib/node.js +0 -480
  27. package/dist/lib/range.d.ts +0 -105
  28. package/dist/lib/range.js +0 -406
  29. package/dist/lib/ranges.d.ts +0 -28
  30. package/dist/lib/ranges.js +0 -126
  31. package/dist/lib/text.d.ts +0 -54
  32. package/dist/lib/text.js +0 -350
  33. package/dist/lib/title.d.ts +0 -40
  34. package/dist/lib/title.js +0 -197
  35. package/dist/mixin/attributesParent.d.ts +0 -49
  36. package/dist/mixin/attributesParent.js +0 -81
  37. package/dist/mixin/fixed.d.ts +0 -5
  38. package/dist/mixin/fixed.js +0 -30
  39. package/dist/mixin/flagsParent.d.ts +0 -41
  40. package/dist/mixin/flagsParent.js +0 -59
  41. package/dist/mixin/hidden.d.ts +0 -4
  42. package/dist/mixin/hidden.js +0 -24
  43. package/dist/mixin/magicLinkParent.d.ts +0 -19
  44. package/dist/mixin/magicLinkParent.js +0 -42
  45. package/dist/mixin/singleLine.d.ts +0 -5
  46. package/dist/mixin/singleLine.js +0 -26
  47. package/dist/mixin/sol.d.ts +0 -5
  48. package/dist/mixin/sol.js +0 -43
  49. package/dist/mixin/syntax.d.ts +0 -8
  50. package/dist/mixin/syntax.js +0 -50
  51. package/dist/parser/braces.js +0 -139
  52. package/dist/parser/commentAndExt.js +0 -89
  53. package/dist/parser/converter.js +0 -40
  54. package/dist/parser/externalLinks.js +0 -44
  55. package/dist/parser/hrAndDoubleUnderscore.js +0 -40
  56. package/dist/parser/html.js +0 -38
  57. package/dist/parser/links.js +0 -99
  58. package/dist/parser/list.js +0 -97
  59. package/dist/parser/magicLinks.js +0 -59
  60. package/dist/parser/quotes.js +0 -67
  61. package/dist/parser/redirect.js +0 -26
  62. package/dist/parser/selector.js +0 -190
  63. package/dist/parser/table.js +0 -123
  64. package/dist/src/arg.d.ts +0 -54
  65. package/dist/src/arg.js +0 -214
  66. package/dist/src/atom.d.ts +0 -12
  67. package/dist/src/atom.js +0 -27
  68. package/dist/src/attribute.d.ts +0 -67
  69. package/dist/src/attribute.js +0 -502
  70. package/dist/src/attributes.d.ts +0 -105
  71. package/dist/src/attributes.js +0 -356
  72. package/dist/src/converter.d.ts +0 -31
  73. package/dist/src/converter.js +0 -134
  74. package/dist/src/converterFlags.d.ts +0 -83
  75. package/dist/src/converterFlags.js +0 -242
  76. package/dist/src/converterRule.d.ts +0 -75
  77. package/dist/src/converterRule.js +0 -209
  78. package/dist/src/extLink.d.ts +0 -39
  79. package/dist/src/extLink.js +0 -191
  80. package/dist/src/gallery.d.ts +0 -50
  81. package/dist/src/gallery.js +0 -139
  82. package/dist/src/heading.d.ts +0 -43
  83. package/dist/src/heading.js +0 -190
  84. package/dist/src/hidden.d.ts +0 -7
  85. package/dist/src/hidden.js +0 -23
  86. package/dist/src/html.d.ts +0 -61
  87. package/dist/src/html.js +0 -358
  88. package/dist/src/imageParameter.d.ts +0 -61
  89. package/dist/src/imageParameter.js +0 -257
  90. package/dist/src/imagemap.d.ts +0 -50
  91. package/dist/src/imagemap.js +0 -144
  92. package/dist/src/imagemapLink.d.ts +0 -31
  93. package/dist/src/imagemapLink.js +0 -93
  94. package/dist/src/index.d.ts +0 -142
  95. package/dist/src/index.js +0 -717
  96. package/dist/src/link/base.d.ts +0 -48
  97. package/dist/src/link/base.js +0 -228
  98. package/dist/src/link/category.d.ts +0 -22
  99. package/dist/src/link/category.js +0 -30
  100. package/dist/src/link/file.d.ts +0 -96
  101. package/dist/src/link/file.js +0 -272
  102. package/dist/src/link/galleryImage.d.ts +0 -30
  103. package/dist/src/link/galleryImage.js +0 -157
  104. package/dist/src/link/index.d.ts +0 -54
  105. package/dist/src/link/index.js +0 -133
  106. package/dist/src/link/redirectTarget.d.ts +0 -49
  107. package/dist/src/link/redirectTarget.js +0 -101
  108. package/dist/src/magicLink.d.ts +0 -59
  109. package/dist/src/magicLink.js +0 -261
  110. package/dist/src/nested.d.ts +0 -41
  111. package/dist/src/nested.js +0 -105
  112. package/dist/src/nowiki/base.d.ts +0 -31
  113. package/dist/src/nowiki/base.js +0 -93
  114. package/dist/src/nowiki/comment.d.ts +0 -21
  115. package/dist/src/nowiki/comment.js +0 -76
  116. package/dist/src/nowiki/dd.d.ts +0 -8
  117. package/dist/src/nowiki/dd.js +0 -24
  118. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -16
  119. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  120. package/dist/src/nowiki/hr.d.ts +0 -5
  121. package/dist/src/nowiki/hr.js +0 -63
  122. package/dist/src/nowiki/index.d.ts +0 -14
  123. package/dist/src/nowiki/index.js +0 -27
  124. package/dist/src/nowiki/list.d.ts +0 -16
  125. package/dist/src/nowiki/list.js +0 -109
  126. package/dist/src/nowiki/listBase.d.ts +0 -5
  127. package/dist/src/nowiki/listBase.js +0 -61
  128. package/dist/src/nowiki/noinclude.d.ts +0 -10
  129. package/dist/src/nowiki/noinclude.js +0 -23
  130. package/dist/src/nowiki/quote.d.ts +0 -17
  131. package/dist/src/nowiki/quote.js +0 -137
  132. package/dist/src/onlyinclude.d.ts +0 -14
  133. package/dist/src/onlyinclude.js +0 -57
  134. package/dist/src/paramTag/index.d.ts +0 -33
  135. package/dist/src/paramTag/index.js +0 -77
  136. package/dist/src/paramTag/inputbox.d.ts +0 -8
  137. package/dist/src/paramTag/inputbox.js +0 -22
  138. package/dist/src/parameter.d.ts +0 -66
  139. package/dist/src/parameter.js +0 -264
  140. package/dist/src/pre.d.ts +0 -29
  141. package/dist/src/pre.js +0 -59
  142. package/dist/src/redirect.d.ts +0 -28
  143. package/dist/src/redirect.js +0 -119
  144. package/dist/src/syntax.d.ts +0 -17
  145. package/dist/src/syntax.js +0 -86
  146. package/dist/src/table/base.d.ts +0 -27
  147. package/dist/src/table/base.js +0 -81
  148. package/dist/src/table/index.d.ts +0 -240
  149. package/dist/src/table/index.js +0 -498
  150. package/dist/src/table/td.d.ts +0 -82
  151. package/dist/src/table/td.js +0 -358
  152. package/dist/src/table/tr.d.ts +0 -32
  153. package/dist/src/table/tr.js +0 -58
  154. package/dist/src/table/trBase.d.ts +0 -51
  155. package/dist/src/table/trBase.js +0 -156
  156. package/dist/src/tagPair/ext.d.ts +0 -30
  157. package/dist/src/tagPair/ext.js +0 -203
  158. package/dist/src/tagPair/include.d.ts +0 -33
  159. package/dist/src/tagPair/include.js +0 -74
  160. package/dist/src/tagPair/index.d.ts +0 -25
  161. package/dist/src/tagPair/index.js +0 -128
  162. package/dist/src/transclude.d.ts +0 -162
  163. package/dist/src/transclude.js +0 -584
  164. package/dist/util/constants.js +0 -27
  165. package/dist/util/debug.js +0 -81
  166. package/dist/util/diff.js +0 -83
  167. package/dist/util/lint.js +0 -31
  168. package/dist/util/string.js +0 -60
  169. package/errors/README +0 -1
  170. package/printed/README +0 -1
@@ -1,54 +0,0 @@
1
- import { AstNode } from './node';
2
- import type { LintError } from '../base';
3
- /** 文本节点 */
4
- export declare class AstText extends AstNode {
5
- #private;
6
- readonly type = "text";
7
- readonly name: undefined;
8
- readonly data: string;
9
- /** 文本长度 */
10
- get length(): number;
11
- /** @param text 包含文本 */
12
- constructor(text: string);
13
- /** 可见部分 */
14
- text(): string;
15
- /**
16
- * 替换字符串
17
- * @param text 替换的字符串
18
- */
19
- replaceData(text: string): void;
20
- /** 复制 */
21
- cloneNode(): AstText;
22
- /**
23
- * 在后方添加字符串
24
- * @param text 添加的字符串
25
- */
26
- appendData(text: string): void;
27
- /**
28
- * 删减字符串
29
- * @param offset 起始位置
30
- * @param count 删减字符数
31
- */
32
- deleteData(offset: number, count: number): void;
33
- /**
34
- * 插入字符串
35
- * @param offset 插入位置
36
- * @param text 待插入的字符串
37
- */
38
- insertData(offset: number, text: string): void;
39
- /**
40
- * 提取子串
41
- * @param offset 起始位置
42
- * @param count 字符数
43
- */
44
- substringData(offset: number, count: number): string;
45
- /**
46
- * 将文本子节点分裂为两部分
47
- * @param offset 分裂位置
48
- * @throws `RangeError` 错误的断开位置
49
- * @throws `Error` 没有父节点
50
- */
51
- splitText(offset: number): AstText;
52
- /** 转义 `=` */
53
- escape(): void;
54
- }
package/dist/lib/text.js DELETED
@@ -1,350 +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'), extImage = new RegExp(`^https?:\\/\\/${string_1.extUrlCharFirst}${string_1.extUrlChar}\\.(?:gif|png|jpg|jpeg)$`, 'iu'), 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
- /** @private */
114
- lint(start = this.getAbsoluteIndex(), errorRegex) {
115
- const { data, parentNode, nextSibling, previousSibling } = this;
116
- if (!parentNode) {
117
- throw new Error('无法对孤立文本节点进行语法分析!');
118
- }
119
- const { type, name, parentNode: grandparent } = parentNode;
120
- let isHtmlAttrVal = false;
121
- if (type === 'attr-value') {
122
- const { type: grandType, name: grandName, tag } = grandparent;
123
- if (grandType !== 'ext-attr') {
124
- isHtmlAttrVal = true;
125
- }
126
- else if (tag === 'choose' && (grandName === 'before' || grandName === 'after')) {
127
- return [];
128
- }
129
- }
130
- errorRegex ??= type === 'free-ext-link'
131
- || type === 'ext-link-url'
132
- || type === 'image-parameter' && name === 'link'
133
- || isHtmlAttrVal
134
- ? errorSyntaxUrl
135
- : errorSyntax;
136
- if (data.search(errorRegex) === -1) {
137
- return [];
138
- }
139
- errorRegex.lastIndex = 0;
140
- 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));
141
- for (let mt = errorRegex.exec(data); mt; mt = errorRegex.exec(data)) {
142
- const [, tag, prefix] = mt;
143
- let { 0: error, index } = mt;
144
- if (prefix && prefix !== ']') {
145
- const { length } = prefix;
146
- index += length;
147
- error = error.slice(length);
148
- }
149
- const { 0: char, length } = error;
150
- if (char === '<' && !tags.has(tag.toLowerCase())
151
- || char === '['
152
- && type === 'ext-link-text'
153
- && (/&(?:rbrack|#93|#x5[Dd];);/u.test(data.slice(index + 1))
154
- || nextType === 'ext'
155
- && nextName === 'nowiki'
156
- && nextSibling.innerText?.includes(']'))) {
157
- continue;
158
- }
159
- else if (char === ']' && (index || length > 1)) {
160
- errorRegex.lastIndex--;
161
- }
162
- else if (char === 'h' && index === 0 && type === 'ext-link-text' && extImage.test(data)) {
163
- continue;
164
- }
165
- 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 ?? '')
166
- || isHtmlAttrVal && (char === '[' || char === ']'))
167
- || char === '{' && (nextChar === char || previousChar === '-')
168
- || char === '}' && (previousChar === char || nextChar === '-')
169
- || char === '[' && (nextChar === char
170
- || type === 'ext-link-text'
171
- || nextType === 'free-ext-link' && !data.slice(index + 1).trim())
172
- || char === ']' && (previousChar === char
173
- || previousType === 'free-ext-link' && !data.slice(0, index).includes(']'))
174
- ? 'error'
175
- : 'warning';
176
- const leftBracket = char === '{' || char === '[', rightBracket = char === ']' || char === '}';
177
- if (severity === 'warning' && (leftBracket || rightBracket)) {
178
- const regex = regexes[char], remains = leftBracket ? data.slice(index + 1) : data.slice(0, index);
179
- if (char === '{' && regex.exec(remains)?.[0] === '}'
180
- || char === '}' && regex.exec(remains)?.[0] === '{') {
181
- continue;
182
- }
183
- else if (!remains.includes(char)) {
184
- const sibling = leftBracket ? 'nextSibling' : 'previousSibling';
185
- let cur = this[sibling];
186
- while (cur && (cur.type !== 'text' || !regex.test(cur.data))) {
187
- cur = cur[sibling];
188
- }
189
- if (cur && regex.exec(cur.data)[0] !== char) {
190
- continue;
191
- }
192
- }
193
- }
194
- 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 = {
195
- rule: ruleMap[char],
196
- message: index_1.default.msg('lonely "$1"', char === 'h' ? error : char),
197
- severity,
198
- startIndex,
199
- endIndex,
200
- startLine,
201
- endLine: startLine,
202
- startCol,
203
- endCol: startCol + length,
204
- };
205
- if (char === '<') {
206
- e.suggestions = [
207
- {
208
- desc: 'escape',
209
- range: [startIndex, startIndex + 1],
210
- text: '&lt;',
211
- },
212
- ];
213
- }
214
- else if (char === 'h'
215
- && !(type === 'ext-link-text' || type === 'link-text')
216
- && /[\p{L}\d_]/u.test(previousChar || '')) {
217
- e.suggestions = [
218
- {
219
- desc: 'whitespace',
220
- range: [startIndex, startIndex],
221
- text: ' ',
222
- },
223
- ];
224
- }
225
- else if (char === '[' && type === 'ext-link-text') {
226
- const i = parentNode.getAbsoluteIndex() + parentNode.toString().length;
227
- e.suggestions = [
228
- {
229
- desc: 'escape',
230
- range: [i, i + 1],
231
- text: '&#93;',
232
- },
233
- ];
234
- }
235
- else if (char === ']' && previousType === 'free-ext-link' && severity === 'error') {
236
- const i = start - previousSibling.toString().length;
237
- e.fix = {
238
- range: [i, i],
239
- text: '[',
240
- };
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(`错误的断开位置:${offset}`);
316
- }
317
- const { parentNode, data } = this;
318
- if (!parentNode) {
319
- throw new Error('待分裂的文本节点没有父节点!');
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('超出文本长度范围!');
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
- // @ts-expect-error abstract class
344
- this.after(new TranscludeToken('=', [], this.parentNode.getAttribute('config')));
345
- this.#setData(this.data.slice(0, i));
346
- }
347
- }
348
- }
349
- exports.AstText = AstText;
350
- 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,197 +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
- /** @private */
25
- conversionTable = new Map();
26
- /** @private */
27
- redirects = new Map();
28
- /* NOT FOR BROWSER END */
29
- /** 不含命名空间的标题主体部分 */
30
- get main() {
31
- return this.#main;
32
- }
33
- set main(title) {
34
- title = title.replace(/_/gu, ' ').trim();
35
- this.#main = title && title[0].toUpperCase() + title.slice(1);
36
- }
37
- /** 命名空间前缀 */
38
- get prefix() {
39
- const namespace = this.#namespaces[this.ns];
40
- return namespace + (namespace && ':');
41
- }
42
- /** 完整标题 */
43
- get title() {
44
- const prefix = this.interwiki + (this.interwiki && ':') + this.prefix;
45
- let title = (prefix + this.main).replace(/ /gu, '_');
46
- /* NOT FOR BROWSER */
47
- let redirected = this.#redirect(title);
48
- if (redirected) {
49
- return redirected;
50
- }
51
- this.autoConvert();
52
- title = (prefix + this.main).replace(/ /gu, '_');
53
- redirected = this.#redirect(title);
54
- if (redirected) {
55
- return redirected;
56
- }
57
- /* NOT FOR BROWSER END */
58
- return title;
59
- }
60
- /** 扩展名 */
61
- get extension() {
62
- const { main } = this, i = main.lastIndexOf('.');
63
- return i === -1 ? undefined : main.slice(i + 1).toLowerCase();
64
- }
65
- /* NOT FOR BROWSER */
66
- set extension(extension) {
67
- extension ||= '';
68
- const { main } = this, i = main.lastIndexOf('.');
69
- this.main = (i === -1 ? main : main.slice(0, i)) + (extension && '.') + extension;
70
- }
71
- /* NOT FOR BROWSER END */
72
- /**
73
- * @see MediaWikiTitleCodec::splitTitleString
74
- *
75
- * @param title 标题(含或不含命名空间前缀)
76
- * @param defaultNs 命名空间
77
- * @param decode 是否需要解码
78
- * @param selfLink 是否允许selfLink
79
- */
80
- constructor(title, defaultNs, config, decode, selfLink) {
81
- const subpage = title.trim().startsWith('../');
82
- title = (0, string_1.decodeHtml)(title);
83
- if (decode && title.includes('%')) {
84
- try {
85
- const encoded = /%(?!21|3[ce]|5[bd]|7[b-d])[\da-f]{2}/iu.test(title);
86
- title = rawurldecode(title);
87
- this.encoded = encoded;
88
- }
89
- catch { }
90
- }
91
- title = title.replace(/_/gu, ' ').trim();
92
- if (subpage) {
93
- this.ns = 0;
94
- }
95
- else {
96
- let ns = defaultNs;
97
- if (title.startsWith(':')) {
98
- ns = 0;
99
- title = title.slice(1).trim();
100
- }
101
- /* NOT FOR BROWSER */
102
- const iw = defaultNs ? null : index_1.default.isInterwiki(title, config);
103
- if (iw) {
104
- this.interwiki = iw[1].toLowerCase();
105
- title = title.slice(iw.indices[0][1]);
106
- }
107
- /* NOT FOR BROWSER END */
108
- const m = title.split(':');
109
- if (m.length > 1) {
110
- const id = config.nsid[m[0].trim().toLowerCase()];
111
- if (id) {
112
- ns = id;
113
- title = m.slice(1).join(':').trim();
114
- }
115
- }
116
- this.ns = ns;
117
- }
118
- const i = title.indexOf('#');
119
- if (i !== -1) {
120
- let fragment = title.slice(i + 1).trimEnd();
121
- if (fragment.includes('%')) {
122
- try {
123
- fragment = rawurldecode(fragment);
124
- }
125
- catch { }
126
- }
127
- this.fragment = fragment;
128
- title = title.slice(0, i).trim();
129
- }
130
- this.valid = Boolean(title || this.interwiki || selfLink && this.ns === 0 && this.fragment !== undefined)
131
- && !/^:|\0\d+[eh!+-]\x7F|[<>[\]{}|\n]|%[\da-f]{2}|(?:^|\/)\.{1,2}(?:$|\/)/iu.test(subpage ? /^(?:\.\.\/)+(.*)/u.exec(title)[1] : title);
132
- this.main = title;
133
- Object.defineProperties(this, {
134
- encoded: { enumerable: false, writable: false },
135
- /* NOT FOR BROWSER */
136
- valid: { writable: false },
137
- conversionTable: { enumerable: false },
138
- redirects: { enumerable: false },
139
- });
140
- this.#namespaces = config.namespaces;
141
- }
142
- /** @private */
143
- toString() {
144
- return `${this.title}${this.fragment === undefined
145
- && this.#fragment === undefined
146
- ? ''
147
- : `#${this.fragment
148
- ?? this.#fragment}`}`;
149
- }
150
- /* NOT FOR BROWSER */
151
- /**
152
- * 处理重定向
153
- * @param title 原标题
154
- */
155
- #redirect(title) {
156
- const redirected = this.redirects.get(title);
157
- if (redirected) {
158
- [title, this.#fragment] = redirected.split('#', 2);
159
- return title;
160
- }
161
- return '';
162
- }
163
- /** 执行单向转换 */
164
- autoConvert() {
165
- const { conversionTable } = this;
166
- if (conversionTable.size > 0) {
167
- const regex = new RegExp([...conversionTable.keys()].sort().reverse().map(string_1.escapeRegExp).join('|'), 'gu');
168
- this.main = this.main.replace(regex, p => conversionTable.get(p));
169
- }
170
- }
171
- /** 转换为主页面 */
172
- toSubjectPage() {
173
- if (this.isTalkPage()) {
174
- this.ns--;
175
- }
176
- }
177
- /** 转换为讨论页面 */
178
- toTalkPage() {
179
- if (!this.isTalkPage()) {
180
- this.ns++;
181
- }
182
- }
183
- /** 是否是讨论页 */
184
- isTalkPage() {
185
- return this.ns % 2 === 1;
186
- }
187
- /** 转换为上一级页面 */
188
- toBasePage() {
189
- this.main = this.main.replace(/\/[^/]*$/u, '');
190
- }
191
- /** 转换为根页面 */
192
- toRootPage() {
193
- this.main = this.main.replace(/\/.*/u, '');
194
- }
195
- }
196
- exports.Title = Title;
197
- 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
- */