wikiparser-node 1.3.1 → 1.3.2-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 (156) hide show
  1. package/bundle/bundle.min.js +36 -0
  2. package/config/llwiki.json +1 -35
  3. package/config/moegirl.json +1 -44
  4. package/config/zhwiki.json +1 -466
  5. package/extensions/dist/base.js +68 -0
  6. package/extensions/dist/editor.js +159 -0
  7. package/extensions/dist/highlight.js +30 -0
  8. package/extensions/dist/lint.js +48 -0
  9. package/extensions/editor.css +63 -0
  10. package/extensions/ui.css +117 -0
  11. package/i18n/zh-hans.json +4 -3
  12. package/i18n/zh-hant.json +4 -3
  13. package/package.json +32 -12
  14. package/config/.schema.json +0 -172
  15. package/dist/addon/table.d.ts +0 -6
  16. package/dist/addon/table.js +0 -564
  17. package/dist/base.d.ts +0 -45
  18. package/dist/bin/toc.js +0 -18
  19. package/dist/index.d.ts +0 -31
  20. package/dist/index.js +0 -209
  21. package/dist/internal.d.ts +0 -44
  22. package/dist/lib/element.d.ts +0 -155
  23. package/dist/lib/element.js +0 -654
  24. package/dist/lib/node.d.ts +0 -146
  25. package/dist/lib/node.js +0 -419
  26. package/dist/lib/range.d.ts +0 -104
  27. package/dist/lib/range.js +0 -385
  28. package/dist/lib/ranges.d.ts +0 -26
  29. package/dist/lib/ranges.js +0 -117
  30. package/dist/lib/text.d.ts +0 -62
  31. package/dist/lib/text.js +0 -235
  32. package/dist/lib/title.d.ts +0 -38
  33. package/dist/lib/title.js +0 -162
  34. package/dist/mixin/attributesParent.js +0 -94
  35. package/dist/mixin/fixed.js +0 -32
  36. package/dist/mixin/flagsParent.js +0 -70
  37. package/dist/mixin/hidden.js +0 -22
  38. package/dist/mixin/magicLinkParent.js +0 -41
  39. package/dist/mixin/singleLine.js +0 -25
  40. package/dist/mixin/sol.js +0 -43
  41. package/dist/mixin/syntax.js +0 -56
  42. package/dist/parser/braces.js +0 -122
  43. package/dist/parser/commentAndExt.js +0 -69
  44. package/dist/parser/converter.js +0 -40
  45. package/dist/parser/externalLinks.js +0 -28
  46. package/dist/parser/hrAndDoubleUnderscore.js +0 -38
  47. package/dist/parser/html.js +0 -36
  48. package/dist/parser/links.js +0 -94
  49. package/dist/parser/list.js +0 -59
  50. package/dist/parser/magicLinks.js +0 -40
  51. package/dist/parser/quotes.js +0 -67
  52. package/dist/parser/selector.js +0 -162
  53. package/dist/parser/table.js +0 -112
  54. package/dist/src/arg.d.ts +0 -58
  55. package/dist/src/arg.js +0 -189
  56. package/dist/src/atom.d.ts +0 -12
  57. package/dist/src/atom.js +0 -27
  58. package/dist/src/attribute.d.ts +0 -86
  59. package/dist/src/attribute.js +0 -391
  60. package/dist/src/attributes.d.ts +0 -107
  61. package/dist/src/attributes.js +0 -341
  62. package/dist/src/converter.d.ts +0 -51
  63. package/dist/src/converter.js +0 -79
  64. package/dist/src/converterFlags.d.ts +0 -87
  65. package/dist/src/converterFlags.js +0 -222
  66. package/dist/src/converterRule.d.ts +0 -81
  67. package/dist/src/converterRule.js +0 -212
  68. package/dist/src/extLink.d.ts +0 -53
  69. package/dist/src/extLink.js +0 -121
  70. package/dist/src/gallery.d.ts +0 -55
  71. package/dist/src/gallery.js +0 -122
  72. package/dist/src/heading.d.ts +0 -72
  73. package/dist/src/heading.js +0 -127
  74. package/dist/src/hidden.d.ts +0 -21
  75. package/dist/src/hidden.js +0 -23
  76. package/dist/src/html.d.ts +0 -103
  77. package/dist/src/html.js +0 -222
  78. package/dist/src/imageParameter.d.ts +0 -66
  79. package/dist/src/imageParameter.js +0 -247
  80. package/dist/src/imagemap.d.ts +0 -57
  81. package/dist/src/imagemap.js +0 -148
  82. package/dist/src/imagemapLink.d.ts +0 -57
  83. package/dist/src/imagemapLink.js +0 -40
  84. package/dist/src/index.d.ts +0 -146
  85. package/dist/src/index.js +0 -777
  86. package/dist/src/link/base.d.ts +0 -52
  87. package/dist/src/link/base.js +0 -207
  88. package/dist/src/link/category.d.ts +0 -13
  89. package/dist/src/link/category.js +0 -29
  90. package/dist/src/link/file.d.ts +0 -96
  91. package/dist/src/link/file.js +0 -253
  92. package/dist/src/link/galleryImage.d.ts +0 -43
  93. package/dist/src/link/galleryImage.js +0 -106
  94. package/dist/src/link/index.d.ts +0 -53
  95. package/dist/src/link/index.js +0 -123
  96. package/dist/src/magicLink.d.ts +0 -69
  97. package/dist/src/magicLink.js +0 -147
  98. package/dist/src/nested.d.ts +0 -44
  99. package/dist/src/nested.js +0 -87
  100. package/dist/src/nowiki/base.d.ts +0 -46
  101. package/dist/src/nowiki/base.js +0 -42
  102. package/dist/src/nowiki/comment.d.ts +0 -39
  103. package/dist/src/nowiki/comment.js +0 -67
  104. package/dist/src/nowiki/dd.d.ts +0 -8
  105. package/dist/src/nowiki/dd.js +0 -25
  106. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -43
  107. package/dist/src/nowiki/doubleUnderscore.js +0 -50
  108. package/dist/src/nowiki/hr.d.ts +0 -29
  109. package/dist/src/nowiki/hr.js +0 -14
  110. package/dist/src/nowiki/index.d.ts +0 -16
  111. package/dist/src/nowiki/index.js +0 -21
  112. package/dist/src/nowiki/list.d.ts +0 -29
  113. package/dist/src/nowiki/list.js +0 -48
  114. package/dist/src/nowiki/listBase.d.ts +0 -18
  115. package/dist/src/nowiki/listBase.js +0 -12
  116. package/dist/src/nowiki/noinclude.d.ts +0 -25
  117. package/dist/src/nowiki/noinclude.js +0 -25
  118. package/dist/src/nowiki/quote.d.ts +0 -22
  119. package/dist/src/nowiki/quote.js +0 -45
  120. package/dist/src/onlyinclude.d.ts +0 -16
  121. package/dist/src/onlyinclude.js +0 -57
  122. package/dist/src/paramTag/index.d.ts +0 -37
  123. package/dist/src/paramTag/index.js +0 -68
  124. package/dist/src/paramTag/inputbox.d.ts +0 -8
  125. package/dist/src/paramTag/inputbox.js +0 -23
  126. package/dist/src/parameter.d.ts +0 -84
  127. package/dist/src/parameter.js +0 -205
  128. package/dist/src/pre.d.ts +0 -28
  129. package/dist/src/pre.js +0 -51
  130. package/dist/src/syntax.d.ts +0 -24
  131. package/dist/src/syntax.js +0 -30
  132. package/dist/src/table/base.d.ts +0 -52
  133. package/dist/src/table/base.js +0 -78
  134. package/dist/src/table/index.d.ts +0 -229
  135. package/dist/src/table/index.js +0 -379
  136. package/dist/src/table/td.d.ts +0 -103
  137. package/dist/src/table/td.js +0 -261
  138. package/dist/src/table/tr.d.ts +0 -32
  139. package/dist/src/table/tr.js +0 -56
  140. package/dist/src/table/trBase.d.ts +0 -54
  141. package/dist/src/table/trBase.js +0 -158
  142. package/dist/src/tagPair/ext.d.ts +0 -58
  143. package/dist/src/tagPair/ext.js +0 -142
  144. package/dist/src/tagPair/include.d.ts +0 -52
  145. package/dist/src/tagPair/include.js +0 -58
  146. package/dist/src/tagPair/index.d.ts +0 -47
  147. package/dist/src/tagPair/index.js +0 -93
  148. package/dist/src/transclude.d.ts +0 -167
  149. package/dist/src/transclude.js +0 -689
  150. package/dist/util/constants.js +0 -108
  151. package/dist/util/debug.js +0 -64
  152. package/dist/util/diff.js +0 -72
  153. package/dist/util/lint.js +0 -46
  154. package/dist/util/string.js +0 -61
  155. package/errors/README +0 -1
  156. package/printed/README +0 -1
@@ -1,106 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GalleryImageToken = void 0;
4
- const lint_1 = require("../../util/lint");
5
- const debug_1 = require("../../util/debug");
6
- const constants_1 = require("../../util/constants");
7
- const singleLine_1 = require("../../mixin/singleLine");
8
- const Parser = require("../../index");
9
- const index_1 = require("../index");
10
- const file_1 = require("./file");
11
- const imageParameter_1 = require("../imageParameter");
12
- /** 图库图片 */
13
- // @ts-expect-error not implementing all abstract methods
14
- class GalleryImageToken extends (0, singleLine_1.singleLine)(file_1.FileToken) {
15
- /* NOT FOR BROWSER */
16
- /** 图片链接 */
17
- get link() {
18
- return this.type === 'imagemap-image' ? '' : super.link;
19
- }
20
- set link(value) {
21
- if (this.type !== 'imagemap-image') {
22
- super.link = value;
23
- }
24
- }
25
- /* NOT FOR BROWSER END */
26
- /**
27
- * @param type 图片类型
28
- * @param link 图片文件名
29
- * @param text 图片参数
30
- */
31
- constructor(type, link, text, config = Parser.getConfig(), accum = []) {
32
- let token;
33
- if (text !== undefined) {
34
- token = new index_1.Token(text, config, accum);
35
- token.type = 'plain';
36
- for (let n = 1; n < constants_1.MAX_STAGE; n++) {
37
- token.parseOnce();
38
- }
39
- accum.splice(accum.indexOf(token), 1);
40
- }
41
- super(link, token?.toString(), config, accum);
42
- this.setAttribute('bracket', false);
43
- this.type = `${type}-image`;
44
- }
45
- /** private */
46
- getTitle() {
47
- const imagemap = this.type === 'imagemap-image';
48
- return this.normalizeTitle(String(this.firstChild), imagemap ? 0 : 6, true, !imagemap);
49
- }
50
- /** @private */
51
- getAttribute(key) {
52
- return key === 'padding' ? 0 : super.getAttribute(key);
53
- }
54
- /** @override */
55
- lint(start = this.getAbsoluteIndex()) {
56
- const errors = super.lint(start), { interwiki, ns, } = this.getAttribute('title');
57
- if (interwiki || ns !== 6) {
58
- errors.push((0, lint_1.generateForSelf)(this, { start }, 'invalid gallery image'));
59
- }
60
- return errors;
61
- }
62
- /**
63
- * 设置`#title`
64
- * @param title Title对象
65
- */
66
- #setName(title) {
67
- this.setAttribute('title', title);
68
- this.setAttribute('name', title.title);
69
- }
70
- /** @private */
71
- afterBuild() {
72
- this.#setName(this.getTitle());
73
- const /** @implements */ linkListener = (e, data) => {
74
- const { prevTarget } = e;
75
- if (prevTarget?.type === 'link-target') {
76
- const name = String(prevTarget), title = this.getTitle(), { interwiki, ns, valid } = title;
77
- if (!valid) {
78
- (0, debug_1.undo)(e, data);
79
- throw new Error(`非法的图片文件名:${name}`);
80
- }
81
- else if (interwiki || ns !== 6) {
82
- (0, debug_1.undo)(e, data);
83
- throw new Error(`图片链接不可更改命名空间:${name}`);
84
- }
85
- this.#setName(title);
86
- }
87
- };
88
- this.addEventListener(['remove', 'insert', 'replace', 'text'], linkListener);
89
- }
90
- /* NOT FOR BROWSER */
91
- /**
92
- * @override
93
- * @param token 待插入的子节点
94
- * @param i 插入位置
95
- * @throws `RangeError` 不可插入多余子节点
96
- * @throws `TypeError` 不可插入文本节点
97
- */
98
- insertAt(child, i) {
99
- if (this.type === 'gallery-image' && child.type === 'image-parameter' && !imageParameter_1.galleryParams.has(child.name)) {
100
- child.setAttribute('name', 'invalid');
101
- }
102
- return super.insertAt(child, i);
103
- }
104
- }
105
- exports.GalleryImageToken = GalleryImageToken;
106
- constants_1.classes['GalleryImageToken'] = __filename;
@@ -1,53 +0,0 @@
1
- import { LinkBaseToken } from './base';
2
- import type { Title } from '../../lib/title';
3
- import type { Token, AtomToken } from '../../internal';
4
- /**
5
- * 内链
6
- * @classdesc `{childNodes: [AtomToken, ?Token]}`
7
- */
8
- export declare class LinkToken extends LinkBaseToken {
9
- #private;
10
- readonly type = "link";
11
- readonly childNodes: [AtomToken] | [AtomToken, Token];
12
- abstract get children(): [AtomToken] | [AtomToken, Token];
13
- abstract get link(): Title;
14
- abstract set link(link: Title);
15
- /** 链接显示文字 */
16
- get innerText(): string;
17
- set innerText(text: string);
18
- /** 是否链接到自身 */
19
- get selfLink(): boolean;
20
- set selfLink(selfLink: boolean);
21
- /** @override */
22
- get fragment(): string | undefined;
23
- set fragment(fragment: string | undefined);
24
- /** interwiki */
25
- get interwiki(): string;
26
- /** @throws `RangeError` 非法的跨维基前缀 */
27
- set interwiki(interwiki: string);
28
- /** @override */
29
- setTarget(link: string): void;
30
- /**
31
- * 设置跨语言链接
32
- * @param lang 语言前缀
33
- * @param link 页面标题
34
- * @throws `SyntaxError` 仅有fragment
35
- */
36
- setLangLink(lang: string, link: string): void;
37
- /**
38
- * 设置fragment
39
- * @param fragment fragment
40
- */
41
- setFragment(fragment?: string): void;
42
- /**
43
- * 修改为到自身的链接
44
- * @param fragment fragment
45
- * @throws `RangeError` 空fragment
46
- */
47
- asSelfLink(fragment?: string | undefined): void;
48
- /**
49
- * 自动生成管道符后的链接文字
50
- * @throws `Error` 带有"#"或"%"时不可用
51
- */
52
- pipeTrick(): void;
53
- }
@@ -1,123 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LinkToken = void 0;
4
- const constants_1 = require("../../util/constants");
5
- const base_1 = require("./base");
6
- /**
7
- * 内链
8
- * @classdesc `{childNodes: [AtomToken, ?Token]}`
9
- */
10
- // @ts-expect-error not implementing all abstract methods
11
- class LinkToken extends base_1.LinkBaseToken {
12
- type = 'link';
13
- /* NOT FOR BROWSER */
14
- /** 链接显示文字 */
15
- get innerText() {
16
- return this.length > 1 ? this.lastChild.text() : this.firstChild.text().replace(/^\s*:/u, '');
17
- }
18
- set innerText(text) {
19
- this.setLinkText(text);
20
- }
21
- /** 是否链接到自身 */
22
- get selfLink() {
23
- const { link: { title, fragment } } = this;
24
- return !title && Boolean(fragment);
25
- }
26
- set selfLink(selfLink) {
27
- if (selfLink) {
28
- this.asSelfLink();
29
- }
30
- }
31
- /** @override */
32
- get fragment() {
33
- return super.fragment;
34
- }
35
- set fragment(fragment) {
36
- this.#setFragment(fragment);
37
- }
38
- /** interwiki */
39
- get interwiki() {
40
- return this.link.interwiki;
41
- }
42
- /** @throws `RangeError` 非法的跨维基前缀 */
43
- set interwiki(interwiki) {
44
- const { link: { prefix, main, fragment } } = this, link = `${interwiki}:${prefix}${main}${fragment === undefined ? '' : `#${fragment}`}`;
45
- if (interwiki && !this.isInterwiki(link)) {
46
- throw new RangeError(`${interwiki} 不是合法的跨维基前缀!`);
47
- }
48
- this.setTarget(link);
49
- }
50
- /** @override */
51
- setTarget(link) {
52
- super.setTarget(`${/^\s*[:#]/u.test(link) ? '' : ':'}${link}`);
53
- }
54
- /**
55
- * 设置跨语言链接
56
- * @param lang 语言前缀
57
- * @param link 页面标题
58
- * @throws `SyntaxError` 仅有fragment
59
- */
60
- setLangLink(lang, link) {
61
- link = link.trim();
62
- if (link.startsWith('#')) {
63
- throw new SyntaxError('跨语言链接不能仅为fragment!');
64
- }
65
- super.setTarget(`${lang}${link.startsWith(':') ? '' : ':'}${link}`);
66
- }
67
- /**
68
- * 设置fragment
69
- * @param fragment fragment
70
- * @param page 是否是其他页面
71
- */
72
- #setFragment(fragment, page = true) {
73
- fragment &&= fragment.replace(/[<>[\]#|=]/gu, p => encodeURIComponent(p));
74
- this.setTarget(`${page ? this.name : ''}${fragment === undefined ? '' : `#${fragment}`}`);
75
- }
76
- /**
77
- * 设置fragment
78
- * @param fragment fragment
79
- */
80
- setFragment(fragment) {
81
- this.#setFragment(fragment);
82
- }
83
- /**
84
- * 修改为到自身的链接
85
- * @param fragment fragment
86
- * @throws `RangeError` 空fragment
87
- */
88
- asSelfLink(fragment = this.fragment) {
89
- if (!fragment?.trim()) {
90
- throw new RangeError(`${this.constructor.name}.asSelfLink 方法必须指定非空的 fragment!`);
91
- }
92
- this.#setFragment(fragment, false);
93
- }
94
- /**
95
- * 自动生成管道符后的链接文字
96
- * @throws `Error` 带有"#"或"%"时不可用
97
- */
98
- pipeTrick() {
99
- const linkText = this.firstChild.text();
100
- if (linkText.includes('#') || linkText.includes('%')) {
101
- throw new Error('Pipe trick 不能用于带有"#"或"%"的场合!');
102
- }
103
- const m1 = /^:?(?:[ \w\x80-\xFF-]+:)?([^(]+)\(.+\)$/u.exec(linkText);
104
- if (m1) {
105
- this.setLinkText(m1[1].trim());
106
- return;
107
- }
108
- const m2 = /^:?(?:[ \w\x80-\xFF-]+:)?([^(]+)(.+)$/u.exec(linkText);
109
- if (m2) {
110
- this.setLinkText(m2[1].trim());
111
- return;
112
- }
113
- const m3 = /^:?(?:[ \w\x80-\xFF-]+:)?(.+?)(?:(?<!\()\(.+\))?(?:, |,|، )./u
114
- .exec(linkText);
115
- if (m3) {
116
- this.setLinkText(m3[1].trim());
117
- return;
118
- }
119
- this.setLinkText(linkText);
120
- }
121
- }
122
- exports.LinkToken = LinkToken;
123
- constants_1.classes['LinkToken'] = __filename;
@@ -1,69 +0,0 @@
1
- import * as Parser from '../index';
2
- import { Token } from './index';
3
- import type { LintError } from '../base';
4
- import type { AstNodes, AstText, CommentToken, IncludeToken, NoincludeToken, TranscludeToken } from '../internal';
5
- declare const MagicLinkToken_base: (abstract new (...args: any[]) => {
6
- "__#5@#pattern": RegExp;
7
- afterBuild(): void;
8
- getAttribute<T extends string>(key: T): TokenAttributeGetter<T>;
9
- setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
10
- replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
11
- readonly length: number;
12
- toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
13
- text(separator?: string | undefined): string;
14
- insertAt(token: unknown, i?: number | undefined): unknown;
15
- addEventListener(events: string | string[], listener: AstListener): void;
16
- }) & typeof Parser.Token;
17
- /**
18
- * 自由外链
19
- * @classdesc `{childNodes: ...AstText|CommentToken|IncludeToken|NoincludeToken}`
20
- */
21
- export declare class MagicLinkToken extends MagicLinkToken_base {
22
- type: 'free-ext-link' | 'ext-link-url';
23
- readonly childNodes: (AstText | CommentToken | IncludeToken | NoincludeToken | TranscludeToken)[];
24
- abstract get children(): (CommentToken | IncludeToken | NoincludeToken | TranscludeToken)[];
25
- abstract get firstChild(): AstText | TranscludeToken;
26
- abstract get firstElementChild(): CommentToken | IncludeToken | NoincludeToken | TranscludeToken | undefined;
27
- abstract get lastChild(): AstText | CommentToken | IncludeToken | NoincludeToken | TranscludeToken;
28
- abstract get lastElementChild(): CommentToken | IncludeToken | NoincludeToken | TranscludeToken | undefined;
29
- /** 协议 */
30
- get protocol(): string | undefined;
31
- /** @throws `Error` 特殊外链无法更改协议n */
32
- set protocol(value: string | undefined);
33
- /** 和内链保持一致 */
34
- get link(): string;
35
- set link(url: string);
36
- /**
37
- * @param url 网址
38
- * @param doubleSlash 是否接受"//"作为协议
39
- */
40
- constructor(url?: string, doubleSlash?: boolean, config?: Parser.Config, accum?: Token[]);
41
- /** @override */
42
- lint(start?: number): LintError[];
43
- /** @override */
44
- cloneNode(): this;
45
- /**
46
- * @override
47
- * @param token 待插入的节点
48
- * @param i 插入位置
49
- * @throws `RangeError` 插入`{{!}}`或`{{=}}`以外的魔术字或模板
50
- */
51
- insertAt(token: string, i?: number): AstText;
52
- /** @ignore */
53
- insertAt<T extends AstNodes>(token: T, i?: number): T;
54
- /**
55
- * 获取网址
56
- * @throws `Error` 非标准协议
57
- */
58
- getUrl(): URL;
59
- /**
60
- * 设置外链目标
61
- * @param url 含协议的网址
62
- */
63
- setTarget(url: string): void;
64
- /** 是否是模板或魔术字参数 */
65
- isParamValue(): boolean;
66
- /** 转义 `=` */
67
- escape(): void;
68
- }
69
- export {};
@@ -1,147 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MagicLinkToken = void 0;
4
- const lint_1 = require("../util/lint");
5
- const debug_1 = require("../util/debug");
6
- const constants_1 = require("../util/constants");
7
- const string_1 = require("../util/string");
8
- const syntax_1 = require("../mixin/syntax");
9
- const Parser = require("../index");
10
- const index_1 = require("./index");
11
- /**
12
- * 自由外链
13
- * @classdesc `{childNodes: ...AstText|CommentToken|IncludeToken|NoincludeToken}`
14
- */
15
- class MagicLinkToken extends (0, syntax_1.syntax)(index_1.Token) {
16
- /* NOT FOR BROWSER */
17
- /** 协议 */
18
- get protocol() {
19
- return this.getAttribute('pattern').exec(this.text())?.[0];
20
- }
21
- /** @throws `Error` 特殊外链无法更改协议n */
22
- set protocol(value) {
23
- if (typeof value !== 'string') {
24
- this.typeError('protocol', 'String');
25
- }
26
- const { link } = this, pattern = this.getAttribute('pattern');
27
- if (!pattern.test(link)) {
28
- throw new Error(`特殊外链无法更改协议:${link}`);
29
- }
30
- this.setTarget(link.replace(pattern, value));
31
- }
32
- /** 和内链保持一致 */
33
- get link() {
34
- const map = { '!': '|', '=': '=' };
35
- return (0, string_1.text)(this.childNodes.map(child => {
36
- const { type, name } = child;
37
- return type === 'magic-word' && name in map ? map[name] : child;
38
- }));
39
- }
40
- set link(url) {
41
- this.setTarget(url);
42
- }
43
- /* NOT FOR BROWSER END */
44
- /**
45
- * @param url 网址
46
- * @param doubleSlash 是否接受"//"作为协议
47
- */
48
- constructor(url, doubleSlash = false, config = Parser.getConfig(), accum = []) {
49
- super(url, config, accum, {
50
- 'Stage-1': '1:', '!ExtToken': '', AstText: ':', TranscludeToken: ':',
51
- });
52
- this.type = doubleSlash ? 'ext-link-url' : 'free-ext-link';
53
- this.setAttribute('pattern', new RegExp(`^(?:${config.protocol}${doubleSlash ? '|//' : ''})`, 'iu'));
54
- }
55
- /** @override */
56
- lint(start = this.getAbsoluteIndex()) {
57
- const errors = super.lint(start), source = `[,;。:!?()]+${this.type === 'ext-link-url' ? '|\\|+' : ''}`, regex = new RegExp(source, 'u'), regexGlobal = new RegExp(source, 'gu');
58
- let rect;
59
- for (const child of this.childNodes) {
60
- const { type, data } = child;
61
- if (type !== 'text' || !regex.test(data)) {
62
- continue;
63
- }
64
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
65
- const refError = (0, lint_1.generateForChild)(child, rect, '', 'warning');
66
- errors.push(...[...data.matchAll(regexGlobal)].map(({ index, 0: s }) => {
67
- const lines = data.slice(0, index).split('\n'), { length: top } = lines, { length: left } = lines.at(-1), startIndex = start + index, startLine = refError.startLine + top - 1, startCol = top === 1 ? refError.startCol + left : left;
68
- return {
69
- ...refError,
70
- message: Parser.msg('$1 in URL', s.startsWith('|') ? '"|"' : Parser.msg('full-width punctuation')),
71
- startIndex,
72
- endIndex: startIndex + s.length,
73
- startLine,
74
- endLine: startLine,
75
- startCol,
76
- endCol: startCol + s.length,
77
- };
78
- }));
79
- }
80
- return errors;
81
- }
82
- /* NOT FOR BROWSER */
83
- /** @override */
84
- cloneNode() {
85
- const cloned = this.cloneChildNodes();
86
- return debug_1.Shadow.run(() => {
87
- const token = new MagicLinkToken(undefined, this.type === 'ext-link-url', this.getAttribute('config'));
88
- token.append(...cloned);
89
- token.afterBuild();
90
- return token;
91
- });
92
- }
93
- /** @ignore */
94
- insertAt(token, i) {
95
- if (typeof token !== 'string') {
96
- const { type, name } = token;
97
- if (type === 'template') {
98
- throw new RangeError(`${this.constructor.name} 不可插入模板!`);
99
- }
100
- else if (!debug_1.Shadow.running && type === 'magic-word' && name !== '!' && name !== '=') {
101
- throw new RangeError(`${this.constructor.name} 不可插入 \`{{!}}\` 或 \`{{=}}\` 以外的魔术字!`);
102
- }
103
- }
104
- return super.insertAt(token, i);
105
- }
106
- /**
107
- * 获取网址
108
- * @throws `Error` 非标准协议
109
- */
110
- getUrl() {
111
- let { link } = this;
112
- if (link.startsWith('//')) {
113
- link = `https:${link}`;
114
- }
115
- try {
116
- return new URL(link);
117
- }
118
- catch (e) {
119
- if (e instanceof TypeError && e.message === 'Invalid URL') {
120
- throw new Error(`非标准协议的外部链接:${link}`);
121
- }
122
- throw e;
123
- }
124
- }
125
- /**
126
- * 设置外链目标
127
- * @param url 含协议的网址
128
- */
129
- setTarget(url) {
130
- const { childNodes } = Parser.parse(url, this.getAttribute('include'), 2, this.getAttribute('config'));
131
- this.replaceChildren(...childNodes);
132
- }
133
- /** 是否是模板或魔术字参数 */
134
- isParamValue() {
135
- return this.closest('parameter')?.getValue() === this.text();
136
- }
137
- /** 转义 `=` */
138
- escape() {
139
- for (const child of this.childNodes) {
140
- if (child.type === 'text') {
141
- child.escape();
142
- }
143
- }
144
- }
145
- }
146
- exports.MagicLinkToken = MagicLinkToken;
147
- constants_1.classes['MagicLinkToken'] = __filename;
@@ -1,44 +0,0 @@
1
- import * as 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 class NestedToken extends Token {
13
- #private;
14
- readonly type = "ext-inner";
15
- readonly name: string;
16
- readonly childNodes: (ExtToken | NoincludeToken | CommentToken)[];
17
- abstract get children(): (ExtToken | NoincludeToken | CommentToken)[];
18
- abstract get firstChild(): ExtToken | NoincludeToken | CommentToken | undefined;
19
- abstract get firstElementChild(): ExtToken | NoincludeToken | CommentToken | undefined;
20
- abstract get lastChild(): ExtToken | NoincludeToken | CommentToken | undefined;
21
- abstract get lastElementChild(): ExtToken | NoincludeToken | CommentToken | undefined;
22
- abstract get nextSibling(): undefined;
23
- abstract get nextElementSibling(): undefined;
24
- abstract get previousSibling(): AttributesToken;
25
- abstract get previousElementSibling(): AttributesToken;
26
- abstract get parentNode(): ExtToken | 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
- /** @override */
34
- lint(start?: number): LintError[];
35
- /**
36
- * @override
37
- * @param token 待插入的子节点
38
- * @param i 插入位置
39
- * @throws `TypeError` 不是许可的标签
40
- */
41
- insertAt<T extends Token>(token: T, i?: number): T;
42
- /** @override */
43
- cloneNode(): this;
44
- }
@@ -1,87 +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 debug_1 = require("../util/debug");
6
- const constants_1 = require("../util/constants");
7
- const Parser = require("../index");
8
- const index_1 = require("./index");
9
- const ext_1 = require("./tagPair/ext");
10
- const noinclude_1 = require("./nowiki/noinclude");
11
- const comment_1 = require("./nowiki/comment");
12
- /**
13
- * 嵌套式的扩展标签
14
- * @classdesc `{childNodes: ...ExtToken|NoincludeToken|CommentToken}`
15
- */
16
- class NestedToken extends index_1.Token {
17
- type = 'ext-inner';
18
- /* NOT FOR BROWSER */
19
- #tags;
20
- #regex;
21
- /**
22
- * @param regex 内层正则
23
- * @param tags 内层标签名
24
- */
25
- constructor(wikitext, regex, tags, config = Parser.getConfig(), accum = []) {
26
- wikitext = wikitext?.replace(regex, (comment, name, attr, inner, closing) => {
27
- const str = `\0${accum.length + 1}${name ? 'e' : 'c'}\x7F`;
28
- if (name) {
29
- new ext_1.ExtToken(name, attr, inner, closing, config, accum);
30
- }
31
- else {
32
- const closed = comment.endsWith('-->');
33
- new comment_1.CommentToken(comment.slice(4, closed ? -3 : undefined), closed, config, accum);
34
- }
35
- return str;
36
- })?.replace(/(?<=^|\0\d+[ce]\x7F)[^\0]+(?=$|\0\d+[ce]\x7F)/gu, substr => {
37
- new noinclude_1.NoincludeToken(substr, config, accum);
38
- return `\0${accum.length}c\x7F`;
39
- });
40
- super(wikitext, config, accum, {
41
- NoincludeToken: ':', ExtToken: ':',
42
- });
43
- this.#tags = [...tags];
44
- this.#regex = regex;
45
- }
46
- /** @override */
47
- lint(start = this.getAbsoluteIndex()) {
48
- let rect;
49
- return [
50
- ...super.lint(start),
51
- ...this.childNodes.filter(child => {
52
- if (child.type === 'ext' || child.type === 'comment') {
53
- return false;
54
- }
55
- const str = String(child).trim();
56
- return str && !/^<!--.*-->$/su.test(str);
57
- }).map(child => {
58
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
59
- return (0, lint_1.generateForChild)(child, rect, Parser.msg('invalid content in <$1>', this.name));
60
- }),
61
- ];
62
- }
63
- /* NOT FOR BROWSER */
64
- /**
65
- * @override
66
- * @param token 待插入的子节点
67
- * @param i 插入位置
68
- * @throws `TypeError` 不是许可的标签
69
- */
70
- insertAt(token, i) {
71
- if (typeof token !== 'string' && token.type === 'ext' && !this.#tags.includes(token.name)) {
72
- throw new TypeError(`${this.constructor.name}只能以${this.#tags.join('或')}标签作为子节点!`);
73
- }
74
- return super.insertAt(token, i);
75
- }
76
- /** @override */
77
- cloneNode() {
78
- const cloned = this.cloneChildNodes(), config = this.getAttribute('config');
79
- return debug_1.Shadow.run(() => {
80
- const token = new NestedToken(undefined, this.#regex, this.#tags, config);
81
- token.append(...cloned);
82
- return token;
83
- });
84
- }
85
- }
86
- exports.NestedToken = NestedToken;
87
- constants_1.classes['NestedToken'] = __filename;
@@ -1,46 +0,0 @@
1
- import * as Parser from '../../index';
2
- import { Token } from '../index';
3
- import type { AstText } from '../../lib/text';
4
- declare type NowikiTypes = 'ext-inner' | 'comment' | 'dd' | 'double-underscore' | 'hr' | 'list' | 'noinclude' | 'quote';
5
- declare const NowikiBaseToken_base: ((abstract new (...args: any[]) => {
6
- removeAt(): never;
7
- insertAt(token: string, i?: number | undefined): Parser.AstText;
8
- insertAt<T extends Parser.AstNodes>(token: T, i?: number | undefined): T;
9
- readonly length: number;
10
- toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
11
- text(separator?: string | undefined): string;
12
- afterBuild(): void;
13
- getAttribute<T_1 extends string>(key: T_1): TokenAttributeGetter<T_1>;
14
- setAttribute<T_2 extends string>(key: T_2, value: TokenAttributeSetter<T_2>): void;
15
- addEventListener(events: string | string[], listener: AstListener): void;
16
- replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
17
- }) & {
18
- readonly fixed: true;
19
- }) & typeof Parser.Token;
20
- /**
21
- * 纯文字Token,不会被解析
22
- * @classdesc `{childNodes: [AstText]}`
23
- */
24
- export declare abstract class NowikiBaseToken extends NowikiBaseToken_base {
25
- type: NowikiTypes;
26
- readonly childNodes: [AstText];
27
- abstract get children(): [];
28
- abstract get firstChild(): AstText;
29
- abstract get firstElementChild(): undefined;
30
- abstract get lastChild(): AstText;
31
- abstract get lastElementChild(): undefined;
32
- /** 纯文本部分 */
33
- get innerText(): string;
34
- /** @param wikitext default: `''` */
35
- constructor(wikitext?: string, config?: Parser.Config, accum?: Token[]);
36
- /** @override */
37
- cloneNode(this: this & {
38
- constructor: new (...args: any[]) => unknown;
39
- }): this;
40
- /**
41
- * @override
42
- * @param str 新文本
43
- */
44
- setText(str: string): string;
45
- }
46
- export {};