wikiparser-node 1.11.1 → 1.12.0-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 (175) hide show
  1. package/bundle/bundle.min.js +37 -0
  2. package/config/default.json +28 -28
  3. package/config/enwiki.json +14 -827
  4. package/config/llwiki.json +20 -54
  5. package/config/minimum.json +1 -1
  6. package/config/moegirl.json +20 -63
  7. package/config/zhwiki.json +27 -492
  8. package/extensions/dist/base.js +162 -0
  9. package/extensions/dist/codejar.js +52 -0
  10. package/extensions/dist/editor.js +159 -0
  11. package/extensions/dist/highlight.js +30 -0
  12. package/extensions/dist/lint.js +72 -0
  13. package/extensions/editor.css +59 -0
  14. package/extensions/ui.css +159 -0
  15. package/package.json +29 -21
  16. package/config/.schema.json +0 -186
  17. package/dist/addon/table.js +0 -486
  18. package/dist/addon/token.js +0 -304
  19. package/dist/addon/transclude.js +0 -184
  20. package/dist/base.d.ts +0 -81
  21. package/dist/base.js +0 -39
  22. package/dist/index.d.ts +0 -33
  23. package/dist/index.js +0 -235
  24. package/dist/internal.d.ts +0 -46
  25. package/dist/lib/element.d.ts +0 -125
  26. package/dist/lib/element.js +0 -375
  27. package/dist/lib/node.d.ts +0 -173
  28. package/dist/lib/node.js +0 -477
  29. package/dist/lib/range.d.ts +0 -105
  30. package/dist/lib/range.js +0 -406
  31. package/dist/lib/ranges.d.ts +0 -28
  32. package/dist/lib/ranges.js +0 -126
  33. package/dist/lib/rect.d.ts +0 -18
  34. package/dist/lib/rect.js +0 -34
  35. package/dist/lib/text.d.ts +0 -58
  36. package/dist/lib/text.js +0 -400
  37. package/dist/lib/title.d.ts +0 -42
  38. package/dist/lib/title.js +0 -208
  39. package/dist/mixin/attributesParent.d.ts +0 -49
  40. package/dist/mixin/attributesParent.js +0 -79
  41. package/dist/mixin/fixed.d.ts +0 -5
  42. package/dist/mixin/fixed.js +0 -32
  43. package/dist/mixin/flagsParent.d.ts +0 -43
  44. package/dist/mixin/flagsParent.js +0 -64
  45. package/dist/mixin/hidden.d.ts +0 -7
  46. package/dist/mixin/hidden.js +0 -37
  47. package/dist/mixin/magicLinkParent.d.ts +0 -19
  48. package/dist/mixin/magicLinkParent.js +0 -43
  49. package/dist/mixin/singleLine.d.ts +0 -5
  50. package/dist/mixin/singleLine.js +0 -25
  51. package/dist/mixin/sol.d.ts +0 -6
  52. package/dist/mixin/sol.js +0 -45
  53. package/dist/mixin/syntax.d.ts +0 -8
  54. package/dist/mixin/syntax.js +0 -46
  55. package/dist/parser/braces.js +0 -150
  56. package/dist/parser/commentAndExt.js +0 -79
  57. package/dist/parser/converter.js +0 -39
  58. package/dist/parser/externalLinks.js +0 -37
  59. package/dist/parser/hrAndDoubleUnderscore.js +0 -42
  60. package/dist/parser/html.js +0 -38
  61. package/dist/parser/links.js +0 -101
  62. package/dist/parser/list.js +0 -114
  63. package/dist/parser/magicLinks.js +0 -52
  64. package/dist/parser/quotes.js +0 -67
  65. package/dist/parser/redirect.js +0 -26
  66. package/dist/parser/selector.js +0 -394
  67. package/dist/parser/table.js +0 -123
  68. package/dist/src/arg.d.ts +0 -51
  69. package/dist/src/arg.js +0 -214
  70. package/dist/src/atom.d.ts +0 -14
  71. package/dist/src/atom.js +0 -52
  72. package/dist/src/attribute.d.ts +0 -64
  73. package/dist/src/attribute.js +0 -480
  74. package/dist/src/attributes.d.ts +0 -101
  75. package/dist/src/attributes.js +0 -381
  76. package/dist/src/converter.d.ts +0 -28
  77. package/dist/src/converter.js +0 -148
  78. package/dist/src/converterFlags.d.ts +0 -80
  79. package/dist/src/converterFlags.js +0 -239
  80. package/dist/src/converterRule.d.ts +0 -71
  81. package/dist/src/converterRule.js +0 -216
  82. package/dist/src/extLink.d.ts +0 -36
  83. package/dist/src/extLink.js +0 -218
  84. package/dist/src/gallery.d.ts +0 -47
  85. package/dist/src/gallery.js +0 -143
  86. package/dist/src/heading.d.ts +0 -40
  87. package/dist/src/heading.js +0 -192
  88. package/dist/src/hidden.d.ts +0 -9
  89. package/dist/src/hidden.js +0 -80
  90. package/dist/src/html.d.ts +0 -61
  91. package/dist/src/html.js +0 -343
  92. package/dist/src/imageParameter.d.ts +0 -60
  93. package/dist/src/imageParameter.js +0 -260
  94. package/dist/src/imagemap.d.ts +0 -47
  95. package/dist/src/imagemap.js +0 -146
  96. package/dist/src/imagemapLink.d.ts +0 -31
  97. package/dist/src/imagemapLink.js +0 -97
  98. package/dist/src/index.d.ts +0 -136
  99. package/dist/src/index.js +0 -834
  100. package/dist/src/link/base.d.ts +0 -52
  101. package/dist/src/link/base.js +0 -256
  102. package/dist/src/link/category.d.ts +0 -22
  103. package/dist/src/link/category.js +0 -34
  104. package/dist/src/link/file.d.ts +0 -102
  105. package/dist/src/link/file.js +0 -333
  106. package/dist/src/link/galleryImage.d.ts +0 -29
  107. package/dist/src/link/galleryImage.js +0 -132
  108. package/dist/src/link/index.d.ts +0 -39
  109. package/dist/src/link/index.js +0 -98
  110. package/dist/src/link/redirectTarget.d.ts +0 -27
  111. package/dist/src/link/redirectTarget.js +0 -69
  112. package/dist/src/magicLink.d.ts +0 -58
  113. package/dist/src/magicLink.js +0 -256
  114. package/dist/src/nested.d.ts +0 -40
  115. package/dist/src/nested.js +0 -106
  116. package/dist/src/nowiki/base.d.ts +0 -28
  117. package/dist/src/nowiki/base.js +0 -89
  118. package/dist/src/nowiki/comment.d.ts +0 -14
  119. package/dist/src/nowiki/comment.js +0 -121
  120. package/dist/src/nowiki/dd.d.ts +0 -8
  121. package/dist/src/nowiki/dd.js +0 -72
  122. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -15
  123. package/dist/src/nowiki/doubleUnderscore.js +0 -97
  124. package/dist/src/nowiki/hr.d.ts +0 -5
  125. package/dist/src/nowiki/hr.js +0 -70
  126. package/dist/src/nowiki/index.d.ts +0 -14
  127. package/dist/src/nowiki/index.js +0 -28
  128. package/dist/src/nowiki/list.d.ts +0 -5
  129. package/dist/src/nowiki/list.js +0 -65
  130. package/dist/src/nowiki/listBase.d.ts +0 -23
  131. package/dist/src/nowiki/listBase.js +0 -99
  132. package/dist/src/nowiki/noinclude.d.ts +0 -6
  133. package/dist/src/nowiki/noinclude.js +0 -75
  134. package/dist/src/nowiki/quote.d.ts +0 -14
  135. package/dist/src/nowiki/quote.js +0 -140
  136. package/dist/src/onlyinclude.d.ts +0 -13
  137. package/dist/src/onlyinclude.js +0 -58
  138. package/dist/src/paramTag/index.d.ts +0 -28
  139. package/dist/src/paramTag/index.js +0 -78
  140. package/dist/src/paramTag/inputbox.d.ts +0 -8
  141. package/dist/src/paramTag/inputbox.js +0 -22
  142. package/dist/src/parameter.d.ts +0 -60
  143. package/dist/src/parameter.js +0 -264
  144. package/dist/src/pre.d.ts +0 -28
  145. package/dist/src/pre.js +0 -60
  146. package/dist/src/redirect.d.ts +0 -30
  147. package/dist/src/redirect.js +0 -126
  148. package/dist/src/syntax.d.ts +0 -17
  149. package/dist/src/syntax.js +0 -87
  150. package/dist/src/table/base.d.ts +0 -28
  151. package/dist/src/table/base.js +0 -81
  152. package/dist/src/table/index.d.ts +0 -230
  153. package/dist/src/table/index.js +0 -506
  154. package/dist/src/table/td.d.ts +0 -72
  155. package/dist/src/table/td.js +0 -370
  156. package/dist/src/table/tr.d.ts +0 -30
  157. package/dist/src/table/tr.js +0 -59
  158. package/dist/src/table/trBase.d.ts +0 -49
  159. package/dist/src/table/trBase.js +0 -164
  160. package/dist/src/tagPair/ext.d.ts +0 -29
  161. package/dist/src/tagPair/ext.js +0 -220
  162. package/dist/src/tagPair/include.d.ts +0 -33
  163. package/dist/src/tagPair/include.js +0 -130
  164. package/dist/src/tagPair/index.d.ts +0 -23
  165. package/dist/src/tagPair/index.js +0 -128
  166. package/dist/src/transclude.d.ts +0 -159
  167. package/dist/src/transclude.js +0 -587
  168. package/dist/util/constants.js +0 -25
  169. package/dist/util/debug.js +0 -95
  170. package/dist/util/diff.js +0 -83
  171. package/dist/util/html.js +0 -143
  172. package/dist/util/lint.js +0 -32
  173. package/dist/util/string.js +0 -87
  174. package/errors/README +0 -3
  175. package/printed/README +0 -3
@@ -1,69 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RedirectTargetToken = void 0;
4
- const lint_1 = require("../../util/lint");
5
- const constants_1 = require("../../util/constants");
6
- const index_1 = require("../../index");
7
- const base_1 = require("./base");
8
- const noinclude_1 = require("../nowiki/noinclude");
9
- /**
10
- * 重定向目标
11
- * @classdesc `{childNodes: [AtomToken, ?NoincludeToken]}`
12
- */
13
- class RedirectTargetToken extends base_1.LinkBaseToken {
14
- /* NOT FOR BROWSER END */
15
- get type() {
16
- return 'redirect-target';
17
- }
18
- /* NOT FOR BROWSER */
19
- /** 链接显示文字 */
20
- get innerText() {
21
- return String(this.link);
22
- }
23
- /* NOT FOR BROWSER END */
24
- /**
25
- * @param link 链接标题
26
- * @param linkText 链接显示文字
27
- * @param delimiter `|`
28
- */
29
- constructor(link, linkText, config = index_1.default.getConfig(), accum = []) {
30
- super(link, undefined, config, accum);
31
- if (linkText !== undefined) {
32
- // @ts-expect-error abstract class
33
- this.insertAt(new noinclude_1.NoincludeToken(linkText, config, accum));
34
- }
35
- /* NOT FOR BROWSER */
36
- this.setAttribute('acceptable', { AtomToken: 0, NoincludeToken: 1 });
37
- // @ts-expect-error abstract getter
38
- this.firstChild.setAttribute('acceptable', { AstText: ':' });
39
- }
40
- /** @private */
41
- getTitle() {
42
- return this.normalizeTitle(this.firstChild.toString(), 0, true, true);
43
- }
44
- /** @private */
45
- lint(start = this.getAbsoluteIndex()) {
46
- const errors = super.lint(start, false);
47
- if (this.length === 2) {
48
- const e = (0, lint_1.generateForChild)(this.lastChild, { start }, 'no-ignored', 'useless link text');
49
- e.startIndex--;
50
- e.startCol--;
51
- e.fix = { range: [e.startIndex, e.endIndex], text: '' };
52
- errors.push(e);
53
- }
54
- return errors;
55
- }
56
- /* NOT FOR BROWSER */
57
- /** @private */
58
- setTarget(link) {
59
- this.firstChild.setText(link);
60
- }
61
- /** @private */
62
- setLinkText(linkStr) {
63
- if (!linkStr) {
64
- this.childNodes[1]?.remove();
65
- }
66
- }
67
- }
68
- exports.RedirectTargetToken = RedirectTargetToken;
69
- constants_1.classes['RedirectTargetToken'] = __filename;
@@ -1,58 +0,0 @@
1
- import Parser from '../index';
2
- import { Token } from './index';
3
- import type { LintError } from '../base';
4
- import type { SyntaxBase } from '../mixin/syntax';
5
- import type { AstText, CommentToken, IncludeToken, NoincludeToken, TranscludeToken, AstNodes } from '../internal';
6
- declare type ExtLinkTypes = 'free-ext-link' | 'ext-link-url' | 'magic-link';
7
- /** NOT FOR BROWSER */
8
- export interface MagicLinkToken extends SyntaxBase {
9
- }
10
- /** NOT FOR BROWSER END */
11
- /**
12
- * 自由外链
13
- * @classdesc `{childNodes: ...AstText|CommentToken|IncludeToken|NoincludeToken}`
14
- */
15
- export declare abstract class MagicLinkToken extends Token {
16
- #private;
17
- readonly childNodes: readonly (AstText | CommentToken | IncludeToken | NoincludeToken | TranscludeToken)[];
18
- abstract get firstChild(): AstText | TranscludeToken;
19
- abstract get lastChild(): AstText | CommentToken | IncludeToken | NoincludeToken | TranscludeToken;
20
- abstract get children(): (CommentToken | IncludeToken | NoincludeToken | TranscludeToken)[];
21
- abstract get firstElementChild(): CommentToken | IncludeToken | NoincludeToken | TranscludeToken | undefined;
22
- abstract get lastElementChild(): CommentToken | IncludeToken | NoincludeToken | TranscludeToken | undefined;
23
- get type(): ExtLinkTypes;
24
- /** 链接显示文字 */
25
- get innerText(): string;
26
- /** 和内链保持一致 */
27
- get link(): string;
28
- set link(url: string);
29
- /** 协议 */
30
- get protocol(): string | undefined;
31
- /** @throws `Error` 特殊外链无法更改协议n */
32
- set protocol(value: string);
33
- /**
34
- * @param url 网址
35
- * @param type 类型
36
- */
37
- constructor(url?: string, type?: ExtLinkTypes, config?: Parser.Config, accum?: Token[]);
38
- cloneNode(): this;
39
- /**
40
- * @override
41
- * @param token 待插入的节点
42
- * @param i 插入位置
43
- */
44
- insertAt(token: string, i?: number): AstText;
45
- insertAt<T extends AstNodes>(token: T, i?: number): T;
46
- /** 获取网址 */
47
- getUrl(): URL | string;
48
- /**
49
- * 设置外链目标
50
- * @param url 含协议的网址
51
- */
52
- setTarget(url: string): void;
53
- /** 是否是模板或魔术字参数 */
54
- isParamValue(): boolean;
55
- /** 转义 `=` */
56
- escape(): void;
57
- }
58
- export {};
@@ -1,256 +0,0 @@
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
- #type;
75
- /* NOT FOR BROWSER END */
76
- get type() {
77
- return this.#type;
78
- }
79
- /** 链接显示文字 */
80
- get innerText() {
81
- const map = new Map([['!', '|'], ['=', '=']]);
82
- let link = (0, string_1.text)(this.childNodes.map(child => {
83
- const { type } = child, name = String(child.name);
84
- return type === 'magic-word' && map.has(name) ? map.get(name) : child;
85
- }));
86
- if (this.type === 'magic-link') {
87
- link = link.replace(spaceRegex, ' ');
88
- }
89
- return link;
90
- }
91
- /** 和内链保持一致 */
92
- get link() {
93
- let { innerText } = this;
94
- if (this.type === 'magic-link' && innerText.startsWith('ISBN')) {
95
- innerText = `ISBN ${innerText.slice(5).replace(/[- ]/gu, '').replace(/x$/u, 'X')}`;
96
- }
97
- return innerText;
98
- }
99
- /* NOT FOR BROWSER */
100
- set link(url) {
101
- this.setTarget(url);
102
- }
103
- /** 协议 */
104
- get protocol() {
105
- return this.pattern.exec(this.text())?.[1];
106
- }
107
- /** @throws `Error` 特殊外链无法更改协议n */
108
- set protocol(value) {
109
- const { link, pattern, type } = this;
110
- if (type === 'magic-link' || !pattern.test(link)) {
111
- throw new Error(`Special external link cannot change protocol: ${link}`);
112
- }
113
- this.setTarget(link.replace(pattern, value));
114
- }
115
- /* NOT FOR BROWSER END */
116
- /**
117
- * @param url 网址
118
- * @param type 类型
119
- */
120
- constructor(url, type = 'free-ext-link', config = index_1.default.getConfig(), accum) {
121
- super(url, config, accum, {
122
- 'Stage-1': '1:', '!ExtToken': '', AstText: ':', TranscludeToken: ':',
123
- });
124
- this.#type = type;
125
- /* NOT FOR BROWSER */
126
- let pattern;
127
- if (type === 'magic-link') {
128
- pattern = url?.startsWith('ISBN') ? isbnPattern : rfcPattern;
129
- }
130
- else {
131
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
132
- /^(ftp:\/\/|\/\/)/iu;
133
- pattern = new RegExp(`^(${config.protocol}${type === 'ext-link-url' ? '|//' : ''})`, 'iu');
134
- }
135
- this.setAttribute('pattern', pattern);
136
- }
137
- /** @private */
138
- lint(start = this.getAbsoluteIndex(), re) {
139
- const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start);
140
- if (this.type === 'magic-link') {
141
- const { link } = this;
142
- if (link.startsWith('ISBN')) {
143
- // eslint-disable-next-line unicorn/no-useless-spread
144
- const digits = [...link.slice(5)].map(s => s === 'X' ? 10 : Number(s));
145
- if (digits.length === 10 && digits.reduce((sum, d, i) => sum + d * (10 - i), 0) % 11
146
- || digits.length === 13 && (digits[12] === 10
147
- || digits.reduce((sum, d, i) => sum + d * (i % 2 ? 3 : 1), 0) % 10)) {
148
- errors.push((0, lint_1.generateForSelf)(this, rect, 'invalid-isbn', 'invalid ISBN'));
149
- }
150
- }
151
- return errors;
152
- }
153
- const pipe = this.type === 'ext-link-url', regex = pipe ? /\|/u : /[,;。:!?()]+/u, child = this.childNodes.find((c) => c.type === 'text' && regex.test(c.data));
154
- if (child) {
155
- 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;
156
- e.suggestions = pipe
157
- ? [
158
- {
159
- desc: 'whitespace',
160
- range: [i, i + 1],
161
- text: ' ',
162
- },
163
- ]
164
- : [
165
- {
166
- desc: 'whitespace',
167
- range: [i, i],
168
- text: ' ',
169
- },
170
- {
171
- desc: 'escape',
172
- range: [i, i + s.length],
173
- text: encodeURI(s),
174
- },
175
- ];
176
- errors.push(e);
177
- }
178
- return errors;
179
- }
180
- /* NOT FOR BROWSER */
181
- cloneNode() {
182
- const cloned = this.cloneChildNodes();
183
- return debug_1.Shadow.run(() => {
184
- // @ts-expect-error abstract class
185
- const token = new MagicLinkToken(undefined, this.type, this.getAttribute('config'));
186
- token.append(...cloned);
187
- token.setAttribute('pattern', this.pattern);
188
- return token;
189
- });
190
- }
191
- insertAt(token, i) {
192
- if (typeof token !== 'string') {
193
- const { type, name } = token;
194
- if (type === 'template') {
195
- this.constructorError('cannot insert a template');
196
- }
197
- else if (!debug_1.Shadow.running && type === 'magic-word' && name !== '!' && name !== '=') {
198
- this.constructorError('cannot insert magic words other than "{{!}}" or "{{=}}"');
199
- }
200
- }
201
- return super.insertAt(token, i);
202
- }
203
- /** 获取网址 */
204
- getUrl() {
205
- const { type, protocol } = this;
206
- let { link } = this;
207
- if (type === 'magic-link') {
208
- if (protocol === 'ISBN') {
209
- return this.normalizeTitle(`Special:BookSources/${link.slice(5)}`).getUrl();
210
- }
211
- link = protocol === 'RFC'
212
- ? `https://tools.ietf.org/html/rfc${link.slice(4)}`
213
- : `https://pubmed.ncbi.nlm.nih.gov/${link.slice(5)}`;
214
- }
215
- else if (protocol === '//') {
216
- link = `https:${link}`;
217
- }
218
- return new URL(link);
219
- }
220
- /**
221
- * 设置外链目标
222
- * @param url 含协议的网址
223
- */
224
- setTarget(url) {
225
- const { childNodes } = index_1.default.parse(url, this.getAttribute('include'), 2, this.getAttribute('config'));
226
- this.replaceChildren(...childNodes);
227
- }
228
- /** 是否是模板或魔术字参数 */
229
- isParamValue() {
230
- return this.closest('parameter')?.getValue() === this.text();
231
- }
232
- /** 转义 `=` */
233
- escape() {
234
- for (const child of this.childNodes) {
235
- if (child.type === 'text') {
236
- child.escape();
237
- }
238
- }
239
- }
240
- /** @private */
241
- toHtmlInternal() {
242
- const { type, innerText, protocol } = this;
243
- let url;
244
- try {
245
- url = this.getUrl();
246
- }
247
- catch { }
248
- return `<a${type === 'magic-link' && protocol === 'ISBN'
249
- ? ''
250
- : ` rel="nofollow" class="external${type === 'free-ext-link' ? ' free' : ''}"`}${url === undefined ? '' : ` href="${typeof url === 'string' ? url : url.href}"`}>${innerText}</a>`;
251
- }
252
- };
253
- return MagicLinkToken = _classThis;
254
- })();
255
- exports.MagicLinkToken = MagicLinkToken;
256
- constants_1.classes['MagicLinkToken'] = __filename;
@@ -1,40 +0,0 @@
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
- }
@@ -1,106 +0,0 @@
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
- /* NOT FOR BROWSER */
19
- #tags;
20
- #regex;
21
- /* NOT FOR BROWSER END */
22
- get type() {
23
- return 'ext-inner';
24
- }
25
- /**
26
- * @param regex 内层正则
27
- * @param tags 内层标签名
28
- */
29
- constructor(wikitext, regex, tags, config = index_1.default.getConfig(), accum = []) {
30
- wikitext = wikitext?.replace(regex, (comment, name, attr, inner, closing) => {
31
- const str = `\0${accum.length + 1}${name ? 'e' : 'c'}\x7F`;
32
- if (name) {
33
- // @ts-expect-error abstract class
34
- new ext_1.ExtToken(name, attr, inner, closing, config, accum);
35
- }
36
- else {
37
- const closed = comment.endsWith('-->');
38
- // @ts-expect-error abstract class
39
- new comment_1.CommentToken(comment.slice(4, closed ? -3 : undefined), closed, config, accum);
40
- }
41
- return str;
42
- }).replace(/(^|\0\d+[ce]\x7F)([^\0]+)(?=$|\0\d+[ce]\x7F)/gu, (_, lead, substr) => {
43
- // @ts-expect-error abstract class
44
- new noinclude_1.NoincludeToken(substr, config, accum);
45
- return `${lead}\0${accum.length}c\x7F`;
46
- });
47
- super(wikitext, config, accum, {
48
- NoincludeToken: ':', ExtToken: ':',
49
- });
50
- /* NOT FOR BROWSER */
51
- this.#tags = [...tags];
52
- this.#regex = regex;
53
- }
54
- /** @private */
55
- lint(start = this.getAbsoluteIndex(), re) {
56
- const rect = new rect_1.BoundingRect(this, start);
57
- return [
58
- ...super.lint(start, re),
59
- ...this.childNodes.filter(child => {
60
- if (child.type === 'ext' || child.type === 'comment') {
61
- return false;
62
- }
63
- const str = child.toString().trim();
64
- return str && !/^<!--.*-->$/su.test(str);
65
- }).map(child => {
66
- const e = (0, lint_1.generateForChild)(child, rect, 'no-ignored', index_1.default.msg('invalid content in <$1>', this.name));
67
- e.suggestions = [
68
- {
69
- desc: 'remove',
70
- range: [e.startIndex, e.endIndex],
71
- text: '',
72
- },
73
- {
74
- desc: 'comment',
75
- range: [e.startIndex, e.endIndex],
76
- text: `<!--${child.toString()}-->`,
77
- },
78
- ];
79
- return e;
80
- }),
81
- ];
82
- }
83
- /* NOT FOR BROWSER */
84
- /**
85
- * @override
86
- * @param token 待插入的子节点
87
- * @param i 插入位置
88
- */
89
- insertAt(token, i) {
90
- if (typeof token !== 'string' && token.type === 'ext' && !this.#tags.includes(token.name)) {
91
- this.constructorError(`can only have ${this.#tags.join(' or ')} tags as child nodes`);
92
- }
93
- return super.insertAt(token, i);
94
- }
95
- cloneNode() {
96
- const cloned = this.cloneChildNodes(), config = this.getAttribute('config');
97
- return debug_1.Shadow.run(() => {
98
- // @ts-expect-error abstract class
99
- const token = new NestedToken(undefined, this.#regex, this.#tags, config);
100
- token.append(...cloned);
101
- return token;
102
- });
103
- }
104
- }
105
- exports.NestedToken = NestedToken;
106
- constants_1.classes['NestedToken'] = __filename;
@@ -1,28 +0,0 @@
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 {};
@@ -1,89 +0,0 @@
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
- cloneNode() {
72
- const { firstChild: { data } } = this;
73
- return debug_1.Shadow.run(() => {
74
- const C = this.constructor, token = new C(data, this.getAttribute('config'));
75
- return token;
76
- });
77
- }
78
- /**
79
- * @override
80
- * @param str 新文本
81
- */
82
- setText(str) {
83
- return super.setText(str);
84
- }
85
- };
86
- return NowikiBaseToken = _classThis;
87
- })();
88
- exports.NowikiBaseToken = NowikiBaseToken;
89
- constants_1.classes['NowikiBaseToken'] = __filename;
@@ -1,14 +0,0 @@
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
- }