wikiparser-node 1.3.2 → 1.3.3-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 (154) 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 +114 -0
  11. package/package.json +32 -12
  12. package/config/.schema.json +0 -172
  13. package/dist/addon/table.d.ts +0 -6
  14. package/dist/addon/table.js +0 -564
  15. package/dist/base.d.ts +0 -45
  16. package/dist/bin/toc.js +0 -18
  17. package/dist/index.d.ts +0 -31
  18. package/dist/index.js +0 -209
  19. package/dist/internal.d.ts +0 -44
  20. package/dist/lib/element.d.ts +0 -155
  21. package/dist/lib/element.js +0 -634
  22. package/dist/lib/node.d.ts +0 -146
  23. package/dist/lib/node.js +0 -419
  24. package/dist/lib/range.d.ts +0 -104
  25. package/dist/lib/range.js +0 -385
  26. package/dist/lib/ranges.d.ts +0 -26
  27. package/dist/lib/ranges.js +0 -117
  28. package/dist/lib/text.d.ts +0 -62
  29. package/dist/lib/text.js +0 -248
  30. package/dist/lib/title.d.ts +0 -38
  31. package/dist/lib/title.js +0 -162
  32. package/dist/mixin/attributesParent.js +0 -94
  33. package/dist/mixin/fixed.js +0 -32
  34. package/dist/mixin/flagsParent.js +0 -70
  35. package/dist/mixin/hidden.js +0 -26
  36. package/dist/mixin/magicLinkParent.js +0 -41
  37. package/dist/mixin/singleLine.js +0 -25
  38. package/dist/mixin/sol.js +0 -43
  39. package/dist/mixin/syntax.js +0 -56
  40. package/dist/parser/braces.js +0 -121
  41. package/dist/parser/commentAndExt.js +0 -69
  42. package/dist/parser/converter.js +0 -40
  43. package/dist/parser/externalLinks.js +0 -28
  44. package/dist/parser/hrAndDoubleUnderscore.js +0 -38
  45. package/dist/parser/html.js +0 -36
  46. package/dist/parser/links.js +0 -94
  47. package/dist/parser/list.js +0 -59
  48. package/dist/parser/magicLinks.js +0 -40
  49. package/dist/parser/quotes.js +0 -67
  50. package/dist/parser/selector.js +0 -162
  51. package/dist/parser/table.js +0 -112
  52. package/dist/src/arg.d.ts +0 -58
  53. package/dist/src/arg.js +0 -189
  54. package/dist/src/atom.d.ts +0 -12
  55. package/dist/src/atom.js +0 -27
  56. package/dist/src/attribute.d.ts +0 -87
  57. package/dist/src/attribute.js +0 -392
  58. package/dist/src/attributes.d.ts +0 -107
  59. package/dist/src/attributes.js +0 -341
  60. package/dist/src/converter.d.ts +0 -52
  61. package/dist/src/converter.js +0 -79
  62. package/dist/src/converterFlags.d.ts +0 -87
  63. package/dist/src/converterFlags.js +0 -224
  64. package/dist/src/converterRule.d.ts +0 -81
  65. package/dist/src/converterRule.js +0 -212
  66. package/dist/src/extLink.d.ts +0 -54
  67. package/dist/src/extLink.js +0 -122
  68. package/dist/src/gallery.d.ts +0 -55
  69. package/dist/src/gallery.js +0 -122
  70. package/dist/src/heading.d.ts +0 -74
  71. package/dist/src/heading.js +0 -127
  72. package/dist/src/hidden.d.ts +0 -22
  73. package/dist/src/hidden.js +0 -23
  74. package/dist/src/html.d.ts +0 -101
  75. package/dist/src/html.js +0 -222
  76. package/dist/src/imageParameter.d.ts +0 -66
  77. package/dist/src/imageParameter.js +0 -247
  78. package/dist/src/imagemap.d.ts +0 -57
  79. package/dist/src/imagemap.js +0 -148
  80. package/dist/src/imagemapLink.d.ts +0 -59
  81. package/dist/src/imagemapLink.js +0 -40
  82. package/dist/src/index.d.ts +0 -146
  83. package/dist/src/index.js +0 -777
  84. package/dist/src/link/base.d.ts +0 -52
  85. package/dist/src/link/base.js +0 -209
  86. package/dist/src/link/category.d.ts +0 -13
  87. package/dist/src/link/category.js +0 -29
  88. package/dist/src/link/file.d.ts +0 -96
  89. package/dist/src/link/file.js +0 -255
  90. package/dist/src/link/galleryImage.d.ts +0 -44
  91. package/dist/src/link/galleryImage.js +0 -106
  92. package/dist/src/link/index.d.ts +0 -53
  93. package/dist/src/link/index.js +0 -123
  94. package/dist/src/magicLink.d.ts +0 -70
  95. package/dist/src/magicLink.js +0 -147
  96. package/dist/src/nested.d.ts +0 -44
  97. package/dist/src/nested.js +0 -87
  98. package/dist/src/nowiki/base.d.ts +0 -47
  99. package/dist/src/nowiki/base.js +0 -42
  100. package/dist/src/nowiki/comment.d.ts +0 -40
  101. package/dist/src/nowiki/comment.js +0 -67
  102. package/dist/src/nowiki/dd.d.ts +0 -8
  103. package/dist/src/nowiki/dd.js +0 -25
  104. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -45
  105. package/dist/src/nowiki/doubleUnderscore.js +0 -50
  106. package/dist/src/nowiki/hr.d.ts +0 -31
  107. package/dist/src/nowiki/hr.js +0 -14
  108. package/dist/src/nowiki/index.d.ts +0 -16
  109. package/dist/src/nowiki/index.js +0 -21
  110. package/dist/src/nowiki/list.d.ts +0 -30
  111. package/dist/src/nowiki/list.js +0 -48
  112. package/dist/src/nowiki/listBase.d.ts +0 -19
  113. package/dist/src/nowiki/listBase.js +0 -12
  114. package/dist/src/nowiki/noinclude.d.ts +0 -26
  115. package/dist/src/nowiki/noinclude.js +0 -25
  116. package/dist/src/nowiki/quote.d.ts +0 -23
  117. package/dist/src/nowiki/quote.js +0 -45
  118. package/dist/src/onlyinclude.d.ts +0 -16
  119. package/dist/src/onlyinclude.js +0 -57
  120. package/dist/src/paramTag/index.d.ts +0 -37
  121. package/dist/src/paramTag/index.js +0 -68
  122. package/dist/src/paramTag/inputbox.d.ts +0 -8
  123. package/dist/src/paramTag/inputbox.js +0 -23
  124. package/dist/src/parameter.d.ts +0 -85
  125. package/dist/src/parameter.js +0 -205
  126. package/dist/src/pre.d.ts +0 -28
  127. package/dist/src/pre.js +0 -51
  128. package/dist/src/syntax.d.ts +0 -28
  129. package/dist/src/syntax.js +0 -34
  130. package/dist/src/table/base.d.ts +0 -53
  131. package/dist/src/table/base.js +0 -78
  132. package/dist/src/table/index.d.ts +0 -229
  133. package/dist/src/table/index.js +0 -379
  134. package/dist/src/table/td.d.ts +0 -104
  135. package/dist/src/table/td.js +0 -261
  136. package/dist/src/table/tr.d.ts +0 -32
  137. package/dist/src/table/tr.js +0 -56
  138. package/dist/src/table/trBase.d.ts +0 -54
  139. package/dist/src/table/trBase.js +0 -159
  140. package/dist/src/tagPair/ext.d.ts +0 -56
  141. package/dist/src/tagPair/ext.js +0 -142
  142. package/dist/src/tagPair/include.d.ts +0 -53
  143. package/dist/src/tagPair/include.js +0 -63
  144. package/dist/src/tagPair/index.d.ts +0 -48
  145. package/dist/src/tagPair/index.js +0 -93
  146. package/dist/src/transclude.d.ts +0 -167
  147. package/dist/src/transclude.js +0 -689
  148. package/dist/util/constants.js +0 -108
  149. package/dist/util/debug.js +0 -64
  150. package/dist/util/diff.js +0 -72
  151. package/dist/util/lint.js +0 -46
  152. package/dist/util/string.js +0 -61
  153. package/errors/README +0 -1
  154. package/printed/README +0 -1
@@ -1,44 +0,0 @@
1
- import * as Parser from '../../index';
2
- import { Token } from '../index';
3
- import type { Title } from '../../lib/title';
4
- import type { LintError } from '../../base';
5
- import type { AtomToken, ImageParameterToken } from '../../internal';
6
- declare const GalleryImageToken_base: (abstract new (...args: any[]) => {
7
- toString(omit?: Set<string> | undefined): string;
8
- text(): string;
9
- readonly length: number;
10
- lint(start?: number | undefined): Parser.LintError[];
11
- insertAt(token: unknown, i?: number | undefined): unknown;
12
- afterBuild(): void;
13
- getAttribute<T extends string>(key: T): TokenAttributeGetter<T>;
14
- setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
15
- addEventListener(events: string | string[], listener: AstListener): void;
16
- replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
17
- }) & typeof Parser.FileToken;
18
- /** 图库图片 */
19
- export declare class GalleryImageToken extends GalleryImageToken_base {
20
- #private;
21
- type: 'gallery-image' | 'imagemap-image';
22
- /** 图片链接 */
23
- get link(): string | Title;
24
- set link(value: string);
25
- /**
26
- * @param type 图片类型
27
- * @param link 图片文件名
28
- * @param text 图片参数
29
- */
30
- constructor(type: 'gallery' | 'imagemap', link: string, text?: string, config?: Parser.Config, accum?: Token[]);
31
- /** private */
32
- getTitle(): Title;
33
- /** @override */
34
- lint(start?: number): LintError[];
35
- /**
36
- * @override
37
- * @param token 待插入的子节点
38
- * @param i 插入位置
39
- * @throws `RangeError` 不可插入多余子节点
40
- * @throws `TypeError` 不可插入文本节点
41
- */
42
- insertAt<T extends AtomToken | ImageParameterToken>(child: T, i?: number): T;
43
- }
44
- export {};
@@ -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,70 +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
- "__#10@#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
- lint(start?: number | undefined): Parser.LintError[];
15
- insertAt(token: unknown, i?: number | undefined): unknown;
16
- addEventListener(events: string | string[], listener: AstListener): void;
17
- }) & typeof Parser.Token;
18
- /**
19
- * 自由外链
20
- * @classdesc `{childNodes: ...AstText|CommentToken|IncludeToken|NoincludeToken}`
21
- */
22
- export declare class MagicLinkToken extends MagicLinkToken_base {
23
- type: 'free-ext-link' | 'ext-link-url';
24
- readonly childNodes: (AstText | CommentToken | IncludeToken | NoincludeToken | TranscludeToken)[];
25
- abstract get children(): (CommentToken | IncludeToken | NoincludeToken | TranscludeToken)[];
26
- abstract get firstChild(): AstText | TranscludeToken;
27
- abstract get firstElementChild(): CommentToken | IncludeToken | NoincludeToken | TranscludeToken | undefined;
28
- abstract get lastChild(): AstText | CommentToken | IncludeToken | NoincludeToken | TranscludeToken;
29
- abstract get lastElementChild(): CommentToken | IncludeToken | NoincludeToken | TranscludeToken | undefined;
30
- /** 协议 */
31
- get protocol(): string | undefined;
32
- /** @throws `Error` 特殊外链无法更改协议n */
33
- set protocol(value: string | undefined);
34
- /** 和内链保持一致 */
35
- get link(): string;
36
- set link(url: string);
37
- /**
38
- * @param url 网址
39
- * @param doubleSlash 是否接受"//"作为协议
40
- */
41
- constructor(url?: string, doubleSlash?: boolean, config?: Parser.Config, accum?: Token[]);
42
- /** @override */
43
- lint(start?: number): LintError[];
44
- /** @override */
45
- cloneNode(): this;
46
- /**
47
- * @override
48
- * @param token 待插入的节点
49
- * @param i 插入位置
50
- * @throws `RangeError` 插入`{{!}}`或`{{=}}`以外的魔术字或模板
51
- */
52
- insertAt(token: string, i?: number): AstText;
53
- /** @ignore */
54
- insertAt<T extends AstNodes>(token: T, i?: number): T;
55
- /**
56
- * 获取网址
57
- * @throws `Error` 非标准协议
58
- */
59
- getUrl(): URL;
60
- /**
61
- * 设置外链目标
62
- * @param url 含协议的网址
63
- */
64
- setTarget(url: string): void;
65
- /** 是否是模板或魔术字参数 */
66
- isParamValue(): boolean;
67
- /** 转义 `=` */
68
- escape(): void;
69
- }
70
- 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;