wikiparser-node 1.9.1-b → 1.9.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 (171) hide show
  1. package/config/.schema.json +181 -0
  2. package/config/enwiki.json +814 -1
  3. package/config/llwiki.json +35 -1
  4. package/config/moegirl.json +44 -1
  5. package/config/zhwiki.json +466 -1
  6. package/dist/addon/table.js +486 -0
  7. package/dist/addon/token.js +239 -0
  8. package/dist/addon/transclude.js +185 -0
  9. package/dist/base.d.ts +73 -0
  10. package/dist/base.js +39 -0
  11. package/dist/index.d.ts +31 -0
  12. package/dist/index.js +221 -0
  13. package/dist/internal.d.ts +46 -0
  14. package/dist/lib/element.d.ts +124 -0
  15. package/dist/lib/element.js +600 -0
  16. package/dist/lib/node.d.ts +166 -0
  17. package/dist/lib/node.js +480 -0
  18. package/dist/lib/range.d.ts +105 -0
  19. package/dist/lib/range.js +406 -0
  20. package/dist/lib/ranges.d.ts +28 -0
  21. package/dist/lib/ranges.js +126 -0
  22. package/dist/lib/rect.d.ts +18 -0
  23. package/dist/lib/rect.js +34 -0
  24. package/dist/lib/text.d.ts +54 -0
  25. package/dist/lib/text.js +345 -0
  26. package/dist/lib/title.d.ts +40 -0
  27. package/dist/lib/title.js +197 -0
  28. package/dist/mixin/attributesParent.d.ts +49 -0
  29. package/dist/mixin/attributesParent.js +82 -0
  30. package/dist/mixin/fixed.d.ts +5 -0
  31. package/dist/mixin/fixed.js +32 -0
  32. package/dist/mixin/flagsParent.d.ts +41 -0
  33. package/dist/mixin/flagsParent.js +60 -0
  34. package/dist/mixin/hidden.d.ts +6 -0
  35. package/dist/mixin/hidden.js +29 -0
  36. package/dist/mixin/magicLinkParent.d.ts +19 -0
  37. package/dist/mixin/magicLinkParent.js +43 -0
  38. package/dist/mixin/singleLine.d.ts +5 -0
  39. package/dist/mixin/singleLine.js +27 -0
  40. package/dist/mixin/sol.d.ts +5 -0
  41. package/dist/mixin/sol.js +44 -0
  42. package/dist/mixin/syntax.d.ts +8 -0
  43. package/dist/mixin/syntax.js +47 -0
  44. package/dist/parser/braces.js +146 -0
  45. package/dist/parser/commentAndExt.js +79 -0
  46. package/dist/parser/converter.js +39 -0
  47. package/dist/parser/externalLinks.js +37 -0
  48. package/dist/parser/hrAndDoubleUnderscore.js +42 -0
  49. package/dist/parser/html.js +38 -0
  50. package/dist/parser/links.js +101 -0
  51. package/dist/parser/list.js +97 -0
  52. package/dist/parser/magicLinks.js +53 -0
  53. package/dist/parser/quotes.js +67 -0
  54. package/dist/parser/redirect.js +26 -0
  55. package/dist/parser/selector.js +190 -0
  56. package/dist/parser/table.js +123 -0
  57. package/dist/src/arg.d.ts +52 -0
  58. package/dist/src/arg.js +213 -0
  59. package/dist/src/atom.d.ts +12 -0
  60. package/dist/src/atom.js +26 -0
  61. package/dist/src/attribute.d.ts +65 -0
  62. package/dist/src/attribute.js +490 -0
  63. package/dist/src/attributes.d.ts +103 -0
  64. package/dist/src/attributes.js +350 -0
  65. package/dist/src/converter.d.ts +29 -0
  66. package/dist/src/converter.js +134 -0
  67. package/dist/src/converterFlags.d.ts +81 -0
  68. package/dist/src/converterFlags.js +243 -0
  69. package/dist/src/converterRule.d.ts +73 -0
  70. package/dist/src/converterRule.js +210 -0
  71. package/dist/src/extLink.d.ts +37 -0
  72. package/dist/src/extLink.js +191 -0
  73. package/dist/src/gallery.d.ts +48 -0
  74. package/dist/src/gallery.js +139 -0
  75. package/dist/src/heading.d.ts +41 -0
  76. package/dist/src/heading.js +185 -0
  77. package/dist/src/hidden.d.ts +10 -0
  78. package/dist/src/hidden.js +79 -0
  79. package/dist/src/html.d.ts +58 -0
  80. package/dist/src/html.js +339 -0
  81. package/dist/src/imageParameter.d.ts +59 -0
  82. package/dist/src/imageParameter.js +261 -0
  83. package/dist/src/imagemap.d.ts +48 -0
  84. package/dist/src/imagemap.js +145 -0
  85. package/dist/src/imagemapLink.d.ts +31 -0
  86. package/dist/src/imagemapLink.js +93 -0
  87. package/dist/src/index.d.ts +130 -0
  88. package/dist/src/index.js +717 -0
  89. package/dist/src/link/base.d.ts +46 -0
  90. package/dist/src/link/base.js +224 -0
  91. package/dist/src/link/category.d.ts +22 -0
  92. package/dist/src/link/category.js +30 -0
  93. package/dist/src/link/file.d.ts +96 -0
  94. package/dist/src/link/file.js +274 -0
  95. package/dist/src/link/galleryImage.d.ts +30 -0
  96. package/dist/src/link/galleryImage.js +157 -0
  97. package/dist/src/link/index.d.ts +52 -0
  98. package/dist/src/link/index.js +133 -0
  99. package/dist/src/link/redirectTarget.d.ts +37 -0
  100. package/dist/src/link/redirectTarget.js +95 -0
  101. package/dist/src/magicLink.d.ts +60 -0
  102. package/dist/src/magicLink.js +271 -0
  103. package/dist/src/nested.d.ts +41 -0
  104. package/dist/src/nested.js +105 -0
  105. package/dist/src/nowiki/base.d.ts +31 -0
  106. package/dist/src/nowiki/base.js +92 -0
  107. package/dist/src/nowiki/comment.d.ts +15 -0
  108. package/dist/src/nowiki/comment.js +123 -0
  109. package/dist/src/nowiki/dd.d.ts +8 -0
  110. package/dist/src/nowiki/dd.js +24 -0
  111. package/dist/src/nowiki/doubleUnderscore.d.ts +16 -0
  112. package/dist/src/nowiki/doubleUnderscore.js +100 -0
  113. package/dist/src/nowiki/hr.d.ts +5 -0
  114. package/dist/src/nowiki/hr.js +63 -0
  115. package/dist/src/nowiki/index.d.ts +14 -0
  116. package/dist/src/nowiki/index.js +29 -0
  117. package/dist/src/nowiki/list.d.ts +16 -0
  118. package/dist/src/nowiki/list.js +109 -0
  119. package/dist/src/nowiki/listBase.d.ts +5 -0
  120. package/dist/src/nowiki/listBase.js +61 -0
  121. package/dist/src/nowiki/noinclude.d.ts +10 -0
  122. package/dist/src/nowiki/noinclude.js +73 -0
  123. package/dist/src/nowiki/quote.d.ts +17 -0
  124. package/dist/src/nowiki/quote.js +131 -0
  125. package/dist/src/onlyinclude.d.ts +14 -0
  126. package/dist/src/onlyinclude.js +57 -0
  127. package/dist/src/paramTag/index.d.ts +31 -0
  128. package/dist/src/paramTag/index.js +77 -0
  129. package/dist/src/paramTag/inputbox.d.ts +8 -0
  130. package/dist/src/paramTag/inputbox.js +22 -0
  131. package/dist/src/parameter.d.ts +66 -0
  132. package/dist/src/parameter.js +265 -0
  133. package/dist/src/pre.d.ts +29 -0
  134. package/dist/src/pre.js +59 -0
  135. package/dist/src/redirect.d.ts +31 -0
  136. package/dist/src/redirect.js +121 -0
  137. package/dist/src/syntax.d.ts +17 -0
  138. package/dist/src/syntax.js +85 -0
  139. package/dist/src/table/base.d.ts +27 -0
  140. package/dist/src/table/base.js +81 -0
  141. package/dist/src/table/index.d.ts +239 -0
  142. package/dist/src/table/index.js +499 -0
  143. package/dist/src/table/td.d.ts +78 -0
  144. package/dist/src/table/td.js +368 -0
  145. package/dist/src/table/tr.d.ts +30 -0
  146. package/dist/src/table/tr.js +57 -0
  147. package/dist/src/table/trBase.d.ts +49 -0
  148. package/dist/src/table/trBase.js +156 -0
  149. package/dist/src/tagPair/ext.d.ts +30 -0
  150. package/dist/src/tagPair/ext.js +201 -0
  151. package/dist/src/tagPair/include.d.ts +35 -0
  152. package/dist/src/tagPair/include.js +124 -0
  153. package/dist/src/tagPair/index.d.ts +23 -0
  154. package/dist/src/tagPair/index.js +128 -0
  155. package/dist/src/transclude.d.ts +160 -0
  156. package/dist/src/transclude.js +582 -0
  157. package/dist/util/constants.js +27 -0
  158. package/dist/util/debug.js +90 -0
  159. package/dist/util/diff.js +83 -0
  160. package/dist/util/lint.js +32 -0
  161. package/dist/util/string.js +60 -0
  162. package/errors/README +1 -0
  163. package/package.json +20 -30
  164. package/printed/README +1 -0
  165. package/bundle/bundle.min.js +0 -38
  166. package/extensions/dist/base.js +0 -64
  167. package/extensions/dist/editor.js +0 -159
  168. package/extensions/dist/highlight.js +0 -58
  169. package/extensions/dist/lint.js +0 -72
  170. package/extensions/editor.css +0 -64
  171. package/extensions/ui.css +0 -144
@@ -0,0 +1,271 @@
1
+ "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.MagicLinkToken = void 0;
38
+ const lint_1 = require("../util/lint");
39
+ const rect_1 = require("../lib/rect");
40
+ const debug_1 = require("../util/debug");
41
+ const constants_1 = require("../util/constants");
42
+ const string_1 = require("../util/string");
43
+ const syntax_1 = require("../mixin/syntax");
44
+ const index_1 = require("../index");
45
+ const index_2 = require("./index");
46
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
47
+ /(?:[\p{Zs}\t]|&nbsp;|&#0*160;|&#[xX]0*[aA]0;)+/gu;
48
+ const space = String.raw `(?:[\p{Zs}\t]|&nbsp;|&#0*160;|&#[xX]0*[aA]0;)`, spaceRegex = new RegExp(`${space}+`, 'gu');
49
+ /* eslint-disable @typescript-eslint/no-unused-expressions */
50
+ /^(ISBN)[\p{Zs}\t]+(?:97[89][\p{Zs}\t-]?)?(?:\d[\p{Zs}\t-]?){9}[\dxX]$/u;
51
+ /^(RFC|PMID)[\p{Zs}\t]+\d+$/u;
52
+ /* eslint-enable @typescript-eslint/no-unused-expressions */
53
+ const spdash = String.raw `(?:[\p{Zs}\t-]|&nbsp;|&#0*160;|&#[xX]0*[aA]0;)`, isbnPattern = new RegExp(String.raw `^(ISBN)${space}+(?:97[89]${spdash}?)?(?:\d${spdash}?){9}[\dxX]$`, 'u'), rfcPattern = new RegExp(String.raw `^(RFC|PMID)${space}+\d+$`, 'u');
54
+ /** NOT FOR BROWSER END */
55
+ /**
56
+ * 自由外链
57
+ * @classdesc `{childNodes: ...AstText|CommentToken|IncludeToken|NoincludeToken}`
58
+ */
59
+ let MagicLinkToken = (() => {
60
+ let _classDecorators = [(0, syntax_1.syntax)()];
61
+ let _classDescriptor;
62
+ let _classExtraInitializers = [];
63
+ let _classThis;
64
+ let _classSuper = index_2.Token;
65
+ var MagicLinkToken = class extends _classSuper {
66
+ static { _classThis = this; }
67
+ static {
68
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
69
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
70
+ MagicLinkToken = _classThis = _classDescriptor.value;
71
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
72
+ __runInitializers(_classThis, _classExtraInitializers);
73
+ }
74
+ /* NOT FOR BROWSER END */
75
+ /** 和内链保持一致 */
76
+ get link() {
77
+ const map = { '!': '|', '=': '=' };
78
+ let link = (0, string_1.text)(this.childNodes.map(child => {
79
+ const { type, name } = child;
80
+ return type === 'magic-word' && String(name) in map ? map[name] : child;
81
+ }));
82
+ if (this.type === 'magic-link') {
83
+ link = link.replace(spaceRegex, ' ');
84
+ if (link.startsWith('ISBN')) {
85
+ link = `ISBN ${link.slice(5).replace(/[- ]/gu, '').replace(/x$/u, 'X')}`;
86
+ }
87
+ }
88
+ return link;
89
+ }
90
+ /* NOT FOR BROWSER */
91
+ set link(url) {
92
+ this.setTarget(url);
93
+ }
94
+ /** 协议 */
95
+ get protocol() {
96
+ return this.pattern.exec(this.text())?.[1];
97
+ }
98
+ /** @throws `Error` 特殊外链无法更改协议n */
99
+ set protocol(value) {
100
+ const { link, pattern, type } = this;
101
+ if (type === 'magic-link' || !pattern.test(link)) {
102
+ throw new Error(`Special external link cannot change protocol: ${link}`);
103
+ }
104
+ this.setTarget(link.replace(pattern, value));
105
+ }
106
+ /* NOT FOR BROWSER END */
107
+ /**
108
+ * @param url 网址
109
+ * @param type 类型
110
+ */
111
+ constructor(url, type = 'free-ext-link', config = index_1.default.getConfig(), accum) {
112
+ super(url, config, accum, {
113
+ 'Stage-1': '1:', '!ExtToken': '', AstText: ':', TranscludeToken: ':',
114
+ });
115
+ this.type = type;
116
+ /* NOT FOR BROWSER */
117
+ let pattern;
118
+ if (type === 'magic-link') {
119
+ pattern = url?.startsWith('ISBN') ? isbnPattern : rfcPattern;
120
+ }
121
+ else {
122
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
123
+ /^(ftp:\/\/|\/\/)/iu;
124
+ pattern = new RegExp(`^(${config.protocol}${type === 'ext-link-url' ? '|//' : ''})`, 'iu');
125
+ }
126
+ this.setAttribute('pattern', pattern);
127
+ }
128
+ /** @private */
129
+ lint(start = this.getAbsoluteIndex(), re) {
130
+ const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start);
131
+ if (this.type === 'magic-link') {
132
+ const { link } = this;
133
+ if (link.startsWith('ISBN')) {
134
+ // eslint-disable-next-line unicorn/no-useless-spread
135
+ const digits = [...link.slice(5)].map(s => s === 'X' ? 10 : Number(s));
136
+ if (digits.length === 10 && digits.reduce((sum, d, i) => sum + d * (10 - i), 0) % 11
137
+ || digits.length === 13 && (digits[12] === 10
138
+ || digits.reduce((sum, d, i) => sum + d * (i % 2 ? 3 : 1), 0) % 10)) {
139
+ errors.push((0, lint_1.generateForSelf)(this, rect, 'invalid-isbn', 'invalid ISBN'));
140
+ }
141
+ }
142
+ return errors;
143
+ }
144
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
145
+ /[,;。:!?()]+|\|+/gu;
146
+ const source = `[,;。:!?()]+${this.type === 'ext-link-url' ? String.raw `|\|+` : ''}`, regex = new RegExp(source, 'u'), regexGlobal = new RegExp(source, 'gu');
147
+ for (const child of this.childNodes) {
148
+ const { type, data } = child;
149
+ if (type !== 'text' || !regex.test(data)) {
150
+ continue;
151
+ }
152
+ const refError = (0, lint_1.generateForChild)(child, rect, 'unterminated-url', '', 'warning');
153
+ regexGlobal.lastIndex = 0;
154
+ for (let mt = regexGlobal.exec(data); mt; mt = regexGlobal.exec(data)) {
155
+ const { index, 0: s } = mt, lines = data.slice(0, index).split('\n'), top = lines.length, left = lines[top - 1].length, startIndex = refError.startIndex + index, startLine = refError.startLine + top - 1, startCol = top === 1 ? refError.startCol + left : left, pipe = s.startsWith('|');
156
+ const e = {
157
+ ...refError,
158
+ message: index_1.default.msg('$1 in URL', pipe ? '"|"' : 'full-width punctuation'),
159
+ startIndex,
160
+ endIndex: startIndex + s.length,
161
+ startLine,
162
+ endLine: startLine,
163
+ startCol,
164
+ endCol: startCol + s.length,
165
+ };
166
+ if (!pipe) {
167
+ e.suggestions = [
168
+ {
169
+ desc: 'whitespace',
170
+ range: [startIndex, startIndex],
171
+ text: ' ',
172
+ },
173
+ {
174
+ desc: 'escape',
175
+ range: [startIndex, e.endIndex],
176
+ text: encodeURI(s),
177
+ },
178
+ ];
179
+ }
180
+ else if (s.length === 1) {
181
+ e.suggestions = [
182
+ {
183
+ desc: 'whitespace',
184
+ range: [startIndex, startIndex + 1],
185
+ text: ' ',
186
+ },
187
+ ];
188
+ }
189
+ errors.push(e);
190
+ }
191
+ }
192
+ return errors;
193
+ }
194
+ /* NOT FOR BROWSER */
195
+ /** @override */
196
+ cloneNode() {
197
+ const cloned = this.cloneChildNodes();
198
+ return debug_1.Shadow.run(() => {
199
+ // @ts-expect-error abstract class
200
+ const token = new MagicLinkToken(undefined, this.type, this.getAttribute('config'));
201
+ token.append(...cloned);
202
+ token.afterBuild();
203
+ return token;
204
+ });
205
+ }
206
+ insertAt(token, i) {
207
+ if (typeof token !== 'string') {
208
+ const { type, name } = token;
209
+ if (type === 'template') {
210
+ this.constructorError('cannot insert a template');
211
+ }
212
+ else if (!debug_1.Shadow.running && type === 'magic-word' && name !== '!' && name !== '=') {
213
+ this.constructorError('cannot insert magic words other than "{{!}}" or "{{=}}"');
214
+ }
215
+ }
216
+ return super.insertAt(token, i);
217
+ }
218
+ /**
219
+ * 获取网址
220
+ * @throws `Error` ISBN
221
+ * @throws `Error` 非标准协议
222
+ */
223
+ getUrl() {
224
+ const { type, protocol } = this;
225
+ let { link } = this;
226
+ if (type === 'magic-link') {
227
+ if (protocol === 'ISBN') {
228
+ throw new Error(`MagicLinkToken.getUrl method does not support ISBN links: ${link}`);
229
+ }
230
+ link = protocol === 'RFC'
231
+ ? `https://tools.ietf.org/html/rfc${link.slice(4)}`
232
+ : `https://pubmed.ncbi.nlm.nih.gov/${link.slice(5)}`;
233
+ }
234
+ else if (protocol === '//') {
235
+ link = `https:${link}`;
236
+ }
237
+ try {
238
+ return new URL(link);
239
+ }
240
+ catch (e) {
241
+ if (e instanceof TypeError && e.message === 'Invalid URL') {
242
+ throw new Error(`External link with a non-standard protocol: ${link}`);
243
+ }
244
+ throw e;
245
+ }
246
+ }
247
+ /**
248
+ * 设置外链目标
249
+ * @param url 含协议的网址
250
+ */
251
+ setTarget(url) {
252
+ const { childNodes } = index_1.default.parse(url, this.getAttribute('include'), 2, this.getAttribute('config'));
253
+ this.replaceChildren(...childNodes);
254
+ }
255
+ /** 是否是模板或魔术字参数 */
256
+ isParamValue() {
257
+ return this.closest('parameter')?.getValue() === this.text();
258
+ }
259
+ /** 转义 `=` */
260
+ escape() {
261
+ for (const child of this.childNodes) {
262
+ if (child.type === 'text') {
263
+ child.escape();
264
+ }
265
+ }
266
+ }
267
+ };
268
+ return MagicLinkToken = _classThis;
269
+ })();
270
+ exports.MagicLinkToken = MagicLinkToken;
271
+ constants_1.classes['MagicLinkToken'] = __filename;
@@ -0,0 +1,41 @@
1
+ import Parser from '../index';
2
+ import { Token } from './index';
3
+ import { ExtToken } from './tagPair/ext';
4
+ import { NoincludeToken } from './nowiki/noinclude';
5
+ import { CommentToken } from './nowiki/comment';
6
+ import type { LintError } from '../base';
7
+ import type { AttributesToken } from './attributes';
8
+ /**
9
+ * 嵌套式的扩展标签
10
+ * @classdesc `{childNodes: ...ExtToken|NoincludeToken|CommentToken}`
11
+ */
12
+ export declare abstract class NestedToken extends Token {
13
+ #private;
14
+ readonly type = "ext-inner";
15
+ readonly name: string;
16
+ readonly childNodes: readonly (ExtToken | NoincludeToken | CommentToken)[];
17
+ abstract get firstChild(): ExtToken | NoincludeToken | CommentToken | undefined;
18
+ abstract get lastChild(): ExtToken | NoincludeToken | CommentToken | undefined;
19
+ abstract get nextSibling(): undefined;
20
+ abstract get previousSibling(): AttributesToken;
21
+ abstract get parentNode(): ExtToken | undefined;
22
+ abstract get children(): (ExtToken | NoincludeToken | CommentToken)[];
23
+ abstract get firstElementChild(): ExtToken | NoincludeToken | CommentToken | undefined;
24
+ abstract get lastElementChild(): ExtToken | NoincludeToken | CommentToken | undefined;
25
+ abstract get previousElementSibling(): AttributesToken;
26
+ abstract get nextElementSibling(): undefined;
27
+ abstract get parentElement(): ExtToken | undefined;
28
+ /**
29
+ * @param regex 内层正则
30
+ * @param tags 内层标签名
31
+ */
32
+ constructor(wikitext: string | undefined, regex: RegExp, tags: readonly string[], config?: Parser.Config, accum?: Token[]);
33
+ /**
34
+ * @override
35
+ * @param token 待插入的子节点
36
+ * @param i 插入位置
37
+ */
38
+ insertAt<T extends Token>(token: T, i?: number): T;
39
+ /** @override */
40
+ cloneNode(): this;
41
+ }
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NestedToken = void 0;
4
+ const lint_1 = require("../util/lint");
5
+ const rect_1 = require("../lib/rect");
6
+ const debug_1 = require("../util/debug");
7
+ const constants_1 = require("../util/constants");
8
+ const index_1 = require("../index");
9
+ const index_2 = require("./index");
10
+ const ext_1 = require("./tagPair/ext");
11
+ const noinclude_1 = require("./nowiki/noinclude");
12
+ const comment_1 = require("./nowiki/comment");
13
+ /**
14
+ * 嵌套式的扩展标签
15
+ * @classdesc `{childNodes: ...ExtToken|NoincludeToken|CommentToken}`
16
+ */
17
+ class NestedToken extends index_2.Token {
18
+ type = 'ext-inner';
19
+ /* NOT FOR BROWSER */
20
+ #tags;
21
+ #regex;
22
+ /* NOT FOR BROWSER END */
23
+ /**
24
+ * @param regex 内层正则
25
+ * @param tags 内层标签名
26
+ */
27
+ constructor(wikitext, regex, tags, config = index_1.default.getConfig(), accum = []) {
28
+ wikitext = wikitext?.replace(regex, (comment, name, attr, inner, closing) => {
29
+ const str = `\0${accum.length + 1}${name ? 'e' : 'c'}\x7F`;
30
+ if (name) {
31
+ // @ts-expect-error abstract class
32
+ new ext_1.ExtToken(name, attr, inner, closing, config, accum);
33
+ }
34
+ else {
35
+ const closed = comment.endsWith('-->');
36
+ // @ts-expect-error abstract class
37
+ new comment_1.CommentToken(comment.slice(4, closed ? -3 : undefined), closed, config, accum);
38
+ }
39
+ return str;
40
+ }).replace(/(^|\0\d+[ce]\x7F)([^\0]+)(?=$|\0\d+[ce]\x7F)/gu, (_, lead, substr) => {
41
+ // @ts-expect-error abstract class
42
+ new noinclude_1.NoincludeToken(substr, config, accum);
43
+ return `${lead}\0${accum.length}c\x7F`;
44
+ });
45
+ super(wikitext, config, accum, {
46
+ NoincludeToken: ':', ExtToken: ':',
47
+ });
48
+ /* NOT FOR BROWSER */
49
+ this.#tags = [...tags];
50
+ this.#regex = regex;
51
+ }
52
+ /** @private */
53
+ lint(start = this.getAbsoluteIndex(), re) {
54
+ const rect = new rect_1.BoundingRect(this, start);
55
+ return [
56
+ ...super.lint(start, re),
57
+ ...this.childNodes.filter(child => {
58
+ if (child.type === 'ext' || child.type === 'comment') {
59
+ return false;
60
+ }
61
+ const str = child.toString().trim();
62
+ return str && !/^<!--.*-->$/su.test(str);
63
+ }).map(child => {
64
+ const e = (0, lint_1.generateForChild)(child, rect, 'no-ignored', index_1.default.msg('invalid content in <$1>', this.name));
65
+ e.suggestions = [
66
+ {
67
+ desc: 'remove',
68
+ range: [e.startIndex, e.endIndex],
69
+ text: '',
70
+ },
71
+ {
72
+ desc: 'comment',
73
+ range: [e.startIndex, e.startIndex],
74
+ text: `<!--${child.toString()}-->`,
75
+ },
76
+ ];
77
+ return e;
78
+ }),
79
+ ];
80
+ }
81
+ /* NOT FOR BROWSER */
82
+ /**
83
+ * @override
84
+ * @param token 待插入的子节点
85
+ * @param i 插入位置
86
+ */
87
+ insertAt(token, i) {
88
+ if (typeof token !== 'string' && token.type === 'ext' && !this.#tags.includes(token.name)) {
89
+ this.constructorError(`can only have ${this.#tags.join(' or ')} tags as child nodes`);
90
+ }
91
+ return super.insertAt(token, i);
92
+ }
93
+ /** @override */
94
+ cloneNode() {
95
+ const cloned = this.cloneChildNodes(), config = this.getAttribute('config');
96
+ return debug_1.Shadow.run(() => {
97
+ // @ts-expect-error abstract class
98
+ const token = new NestedToken(undefined, this.#regex, this.#tags, config);
99
+ token.append(...cloned);
100
+ return token;
101
+ });
102
+ }
103
+ }
104
+ exports.NestedToken = NestedToken;
105
+ constants_1.classes['NestedToken'] = __filename;
@@ -0,0 +1,31 @@
1
+ import { Token } from '../index';
2
+ import type { Config } from '../../base';
3
+ import type { AstText } from '../../lib/text';
4
+ declare type NowikiTypes = 'ext-inner' | 'comment' | 'dd' | 'double-underscore' | 'hr' | 'list' | 'noinclude' | 'quote';
5
+ /**
6
+ * 纯文字Token,不会被解析
7
+ * @classdesc `{childNodes: [AstText]}`
8
+ */
9
+ export declare abstract class NowikiBaseToken extends Token {
10
+ type: NowikiTypes;
11
+ readonly childNodes: readonly [AstText];
12
+ abstract get firstChild(): AstText;
13
+ abstract get lastChild(): AstText;
14
+ abstract get children(): [];
15
+ abstract get firstElementChild(): undefined;
16
+ abstract get lastElementChild(): undefined;
17
+ /** 纯文本部分 */
18
+ get innerText(): string;
19
+ /** @param wikitext default: `''` */
20
+ constructor(wikitext?: string, config?: Config, accum?: Token[]);
21
+ /** @override */
22
+ cloneNode(this: this & {
23
+ constructor: new (...args: any[]) => unknown;
24
+ }): this;
25
+ /**
26
+ * @override
27
+ * @param str 新文本
28
+ */
29
+ setText(str: string): string;
30
+ }
31
+ export {};
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.NowikiBaseToken = void 0;
38
+ const debug_1 = require("../../util/debug");
39
+ const constants_1 = require("../../util/constants");
40
+ const fixed_1 = require("../../mixin/fixed");
41
+ const index_1 = require("../index");
42
+ /**
43
+ * 纯文字Token,不会被解析
44
+ * @classdesc `{childNodes: [AstText]}`
45
+ */
46
+ let NowikiBaseToken = (() => {
47
+ let _classDecorators = [fixed_1.fixedToken];
48
+ let _classDescriptor;
49
+ let _classExtraInitializers = [];
50
+ let _classThis;
51
+ let _classSuper = index_1.Token;
52
+ var NowikiBaseToken = class extends _classSuper {
53
+ static { _classThis = this; }
54
+ static {
55
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
56
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
57
+ NowikiBaseToken = _classThis = _classDescriptor.value;
58
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
59
+ __runInitializers(_classThis, _classExtraInitializers);
60
+ }
61
+ /* NOT FOR BROWSER END */
62
+ /** 纯文本部分 */
63
+ get innerText() {
64
+ return this.firstChild.data;
65
+ }
66
+ /** @param wikitext default: `''` */
67
+ constructor(wikitext = '', config, accum) {
68
+ super(wikitext, config, accum);
69
+ }
70
+ /* NOT FOR BROWSER */
71
+ /** @override */
72
+ cloneNode() {
73
+ const { constructor, firstChild: { data }, type } = this;
74
+ return debug_1.Shadow.run(() => {
75
+ const token = new constructor(data, this.getAttribute('config'));
76
+ token.type = type;
77
+ token.afterBuild();
78
+ return token;
79
+ });
80
+ }
81
+ /**
82
+ * @override
83
+ * @param str 新文本
84
+ */
85
+ setText(str) {
86
+ return super.setText(str, 0);
87
+ }
88
+ };
89
+ return NowikiBaseToken = _classThis;
90
+ })();
91
+ exports.NowikiBaseToken = NowikiBaseToken;
92
+ constants_1.classes['NowikiBaseToken'] = __filename;
@@ -0,0 +1,15 @@
1
+ import { NowikiBaseToken } from './base';
2
+ import type { LintError, Config } from '../../base';
3
+ import type { Token } from '../index';
4
+ /** HTML注释,不可见 */
5
+ export declare abstract class CommentToken extends NowikiBaseToken {
6
+ readonly type = "comment";
7
+ closed: boolean;
8
+ /** 内部文本 */
9
+ get innerText(): string;
10
+ set innerText(text: string);
11
+ /** @param closed 是否闭合 */
12
+ constructor(wikitext: string, closed?: boolean, config?: Config, accum?: Token[]);
13
+ /** @override */
14
+ cloneNode(): this;
15
+ }