wikiparser-node 1.12.5-b → 1.12.6

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 +30 -29
  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 +494 -28
  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 +82 -0
  11. package/dist/base.js +40 -0
  12. package/dist/index.d.ts +33 -0
  13. package/dist/index.js +275 -0
  14. package/dist/internal.d.ts +47 -0
  15. package/dist/lib/element.d.ts +125 -0
  16. package/dist/lib/element.js +377 -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 +253 -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 +393 -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 +380 -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 +24 -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 +62 -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 +132 -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 -52
  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,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RedirectTargetToken = void 0;
4
+ const lint_1 = require("../../util/lint");
5
+ const index_1 = require("../../index");
6
+ const base_1 = require("./base");
7
+ const noinclude_1 = require("../nowiki/noinclude");
8
+ /* NOT FOR BROWSER */
9
+ const constants_1 = require("../../util/constants");
10
+ /* NOT FOR BROWSER END */
11
+ /**
12
+ * 重定向目标
13
+ * @classdesc `{childNodes: [AtomToken, ?NoincludeToken]}`
14
+ */
15
+ class RedirectTargetToken extends base_1.LinkBaseToken {
16
+ /* NOT FOR BROWSER END */
17
+ get type() {
18
+ return 'redirect-target';
19
+ }
20
+ /* NOT FOR BROWSER */
21
+ /** 链接显示文字 */
22
+ get innerText() {
23
+ return this.link.toString(true);
24
+ }
25
+ /* NOT FOR BROWSER END */
26
+ /**
27
+ * @param link 链接标题
28
+ * @param linkText 链接显示文字
29
+ * @param delimiter `|`
30
+ */
31
+ constructor(link, linkText, config = index_1.default.getConfig(), accum = []) {
32
+ super(link, undefined, config, accum);
33
+ if (linkText !== undefined) {
34
+ // @ts-expect-error abstract class
35
+ this.insertAt(new noinclude_1.NoincludeToken(linkText, config, accum));
36
+ }
37
+ /* NOT FOR BROWSER */
38
+ this.setAttribute('acceptable', { AtomToken: 0, NoincludeToken: 1 });
39
+ // @ts-expect-error abstract getter
40
+ this.firstChild.setAttribute('acceptable', { AstText: ':' });
41
+ }
42
+ /** @private */
43
+ getTitle() {
44
+ return this.normalizeTitle(this.firstChild.toString(), 0, true, true);
45
+ }
46
+ /** @private */
47
+ lint(start = this.getAbsoluteIndex()) {
48
+ const errors = super.lint(start, false);
49
+ if (this.length === 2) {
50
+ const e = (0, lint_1.generateForChild)(this.lastChild, { start }, 'no-ignored', 'useless link text');
51
+ e.startIndex--;
52
+ e.startCol--;
53
+ e.fix = { range: [e.startIndex, e.endIndex], text: '' };
54
+ errors.push(e);
55
+ }
56
+ return errors;
57
+ }
58
+ /* NOT FOR BROWSER */
59
+ /** @private */
60
+ setTarget(link) {
61
+ this.firstChild.setText(link);
62
+ }
63
+ /** @private */
64
+ setLinkText(linkStr) {
65
+ if (!linkStr) {
66
+ this.childNodes[1]?.remove();
67
+ }
68
+ }
69
+ }
70
+ exports.RedirectTargetToken = RedirectTargetToken;
71
+ constants_1.classes['RedirectTargetToken'] = __filename;
@@ -0,0 +1,57 @@
1
+ import Parser from '../index';
2
+ import { Token } from './index';
3
+ import type { LintError } from '../base';
4
+ import type { AstText, CommentToken, IncludeToken, NoincludeToken, TranscludeToken, AstNodes } from '../internal';
5
+ import type { SyntaxBase } from '../mixin/syntax';
6
+ declare type ExtLinkTypes = 'free-ext-link' | 'ext-link-url' | 'magic-link';
7
+ export interface MagicLinkToken extends SyntaxBase {
8
+ }
9
+ /** NOT FOR BROWSER END */
10
+ /**
11
+ * 自由外链
12
+ * @classdesc `{childNodes: ...AstText|CommentToken|IncludeToken|NoincludeToken}`
13
+ */
14
+ export declare abstract class MagicLinkToken extends Token {
15
+ #private;
16
+ readonly childNodes: readonly (AstText | CommentToken | IncludeToken | NoincludeToken | TranscludeToken)[];
17
+ abstract get firstChild(): AstText | TranscludeToken;
18
+ abstract get lastChild(): AstText | CommentToken | IncludeToken | NoincludeToken | TranscludeToken;
19
+ abstract get children(): (CommentToken | IncludeToken | NoincludeToken | TranscludeToken)[];
20
+ abstract get firstElementChild(): CommentToken | IncludeToken | NoincludeToken | TranscludeToken | undefined;
21
+ abstract get lastElementChild(): CommentToken | IncludeToken | NoincludeToken | TranscludeToken | undefined;
22
+ get type(): ExtLinkTypes;
23
+ /** 链接显示文字 */
24
+ get innerText(): string;
25
+ /** 和内链保持一致 */
26
+ get link(): string;
27
+ set link(url: string);
28
+ /** 协议 */
29
+ get protocol(): string | undefined;
30
+ /** @throws `Error` 特殊外链无法更改协议n */
31
+ set protocol(value: string);
32
+ /**
33
+ * @param url 网址
34
+ * @param type 类型
35
+ */
36
+ constructor(url?: string, type?: ExtLinkTypes, config?: Parser.Config, accum?: Token[]);
37
+ cloneNode(): this;
38
+ /**
39
+ * @override
40
+ * @param token 待插入的节点
41
+ * @param i 插入位置
42
+ */
43
+ insertAt(token: string, i?: number): AstText;
44
+ insertAt<T extends AstNodes>(token: T, i?: number): T;
45
+ /** 获取网址 */
46
+ getUrl(): URL | string;
47
+ /**
48
+ * 设置外链目标
49
+ * @param url 含协议的网址
50
+ */
51
+ setTarget(url: string): void;
52
+ /** 是否是模板或魔术字参数 */
53
+ isParamValue(): boolean;
54
+ /** 转义 `=` */
55
+ escape(): void;
56
+ }
57
+ export {};
@@ -0,0 +1,261 @@
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 string_1 = require("../util/string");
40
+ const rect_1 = require("../lib/rect");
41
+ const index_1 = require("../index");
42
+ const index_2 = require("./index");
43
+ /* NOT FOR BROWSER */
44
+ const debug_1 = require("../util/debug");
45
+ const constants_1 = require("../util/constants");
46
+ const html_1 = require("../util/html");
47
+ const syntax_1 = require("../mixin/syntax");
48
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
49
+ /(?:[\p{Zs}\t]|&nbsp;|&#0*160;|&#[xX]0*[aA]0;)+/gu;
50
+ const space = String.raw `(?:[\p{Zs}\t]|&nbsp;|&#0*160;|&#[xX]0*[aA]0;)`, spaceRegex = new RegExp(`${space}+`, 'gu');
51
+ /** NOT FOR BROWSER */
52
+ /* eslint-disable @typescript-eslint/no-unused-expressions */
53
+ /^(ISBN)[\p{Zs}\t]+(?:97[89][\p{Zs}\t-]?)?(?:\d[\p{Zs}\t-]?){9}[\dxX]$/u;
54
+ /^(RFC|PMID)[\p{Zs}\t]+\d+$/u;
55
+ /* eslint-enable @typescript-eslint/no-unused-expressions */
56
+ 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');
57
+ /** NOT FOR BROWSER END */
58
+ /**
59
+ * 自由外链
60
+ * @classdesc `{childNodes: ...AstText|CommentToken|IncludeToken|NoincludeToken}`
61
+ */
62
+ let MagicLinkToken = (() => {
63
+ let _classDecorators = [(0, syntax_1.syntax)()];
64
+ let _classDescriptor;
65
+ let _classExtraInitializers = [];
66
+ let _classThis;
67
+ let _classSuper = index_2.Token;
68
+ var MagicLinkToken = class extends _classSuper {
69
+ static { _classThis = this; }
70
+ static {
71
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
72
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
73
+ MagicLinkToken = _classThis = _classDescriptor.value;
74
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
75
+ __runInitializers(_classThis, _classExtraInitializers);
76
+ }
77
+ #type;
78
+ /* NOT FOR BROWSER END */
79
+ get type() {
80
+ return this.#type;
81
+ }
82
+ /** 链接显示文字 */
83
+ get innerText() {
84
+ const map = new Map([['!', '|'], ['=', '=']]);
85
+ let link = (0, string_1.text)(this.childNodes.map(child => {
86
+ const { type } = child, name = String(child.name);
87
+ return type === 'magic-word' && map.has(name) ? map.get(name) : child;
88
+ }));
89
+ if (this.type === 'magic-link') {
90
+ link = link.replace(spaceRegex, ' ');
91
+ }
92
+ return link;
93
+ }
94
+ /** 和内链保持一致 */
95
+ get link() {
96
+ const { innerText } = this;
97
+ if (this.type === 'magic-link') {
98
+ return innerText.startsWith('ISBN')
99
+ ? `ISBN ${innerText.slice(5).replace(/[- ]/gu, '').replace(/x$/u, 'X')}`
100
+ : innerText;
101
+ }
102
+ return (0, string_1.decodeNumber)(innerText);
103
+ }
104
+ /* NOT FOR BROWSER */
105
+ set link(url) {
106
+ this.setTarget(url);
107
+ }
108
+ /** 协议 */
109
+ get protocol() {
110
+ return this.pattern.exec(this.text())?.[1];
111
+ }
112
+ /** @throws `Error` 特殊外链无法更改协议n */
113
+ set protocol(value) {
114
+ const { link, pattern, type } = this;
115
+ if (type === 'magic-link' || !pattern.test(link)) {
116
+ throw new Error(`Special external link cannot change protocol: ${link}`);
117
+ }
118
+ this.setTarget(link.replace(pattern, value));
119
+ }
120
+ /* NOT FOR BROWSER END */
121
+ /**
122
+ * @param url 网址
123
+ * @param type 类型
124
+ */
125
+ constructor(url, type = 'free-ext-link', config = index_1.default.getConfig(), accum) {
126
+ super(url, config, accum, {
127
+ 'Stage-1': '1:', '!ExtToken': '', AstText: ':', TranscludeToken: ':',
128
+ });
129
+ this.#type = type;
130
+ /* NOT FOR BROWSER */
131
+ let pattern;
132
+ if (type === 'magic-link') {
133
+ pattern = url?.startsWith('ISBN') ? isbnPattern : rfcPattern;
134
+ }
135
+ else {
136
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
137
+ /^(ftp:\/\/|\/\/)/iu;
138
+ pattern = new RegExp(`^(${config.protocol}${type === 'ext-link-url' ? '|//' : ''})`, 'iu');
139
+ }
140
+ this.setAttribute('pattern', pattern);
141
+ }
142
+ /** @private */
143
+ lint(start = this.getAbsoluteIndex(), re) {
144
+ const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start);
145
+ if (this.type === 'magic-link') {
146
+ const { link } = this;
147
+ if (link.startsWith('ISBN')) {
148
+ // eslint-disable-next-line unicorn/no-useless-spread
149
+ const digits = [...link.slice(5)].map(s => s === 'X' ? 10 : Number(s));
150
+ if (digits.length === 10 && digits.reduce((sum, d, i) => sum + d * (10 - i), 0) % 11
151
+ || digits.length === 13 && (digits[12] === 10
152
+ || digits.reduce((sum, d, i) => sum + d * (i % 2 ? 3 : 1), 0) % 10)) {
153
+ errors.push((0, lint_1.generateForSelf)(this, rect, 'invalid-isbn', 'invalid ISBN'));
154
+ }
155
+ }
156
+ return errors;
157
+ }
158
+ const pipe = this.type === 'ext-link-url', regex = pipe ? /\|/u : /[,;。:!?()]+/u, child = this.childNodes.find((c) => c.type === 'text' && regex.test(c.data));
159
+ if (child) {
160
+ const { data } = child, e = (0, lint_1.generateForChild)(child, rect, 'unterminated-url', index_1.default.msg('$1 in URL', pipe ? '"|"' : 'full-width punctuation'), 'warning'), { index, 0: s } = regex.exec(data), i = e.startIndex + index;
161
+ e.suggestions = pipe
162
+ ? [
163
+ {
164
+ desc: 'whitespace',
165
+ range: [i, i + 1],
166
+ text: ' ',
167
+ },
168
+ ]
169
+ : [
170
+ {
171
+ desc: 'whitespace',
172
+ range: [i, i],
173
+ text: ' ',
174
+ },
175
+ {
176
+ desc: 'escape',
177
+ range: [i, i + s.length],
178
+ text: encodeURI(s),
179
+ },
180
+ ];
181
+ errors.push(e);
182
+ }
183
+ return errors;
184
+ }
185
+ /* NOT FOR BROWSER */
186
+ cloneNode() {
187
+ const cloned = this.cloneChildNodes();
188
+ return debug_1.Shadow.run(() => {
189
+ // @ts-expect-error abstract class
190
+ const token = new MagicLinkToken(undefined, this.type, this.getAttribute('config'));
191
+ token.append(...cloned);
192
+ token.setAttribute('pattern', this.pattern);
193
+ return token;
194
+ });
195
+ }
196
+ insertAt(token, i) {
197
+ if (typeof token !== 'string') {
198
+ const { type, name } = token;
199
+ if (type === 'template') {
200
+ this.constructorError('cannot insert a template');
201
+ }
202
+ else if (!debug_1.Shadow.running && type === 'magic-word' && name !== '!' && name !== '=') {
203
+ this.constructorError('cannot insert magic words other than "{{!}}" or "{{=}}"');
204
+ }
205
+ }
206
+ return super.insertAt(token, i);
207
+ }
208
+ /** 获取网址 */
209
+ getUrl() {
210
+ const { type, protocol } = this;
211
+ let { link } = this;
212
+ if (type === 'magic-link') {
213
+ if (protocol === 'ISBN') {
214
+ return this.normalizeTitle(`Special:BookSources/${link.slice(5)}`).getUrl();
215
+ }
216
+ link = protocol === 'RFC'
217
+ ? `https://tools.ietf.org/html/rfc${link.slice(4)}`
218
+ : `https://pubmed.ncbi.nlm.nih.gov/${link.slice(5)}`;
219
+ }
220
+ else if (protocol === '//') {
221
+ link = `https:${link}`;
222
+ }
223
+ return new URL(link);
224
+ }
225
+ /**
226
+ * 设置外链目标
227
+ * @param url 含协议的网址
228
+ */
229
+ setTarget(url) {
230
+ const { childNodes } = index_1.default.parse(url, this.getAttribute('include'), 2, this.getAttribute('config'));
231
+ this.replaceChildren(...childNodes);
232
+ }
233
+ /** 是否是模板或魔术字参数 */
234
+ isParamValue() {
235
+ return this.closest('parameter')?.getValue() === this.text();
236
+ }
237
+ /** 转义 `=` */
238
+ escape() {
239
+ for (const child of this.childNodes) {
240
+ if (child.type === 'text') {
241
+ child.escape();
242
+ }
243
+ }
244
+ }
245
+ /** @private */
246
+ toHtmlInternal() {
247
+ const { type, innerText, protocol } = this;
248
+ let url;
249
+ try {
250
+ url = this.getUrl();
251
+ }
252
+ catch { }
253
+ return (0, html_1.font)(this, `<a${type === 'magic-link' && protocol === 'ISBN'
254
+ ? ''
255
+ : ` rel="nofollow" class="external${type === 'free-ext-link' ? ' free' : ''}"`}${url === undefined ? '' : ` href="${typeof url === 'string' ? url : url.href}"`}>${innerText}</a>`);
256
+ }
257
+ };
258
+ return MagicLinkToken = _classThis;
259
+ })();
260
+ exports.MagicLinkToken = MagicLinkToken;
261
+ constants_1.classes['MagicLinkToken'] = __filename;
@@ -0,0 +1,40 @@
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 name: string;
15
+ readonly childNodes: readonly (ExtToken | NoincludeToken | CommentToken)[];
16
+ abstract get firstChild(): ExtToken | NoincludeToken | CommentToken | undefined;
17
+ abstract get lastChild(): ExtToken | NoincludeToken | CommentToken | undefined;
18
+ abstract get nextSibling(): undefined;
19
+ abstract get previousSibling(): AttributesToken;
20
+ abstract get parentNode(): ExtToken | undefined;
21
+ abstract get children(): (ExtToken | NoincludeToken | CommentToken)[];
22
+ abstract get firstElementChild(): ExtToken | NoincludeToken | CommentToken | undefined;
23
+ abstract get lastElementChild(): ExtToken | NoincludeToken | CommentToken | undefined;
24
+ abstract get previousElementSibling(): AttributesToken;
25
+ abstract get nextElementSibling(): undefined;
26
+ abstract get parentElement(): ExtToken | undefined;
27
+ get type(): 'ext-inner';
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
+ cloneNode(): this;
40
+ }
@@ -0,0 +1,108 @@
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 index_1 = require("../index");
7
+ const index_2 = require("./index");
8
+ const ext_1 = require("./tagPair/ext");
9
+ const noinclude_1 = require("./nowiki/noinclude");
10
+ const comment_1 = require("./nowiki/comment");
11
+ /* NOT FOR BROWSER */
12
+ const debug_1 = require("../util/debug");
13
+ const constants_1 = require("../util/constants");
14
+ /* NOT FOR BROWSER END */
15
+ /**
16
+ * 嵌套式的扩展标签
17
+ * @classdesc `{childNodes: ...ExtToken|NoincludeToken|CommentToken}`
18
+ */
19
+ class NestedToken extends index_2.Token {
20
+ /* NOT FOR BROWSER */
21
+ #tags;
22
+ #regex;
23
+ /* NOT FOR BROWSER END */
24
+ get type() {
25
+ return 'ext-inner';
26
+ }
27
+ /**
28
+ * @param regex 内层正则
29
+ * @param tags 内层标签名
30
+ */
31
+ constructor(wikitext, regex, tags, config = index_1.default.getConfig(), accum = []) {
32
+ wikitext = wikitext?.replace(regex, (comment, name, attr, inner, closing) => {
33
+ const str = `\0${accum.length + 1}${name ? 'e' : 'c'}\x7F`;
34
+ if (name) {
35
+ // @ts-expect-error abstract class
36
+ new ext_1.ExtToken(name, attr, inner, closing, config, accum);
37
+ }
38
+ else {
39
+ const closed = comment.endsWith('-->');
40
+ // @ts-expect-error abstract class
41
+ new comment_1.CommentToken(comment.slice(4, closed ? -3 : undefined), closed, config, accum);
42
+ }
43
+ return str;
44
+ }).replace(/(^|\0\d+[cne]\x7F)([^\0]+)(?=$|\0\d+[cne]\x7F)/gu, (_, lead, substr) => {
45
+ // @ts-expect-error abstract class
46
+ new noinclude_1.NoincludeToken(substr, config, accum);
47
+ return `${lead}\0${accum.length}n\x7F`;
48
+ });
49
+ super(wikitext, config, accum, {
50
+ NoincludeToken: ':', ExtToken: ':',
51
+ });
52
+ /* NOT FOR BROWSER */
53
+ this.#tags = [...tags];
54
+ this.#regex = regex;
55
+ }
56
+ /** @private */
57
+ lint(start = this.getAbsoluteIndex(), re) {
58
+ const rect = new rect_1.BoundingRect(this, start);
59
+ return [
60
+ ...super.lint(start, re),
61
+ ...this.childNodes.filter(child => {
62
+ if (child.type === 'ext' || child.type === 'comment') {
63
+ return false;
64
+ }
65
+ const str = child.toString().trim();
66
+ return str && !/^<!--.*-->$/su.test(str);
67
+ }).map(child => {
68
+ const e = (0, lint_1.generateForChild)(child, rect, 'no-ignored', index_1.default.msg('invalid content in <$1>', this.name));
69
+ e.suggestions = [
70
+ {
71
+ desc: 'remove',
72
+ range: [e.startIndex, e.endIndex],
73
+ text: '',
74
+ },
75
+ {
76
+ desc: 'comment',
77
+ range: [e.startIndex, e.endIndex],
78
+ text: `<!--${child.toString()}-->`,
79
+ },
80
+ ];
81
+ return e;
82
+ }),
83
+ ];
84
+ }
85
+ /* NOT FOR BROWSER */
86
+ /**
87
+ * @override
88
+ * @param token 待插入的子节点
89
+ * @param i 插入位置
90
+ */
91
+ insertAt(token, i) {
92
+ if (typeof token !== 'string' && token.type === 'ext' && !this.#tags.includes(token.name)) {
93
+ this.constructorError(`can only have ${this.#tags.join(' or ')} tags as child nodes`);
94
+ }
95
+ return super.insertAt(token, i);
96
+ }
97
+ cloneNode() {
98
+ const cloned = this.cloneChildNodes(), config = this.getAttribute('config');
99
+ return debug_1.Shadow.run(() => {
100
+ // @ts-expect-error abstract class
101
+ const token = new NestedToken(undefined, this.#regex, this.#tags, config);
102
+ token.append(...cloned);
103
+ return token;
104
+ });
105
+ }
106
+ }
107
+ exports.NestedToken = NestedToken;
108
+ constants_1.classes['NestedToken'] = __filename;
@@ -0,0 +1,28 @@
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
+ abstract get 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
+ cloneNode(): this;
22
+ /**
23
+ * @override
24
+ * @param str 新文本
25
+ */
26
+ setText(str: string): string;
27
+ }
28
+ export {};
@@ -0,0 +1,90 @@
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 index_1 = require("../index");
39
+ /* NOT FOR BROWSER */
40
+ const debug_1 = require("../../util/debug");
41
+ const constants_1 = require("../../util/constants");
42
+ const fixed_1 = require("../../mixin/fixed");
43
+ /**
44
+ * 纯文字Token,不会被解析
45
+ * @classdesc `{childNodes: [AstText]}`
46
+ */
47
+ let NowikiBaseToken = (() => {
48
+ let _classDecorators = [fixed_1.fixedToken];
49
+ let _classDescriptor;
50
+ let _classExtraInitializers = [];
51
+ let _classThis;
52
+ let _classSuper = index_1.Token;
53
+ var NowikiBaseToken = class extends _classSuper {
54
+ static { _classThis = this; }
55
+ static {
56
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
57
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
58
+ NowikiBaseToken = _classThis = _classDescriptor.value;
59
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
60
+ __runInitializers(_classThis, _classExtraInitializers);
61
+ }
62
+ /* NOT FOR BROWSER END */
63
+ /** 纯文本部分 */
64
+ get innerText() {
65
+ return this.firstChild.data;
66
+ }
67
+ /** @param wikitext default: `''` */
68
+ constructor(wikitext = '', config, accum) {
69
+ super(wikitext, config, accum);
70
+ }
71
+ /* NOT FOR BROWSER */
72
+ cloneNode() {
73
+ const { firstChild: { data } } = this;
74
+ return debug_1.Shadow.run(() => {
75
+ const C = this.constructor, token = new C(data, this.getAttribute('config'));
76
+ return token;
77
+ });
78
+ }
79
+ /**
80
+ * @override
81
+ * @param str 新文本
82
+ */
83
+ setText(str) {
84
+ return super.setText(str);
85
+ }
86
+ };
87
+ return NowikiBaseToken = _classThis;
88
+ })();
89
+ exports.NowikiBaseToken = NowikiBaseToken;
90
+ constants_1.classes['NowikiBaseToken'] = __filename;
@@ -0,0 +1,14 @@
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
+ closed: boolean;
7
+ get type(): 'comment';
8
+ /** 内部文本 */
9
+ get innerText(): string;
10
+ set innerText(text: string);
11
+ /** @param closed 是否闭合 */
12
+ constructor(wikitext: string, closed?: boolean, config?: Config, accum?: Token[]);
13
+ cloneNode(): this;
14
+ }