wikiparser-node 1.3.7 → 1.3.8-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 (153) 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 +64 -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 +31 -13
  12. package/config/.schema.json +0 -172
  13. package/dist/addon/table.d.ts +0 -6
  14. package/dist/addon/table.js +0 -558
  15. package/dist/base.d.ts +0 -45
  16. package/dist/index.d.ts +0 -32
  17. package/dist/index.js +0 -209
  18. package/dist/internal.d.ts +0 -44
  19. package/dist/lib/element.d.ts +0 -154
  20. package/dist/lib/element.js +0 -630
  21. package/dist/lib/node.d.ts +0 -146
  22. package/dist/lib/node.js +0 -417
  23. package/dist/lib/range.d.ts +0 -104
  24. package/dist/lib/range.js +0 -385
  25. package/dist/lib/ranges.d.ts +0 -26
  26. package/dist/lib/ranges.js +0 -118
  27. package/dist/lib/text.d.ts +0 -62
  28. package/dist/lib/text.js +0 -255
  29. package/dist/lib/title.d.ts +0 -38
  30. package/dist/lib/title.js +0 -162
  31. package/dist/mixin/attributesParent.js +0 -89
  32. package/dist/mixin/fixed.js +0 -25
  33. package/dist/mixin/flagsParent.js +0 -70
  34. package/dist/mixin/hidden.js +0 -26
  35. package/dist/mixin/magicLinkParent.js +0 -41
  36. package/dist/mixin/singleLine.js +0 -25
  37. package/dist/mixin/sol.js +0 -43
  38. package/dist/mixin/syntax.js +0 -54
  39. package/dist/parser/braces.js +0 -128
  40. package/dist/parser/commentAndExt.js +0 -80
  41. package/dist/parser/converter.js +0 -40
  42. package/dist/parser/externalLinks.js +0 -28
  43. package/dist/parser/hrAndDoubleUnderscore.js +0 -38
  44. package/dist/parser/html.js +0 -36
  45. package/dist/parser/links.js +0 -94
  46. package/dist/parser/list.js +0 -66
  47. package/dist/parser/magicLinks.js +0 -40
  48. package/dist/parser/quotes.js +0 -67
  49. package/dist/parser/selector.js +0 -162
  50. package/dist/parser/table.js +0 -120
  51. package/dist/src/arg.d.ts +0 -56
  52. package/dist/src/arg.js +0 -187
  53. package/dist/src/atom.d.ts +0 -12
  54. package/dist/src/atom.js +0 -27
  55. package/dist/src/attribute.d.ts +0 -88
  56. package/dist/src/attribute.js +0 -398
  57. package/dist/src/attributes.d.ts +0 -109
  58. package/dist/src/attributes.js +0 -343
  59. package/dist/src/converter.d.ts +0 -53
  60. package/dist/src/converter.js +0 -79
  61. package/dist/src/converterFlags.d.ts +0 -87
  62. package/dist/src/converterFlags.js +0 -224
  63. package/dist/src/converterRule.d.ts +0 -77
  64. package/dist/src/converterRule.js +0 -208
  65. package/dist/src/extLink.d.ts +0 -55
  66. package/dist/src/extLink.js +0 -122
  67. package/dist/src/gallery.d.ts +0 -54
  68. package/dist/src/gallery.js +0 -121
  69. package/dist/src/heading.d.ts +0 -76
  70. package/dist/src/heading.js +0 -127
  71. package/dist/src/hidden.d.ts +0 -23
  72. package/dist/src/hidden.js +0 -23
  73. package/dist/src/html.d.ts +0 -104
  74. package/dist/src/html.js +0 -226
  75. package/dist/src/imageParameter.d.ts +0 -65
  76. package/dist/src/imageParameter.js +0 -245
  77. package/dist/src/imagemap.d.ts +0 -56
  78. package/dist/src/imagemap.js +0 -147
  79. package/dist/src/imagemapLink.d.ts +0 -61
  80. package/dist/src/imagemapLink.js +0 -40
  81. package/dist/src/index.d.ts +0 -140
  82. package/dist/src/index.js +0 -769
  83. package/dist/src/link/base.d.ts +0 -52
  84. package/dist/src/link/base.js +0 -209
  85. package/dist/src/link/category.d.ts +0 -13
  86. package/dist/src/link/category.js +0 -29
  87. package/dist/src/link/file.d.ts +0 -96
  88. package/dist/src/link/file.js +0 -257
  89. package/dist/src/link/galleryImage.d.ts +0 -45
  90. package/dist/src/link/galleryImage.js +0 -106
  91. package/dist/src/link/index.d.ts +0 -53
  92. package/dist/src/link/index.js +0 -124
  93. package/dist/src/magicLink.d.ts +0 -69
  94. package/dist/src/magicLink.js +0 -147
  95. package/dist/src/nested.d.ts +0 -43
  96. package/dist/src/nested.js +0 -86
  97. package/dist/src/nowiki/base.d.ts +0 -48
  98. package/dist/src/nowiki/base.js +0 -42
  99. package/dist/src/nowiki/comment.d.ts +0 -41
  100. package/dist/src/nowiki/comment.js +0 -67
  101. package/dist/src/nowiki/dd.d.ts +0 -8
  102. package/dist/src/nowiki/dd.js +0 -25
  103. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -47
  104. package/dist/src/nowiki/doubleUnderscore.js +0 -50
  105. package/dist/src/nowiki/hr.d.ts +0 -33
  106. package/dist/src/nowiki/hr.js +0 -14
  107. package/dist/src/nowiki/index.d.ts +0 -16
  108. package/dist/src/nowiki/index.js +0 -21
  109. package/dist/src/nowiki/list.d.ts +0 -31
  110. package/dist/src/nowiki/list.js +0 -48
  111. package/dist/src/nowiki/listBase.d.ts +0 -20
  112. package/dist/src/nowiki/listBase.js +0 -12
  113. package/dist/src/nowiki/noinclude.d.ts +0 -26
  114. package/dist/src/nowiki/noinclude.js +0 -24
  115. package/dist/src/nowiki/quote.d.ts +0 -24
  116. package/dist/src/nowiki/quote.js +0 -45
  117. package/dist/src/onlyinclude.d.ts +0 -16
  118. package/dist/src/onlyinclude.js +0 -57
  119. package/dist/src/paramTag/index.d.ts +0 -37
  120. package/dist/src/paramTag/index.js +0 -68
  121. package/dist/src/paramTag/inputbox.d.ts +0 -8
  122. package/dist/src/paramTag/inputbox.js +0 -23
  123. package/dist/src/parameter.d.ts +0 -86
  124. package/dist/src/parameter.js +0 -205
  125. package/dist/src/pre.d.ts +0 -28
  126. package/dist/src/pre.js +0 -51
  127. package/dist/src/syntax.d.ts +0 -30
  128. package/dist/src/syntax.js +0 -34
  129. package/dist/src/table/base.d.ts +0 -59
  130. package/dist/src/table/base.js +0 -78
  131. package/dist/src/table/index.d.ts +0 -228
  132. package/dist/src/table/index.js +0 -379
  133. package/dist/src/table/td.d.ts +0 -107
  134. package/dist/src/table/td.js +0 -263
  135. package/dist/src/table/tr.d.ts +0 -32
  136. package/dist/src/table/tr.js +0 -56
  137. package/dist/src/table/trBase.d.ts +0 -53
  138. package/dist/src/table/trBase.js +0 -153
  139. package/dist/src/tagPair/ext.d.ts +0 -58
  140. package/dist/src/tagPair/ext.js +0 -140
  141. package/dist/src/tagPair/include.d.ts +0 -54
  142. package/dist/src/tagPair/include.js +0 -63
  143. package/dist/src/tagPair/index.d.ts +0 -49
  144. package/dist/src/tagPair/index.js +0 -93
  145. package/dist/src/transclude.d.ts +0 -167
  146. package/dist/src/transclude.js +0 -698
  147. package/dist/util/constants.js +0 -113
  148. package/dist/util/debug.js +0 -83
  149. package/dist/util/diff.js +0 -72
  150. package/dist/util/lint.js +0 -30
  151. package/dist/util/string.js +0 -51
  152. package/errors/README +0 -1
  153. package/printed/README +0 -1
@@ -1,45 +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
- constructorError(msg: string): never;
18
- }) & typeof Parser.FileToken;
19
- /** 图库图片 */
20
- export declare class GalleryImageToken extends GalleryImageToken_base {
21
- #private;
22
- type: 'gallery-image' | 'imagemap-image';
23
- /** 图片链接 */
24
- get link(): string | Title;
25
- set link(value: string);
26
- /**
27
- * @param type 图片类型
28
- * @param link 图片文件名
29
- * @param text 图片参数
30
- */
31
- constructor(type: 'gallery' | 'imagemap', link: string, text?: string, config?: Parser.Config, accum?: Token[]);
32
- /** private */
33
- getTitle(): Title;
34
- /** @override */
35
- lint(start?: number): LintError[];
36
- /**
37
- * @override
38
- * @param token 待插入的子节点
39
- * @param i 插入位置
40
- * @throws `RangeError` 不可插入多余子节点
41
- * @throws `TypeError` 不可插入文本节点
42
- */
43
- insertAt<T extends AtomToken | ImageParameterToken>(child: T, i?: number): T;
44
- }
45
- 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,124 +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('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
- // eslint-disable-next-line es-x/no-regexp-lookbehind-assertions
114
- const m3 = /^:?(?:[ \w\x80-\xFF-]+:)?(.+?)(?:(?<!\()\(.+\))?(?:, |,|، )./u
115
- .exec(linkText);
116
- if (m3) {
117
- this.setLinkText(m3[1].trim());
118
- return;
119
- }
120
- this.setLinkText(linkText);
121
- }
122
- }
123
- exports.LinkToken = LinkToken;
124
- 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
- "__#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
- constructorError(msg: string): never;
18
- }) & typeof Parser.Token;
19
- /**
20
- * 自由外链
21
- * @classdesc `{childNodes: ...AstText|CommentToken|IncludeToken|NoincludeToken}`
22
- */
23
- export declare class MagicLinkToken extends MagicLinkToken_base {
24
- type: 'free-ext-link' | 'ext-link-url';
25
- readonly childNodes: (AstText | CommentToken | IncludeToken | NoincludeToken | TranscludeToken)[];
26
- abstract get children(): (CommentToken | IncludeToken | NoincludeToken | TranscludeToken)[];
27
- abstract get firstChild(): AstText | TranscludeToken;
28
- abstract get firstElementChild(): CommentToken | IncludeToken | NoincludeToken | TranscludeToken | undefined;
29
- abstract get lastChild(): AstText | CommentToken | IncludeToken | NoincludeToken | TranscludeToken;
30
- abstract get lastElementChild(): CommentToken | IncludeToken | NoincludeToken | TranscludeToken | undefined;
31
- /** 协议 */
32
- get protocol(): string | undefined;
33
- /** @throws `Error` 特殊外链无法更改协议n */
34
- set protocol(value: string | undefined);
35
- /** 和内链保持一致 */
36
- get link(): string;
37
- set link(url: string);
38
- /**
39
- * @param url 网址
40
- * @param doubleSlash 是否接受"//"作为协议
41
- */
42
- constructor(url?: string, doubleSlash?: boolean, config?: Parser.Config, accum?: Token[]);
43
- /** @override */
44
- lint(start?: number): LintError[];
45
- /** @override */
46
- cloneNode(): this;
47
- /**
48
- * @override
49
- * @param token 待插入的节点
50
- * @param i 插入位置
51
- */
52
- insertAt(token: string, i?: number): AstText;
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
- regexGlobal.lastIndex = 0;
67
- for (let mt = regexGlobal.exec(data); mt; mt = regexGlobal.exec(data)) {
68
- const { index, 0: s } = mt, lines = data.slice(0, index).split('\n'), { length: top } = lines, { length: left } = lines[lines.length - 1], startIndex = refError.startIndex + index, startLine = refError.startLine + top - 1, startCol = top === 1 ? refError.startCol + left : left;
69
- errors.push({
70
- ...refError,
71
- message: Parser.msg('$1 in URL', s.startsWith('|') ? '"|"' : Parser.msg('full-width punctuation')),
72
- startIndex,
73
- endIndex: startIndex + s.length,
74
- startLine,
75
- endLine: startLine,
76
- startCol,
77
- endCol: startCol + s.length,
78
- });
79
- }
80
- }
81
- return errors;
82
- }
83
- /* NOT FOR BROWSER */
84
- /** @override */
85
- cloneNode() {
86
- const cloned = this.cloneChildNodes();
87
- return debug_1.Shadow.run(() => {
88
- const token = new MagicLinkToken(undefined, this.type === 'ext-link-url', this.getAttribute('config'));
89
- token.append(...cloned);
90
- token.afterBuild();
91
- return token;
92
- });
93
- }
94
- insertAt(token, i) {
95
- if (typeof token !== 'string') {
96
- const { type, name } = token;
97
- if (type === 'template') {
98
- this.constructorError('不可插入模板');
99
- }
100
- else if (!debug_1.Shadow.running && type === 'magic-word' && name !== '!' && name !== '=') {
101
- this.constructorError('不可插入 `{{!}}` 或 `{{=}}` 以外的魔术字');
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,43 +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
- */
40
- insertAt<T extends Token>(token: T, i?: number): T;
41
- /** @override */
42
- cloneNode(): this;
43
- }
@@ -1,86 +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, (_, lead, substr) => {
37
- new noinclude_1.NoincludeToken(substr, config, accum);
38
- return `${lead}\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
- */
69
- insertAt(token, i) {
70
- if (typeof token !== 'string' && token.type === 'ext' && !this.#tags.includes(token.name)) {
71
- this.constructorError(`只能以 ${this.#tags.join(' 或 ')} 标签作为子节点`);
72
- }
73
- return super.insertAt(token, i);
74
- }
75
- /** @override */
76
- cloneNode() {
77
- const cloned = this.cloneChildNodes(), config = this.getAttribute('config');
78
- return debug_1.Shadow.run(() => {
79
- const token = new NestedToken(undefined, this.#regex, this.#tags, config);
80
- token.append(...cloned);
81
- return token;
82
- });
83
- }
84
- }
85
- exports.NestedToken = NestedToken;
86
- constants_1.classes['NestedToken'] = __filename;