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