wikiparser-node 1.13.1-b → 1.13.1

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