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,58 +0,0 @@
1
- import * as Parser from '../../index';
2
- import { Token } from '../index';
3
- import { TagPairToken } from './index';
4
- import { AttributesToken } from '../attributes';
5
- import type { LintError } from '../../base';
6
- declare const ExtToken_base: (abstract new (...args: any[]) => {
7
- readonly childNodes: Parser.AstNodes[];
8
- readonly "__#8@#attributesChild": Parser.AttributesToken;
9
- attributes: Record<string, string | true>;
10
- className: string;
11
- classList: Set<string>;
12
- id: string;
13
- hasAttr(key: string): boolean;
14
- getAttr(key: string): string | true | undefined;
15
- getAttrNames(): Set<string>;
16
- getAttrs(): Record<string, string | true>;
17
- setAttr(key: string, value: string | boolean): void;
18
- removeAttr(key: string): void;
19
- toggleAttr(key: string, force?: boolean | undefined): void;
20
- readonly length: number;
21
- toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
22
- text(separator?: string | undefined): string;
23
- insertAt(token: unknown, i?: number | undefined): unknown; /**
24
- * 扩展标签
25
- * @classdesc `{childNodes: [AttributesToken, Token]}`
26
- */
27
- afterBuild(): void;
28
- getAttribute<T extends string>(key: T): TokenAttributeGetter<T>;
29
- setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
30
- addEventListener(events: string | string[], listener: AstListener): void;
31
- replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
32
- }) & typeof TagPairToken;
33
- /**
34
- * 扩展标签
35
- * @classdesc `{childNodes: [AttributesToken, Token]}`
36
- */
37
- export declare class ExtToken extends ExtToken_base {
38
- readonly type = "ext";
39
- readonly childNodes: [AttributesToken, Token];
40
- abstract get children(): [AttributesToken, Token];
41
- abstract get firstChild(): AttributesToken;
42
- abstract get firstElementChild(): AttributesToken;
43
- abstract get lastChild(): Token;
44
- /** @override */
45
- get closed(): boolean;
46
- /**
47
- * @param name 标签名
48
- * @param attr 标签属性
49
- * @param inner 内部wikitext
50
- * @param closed 是否封闭
51
- */
52
- constructor(name: string, attr?: string, inner?: string, closed?: string, config?: Parser.Config, accum?: Token[]);
53
- /** @override */
54
- lint(start?: number): LintError[];
55
- /** @override */
56
- cloneNode(): this;
57
- }
58
- export {};
@@ -1,142 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExtToken = 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 attributesParent_1 = require("../../mixin/attributesParent");
8
- const Parser = require("../../index");
9
- const index_1 = require("../index");
10
- const index_2 = require("./index");
11
- const attributes_1 = require("../attributes");
12
- /**
13
- * 从数组中删除指定元素
14
- * @param arr 数组
15
- * @param ele 元素
16
- */
17
- const del = (arr, ele) => {
18
- const set = new Set(arr);
19
- set.delete(ele);
20
- return [...set];
21
- };
22
- /**
23
- * 扩展标签
24
- * @classdesc `{childNodes: [AttributesToken, Token]}`
25
- */
26
- class ExtToken extends (0, attributesParent_1.attributesParent)(index_2.TagPairToken) {
27
- type = 'ext';
28
- /* NOT FOR BROWSER */
29
- /** @override */
30
- // eslint-disable-next-line class-methods-use-this
31
- get closed() {
32
- return true;
33
- }
34
- /* NOT FOR BROWSER END */
35
- /**
36
- * @param name 标签名
37
- * @param attr 标签属性
38
- * @param inner 内部wikitext
39
- * @param closed 是否封闭
40
- */
41
- constructor(name, attr, inner, closed, config = Parser.getConfig(), accum = []) {
42
- const lcName = name.toLowerCase(), attrToken = new attributes_1.AttributesToken(!attr || attr.trimStart() !== attr
43
- ? attr
44
- : ` ${attr}`, 'ext-attrs', lcName, config, accum), newConfig = { ...config, ext: del(config.ext, lcName), excludes: [...config.excludes ?? []] };
45
- let innerToken;
46
- switch (lcName) {
47
- case 'tab':
48
- newConfig.ext = del(newConfig.ext, 'tabs');
49
- // fall through
50
- case 'indicator':
51
- case 'poem':
52
- case 'ref':
53
- case 'option':
54
- case 'combooption':
55
- case 'tabs':
56
- case 'poll':
57
- case 'seo':
58
- if (lcName === 'poem') {
59
- newConfig.excludes.push('heading');
60
- }
61
- innerToken = new index_1.Token(inner, newConfig, accum);
62
- break;
63
- case 'pre': {
64
- const { PreToken } = require('../pre');
65
- innerToken = new PreToken(inner, newConfig, accum);
66
- break;
67
- }
68
- case 'dynamicpagelist': {
69
- const { ParamTagToken } = require('../paramTag/index');
70
- innerToken = new ParamTagToken(inner, newConfig, accum);
71
- break;
72
- }
73
- case 'inputbox': {
74
- newConfig.excludes.push('heading');
75
- const { InputboxToken } = require('../paramTag/inputbox');
76
- innerToken = new InputboxToken(inner, newConfig, accum);
77
- break;
78
- }
79
- case 'references': {
80
- const { NestedToken } = require('../nested');
81
- innerToken = new NestedToken(inner, /<!--.*?(?:-->|$)|<(ref)(\s[^>]*)?>(.*?)<\/(ref\s*)>/gisu, ['ref'], newConfig, accum);
82
- break;
83
- }
84
- case 'choose': {
85
- const { NestedToken } = require('../nested');
86
- innerToken = new NestedToken(inner, /<(option|choicetemplate)(\s[^>]*)?>(.*?)<\/(\1)>/gsu, ['option', 'choicetemplate'], newConfig, accum);
87
- break;
88
- }
89
- case 'combobox': {
90
- const { NestedToken } = require('../nested');
91
- innerToken = new NestedToken(inner, /<(combooption)(\s[^>]*)?>(.*?)<\/(combooption\s*)>/gisu, ['combooption'], newConfig, accum);
92
- break;
93
- }
94
- case 'gallery': {
95
- const { GalleryToken } = require('../gallery');
96
- innerToken = new GalleryToken(inner, newConfig, accum);
97
- break;
98
- }
99
- case 'imagemap': {
100
- const { ImagemapToken } = require('../imagemap');
101
- innerToken = new ImagemapToken(inner, newConfig, accum);
102
- break;
103
- }
104
- // 更多定制扩展的代码示例:
105
- // ```
106
- // case 'extensionName': {
107
- // const {ExtensionToken}: typeof import('../extension') = require('../extension');
108
- // innerToken = new ExtensionToken(inner, newConfig, accum);
109
- // break;
110
- // }
111
- // ```
112
- default: {
113
- const { NowikiToken } = require('../nowiki/index');
114
- innerToken = new NowikiToken(inner, newConfig);
115
- }
116
- }
117
- innerToken.setAttribute('name', lcName);
118
- innerToken.type = 'ext-inner';
119
- super(name, attrToken, innerToken, closed, config, accum);
120
- }
121
- /** @override */
122
- lint(start = this.getAbsoluteIndex()) {
123
- const errors = super.lint(start);
124
- if (this.name !== 'nowiki' && this.closest('html-attrs, table-attrs')) {
125
- const rect = { start, ...this.getRootNode().posFromIndex(start) };
126
- errors.push((0, lint_1.generateForSelf)(this, rect, 'extension tag in HTML tag attributes'));
127
- }
128
- return errors;
129
- }
130
- /* NOT FOR BROWSER */
131
- /** @override */
132
- cloneNode() {
133
- const inner = this.lastChild.cloneNode(), tags = this.getAttribute('tags'), config = this.getAttribute('config'), attr = String(this.firstChild);
134
- return debug_1.Shadow.run(() => {
135
- const token = new ExtToken(tags[0], attr, '', this.selfClosing ? undefined : tags[1], config);
136
- token.lastChild.safeReplaceWith(inner);
137
- return token;
138
- });
139
- }
140
- }
141
- exports.ExtToken = ExtToken;
142
- constants_1.classes['ExtToken'] = __filename;
@@ -1,52 +0,0 @@
1
- import * as Parser from '../../index';
2
- import { TagPairToken } from './index';
3
- import type { AstText, Token } from '../../internal';
4
- declare const IncludeToken_base: ((abstract new (...args: any[]) => {
5
- text(): string;
6
- readonly length: number;
7
- toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
8
- insertAt(token: unknown, i?: number | undefined): unknown;
9
- afterBuild(): void;
10
- getAttribute<T extends string>(key: T): TokenAttributeGetter<T>;
11
- setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
12
- addEventListener(events: string | string[], listener: AstListener): void;
13
- replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
14
- }) & {
15
- readonly hidden: true; /**
16
- * `<includeonly>`或`<noinclude>`或`<onlyinclude>`
17
- * @classdesc `{childNodes: [AstText, AstText]}`
18
- */
19
- }) & typeof TagPairToken;
20
- /**
21
- * `<includeonly>`或`<noinclude>`或`<onlyinclude>`
22
- * @classdesc `{childNodes: [AstText, AstText]}`
23
- */
24
- export declare class IncludeToken extends IncludeToken_base {
25
- readonly type = "include";
26
- readonly childNodes: [AstText, 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
- /** @override */
33
- get innerText(): string | undefined;
34
- set innerText(text: string | undefined);
35
- /**
36
- * @param name 标签名
37
- * @param attr 标签属性
38
- * @param inner 内部wikitext
39
- * @param closed 是否封闭
40
- */
41
- constructor(name: string, attr?: string, inner?: string, closed?: string, config?: Parser.Config, accum?: Token[]);
42
- /** @override */
43
- cloneNode(): this;
44
- /**
45
- * @override
46
- * @param str 新文本
47
- */
48
- setText(str: string): string;
49
- /** 清除标签属性 */
50
- removeAttr(): void;
51
- }
52
- export {};
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IncludeToken = void 0;
4
- const debug_1 = require("../../util/debug");
5
- const constants_1 = require("../../util/constants");
6
- const hidden_1 = require("../../mixin/hidden");
7
- const Parser = require("../../index");
8
- const index_1 = require("./index");
9
- /**
10
- * `<includeonly>`或`<noinclude>`或`<onlyinclude>`
11
- * @classdesc `{childNodes: [AstText, AstText]}`
12
- */
13
- class IncludeToken extends (0, hidden_1.hidden)(index_1.TagPairToken) {
14
- type = 'include';
15
- /* NOT FOR BROWSER */
16
- /** @override */
17
- get innerText() {
18
- return this.selfClosing ? undefined : this.lastChild.data;
19
- }
20
- set innerText(text) {
21
- if (text === undefined) {
22
- this.selfClosing = true;
23
- }
24
- else {
25
- this.selfClosing = false;
26
- this.setText(text);
27
- }
28
- }
29
- /* NOT FOR BROWSER END */
30
- /**
31
- * @param name 标签名
32
- * @param attr 标签属性
33
- * @param inner 内部wikitext
34
- * @param closed 是否封闭
35
- */
36
- constructor(name, attr = '', inner, closed, config = Parser.getConfig(), accum = []) {
37
- super(name, attr, inner ?? '', inner === undefined ? closed : closed ?? '', config, accum);
38
- }
39
- /* NOT FOR BROWSER */
40
- /** @override */
41
- cloneNode() {
42
- const tags = this.getAttribute('tags'), config = this.getAttribute('config'), { innerText } = this, closing = this.selfClosing || !this.closed ? undefined : tags[1];
43
- return debug_1.Shadow.run(() => new IncludeToken(tags[0], this.firstChild.data, innerText, closing, config));
44
- }
45
- /**
46
- * @override
47
- * @param str 新文本
48
- */
49
- setText(str) {
50
- return super.setText(str, 1);
51
- }
52
- /** 清除标签属性 */
53
- removeAttr() {
54
- super.setText('');
55
- }
56
- }
57
- exports.IncludeToken = IncludeToken;
58
- constants_1.classes['IncludeToken'] = __filename;
@@ -1,47 +0,0 @@
1
- import * as Parser from '../../index';
2
- import { Token } from '../index';
3
- import type { AstNodes } from '../../lib/node';
4
- declare const TagPairToken_base: ((abstract new (...args: any[]) => {
5
- removeAt(): never;
6
- insertAt(token: string, i?: number | undefined): Parser.AstText;
7
- insertAt<T extends Parser.AstNodes>(token: T, i?: number | undefined): T;
8
- readonly length: number;
9
- toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
10
- text(separator?: string | undefined): string;
11
- afterBuild(): void;
12
- getAttribute<T_1 extends string>(key: T_1): TokenAttributeGetter<T_1>;
13
- setAttribute<T_2 extends string>(key: T_2, value: TokenAttributeSetter<T_2>): void;
14
- addEventListener(events: string | string[], listener: AstListener): void;
15
- replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
16
- }) & {
17
- readonly fixed: true;
18
- }) & typeof Parser.Token;
19
- /** 成对标签 */
20
- export declare abstract class TagPairToken extends TagPairToken_base {
21
- #private;
22
- type: 'ext' | 'include';
23
- readonly name: string;
24
- readonly childNodes: [AstNodes, AstNodes];
25
- abstract get firstChild(): AstNodes;
26
- abstract get lastChild(): AstNodes;
27
- /** 是否闭合 */
28
- get closed(): boolean;
29
- set closed(value: boolean);
30
- /** 是否自封闭 */
31
- get selfClosing(): boolean;
32
- set selfClosing(value: boolean);
33
- /** 内部wikitext */
34
- get innerText(): string | undefined;
35
- /**
36
- * @param name 标签名
37
- * @param attr 标签属性
38
- * @param inner 内部wikitext
39
- * @param closed 是否封闭;约定`undefined`表示自封闭,`''`表示未闭合
40
- */
41
- constructor(name: string, attr: string | Token, inner: string | Token, closed?: string, config?: Parser.Config, accum?: Token[]);
42
- /** @override */
43
- text(): string;
44
- /** @override */
45
- print(): string;
46
- }
47
- export {};
@@ -1,93 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TagPairToken = void 0;
4
- const constants_1 = require("../../util/constants");
5
- const fixed_1 = require("../../mixin/fixed");
6
- const Parser = require("../../index");
7
- const index_1 = require("../index");
8
- /** 成对标签 */
9
- class TagPairToken extends (0, fixed_1.fixed)(index_1.Token) {
10
- #selfClosing;
11
- #closed;
12
- #tags;
13
- /** 是否闭合 */
14
- get closed() {
15
- return this.#closed;
16
- }
17
- /* NOT FOR BROWSER */
18
- set closed(value) {
19
- this.#closed ||= value;
20
- }
21
- /** 是否自封闭 */
22
- get selfClosing() {
23
- return this.#selfClosing;
24
- }
25
- set selfClosing(value) {
26
- if (value !== this.selfClosing && this.lastChild.text()) {
27
- Parser.warn(`<${this.name}>标签内部的${value ? '文本将被隐藏' : '原有文本将再次可见'}!`);
28
- }
29
- this.#selfClosing = value;
30
- }
31
- /** 内部wikitext */
32
- get innerText() {
33
- return this.selfClosing ? undefined : this.lastChild.text();
34
- }
35
- /* NOT FOR BROWSER END */
36
- /**
37
- * @param name 标签名
38
- * @param attr 标签属性
39
- * @param inner 内部wikitext
40
- * @param closed 是否封闭;约定`undefined`表示自封闭,`''`表示未闭合
41
- */
42
- constructor(name, attr, inner, closed, config = Parser.getConfig(), accum = []) {
43
- super(undefined, config);
44
- this.setAttribute('name', name.toLowerCase());
45
- this.#tags = [name, closed || name];
46
- this.#selfClosing = closed === undefined;
47
- this.#closed = closed !== '';
48
- this.append(attr, inner);
49
- const index = typeof attr === 'string' ? -1 : accum.indexOf(attr);
50
- accum.splice(index === -1 ? Infinity : index, 0, this);
51
- }
52
- /** @private */
53
- toString(omit) {
54
- const { firstChild, lastChild, nextSibling, name, closed, } = this, [opening, closing] = this.#tags;
55
- if (omit && this.matchesTypes(omit)) {
56
- return '';
57
- }
58
- else if (!closed && nextSibling) {
59
- Parser.error(`自动闭合 <${name}>`, lastChild);
60
- this.#closed = true;
61
- }
62
- return this.#selfClosing
63
- ? `<${opening}${firstChild.toString(omit)}/>`
64
- : `<${opening}${firstChild.toString(omit)}>${lastChild.toString(omit)}${this.closed ? `</${closing}>` : ''}`;
65
- }
66
- /** @override */
67
- text() {
68
- const [opening, closing] = this.#tags;
69
- return this.#selfClosing
70
- ? `<${opening}${this.firstChild.text()}/>`
71
- : `<${opening}${super.text('>')}${this.closed ? `</${closing}>` : ''}`;
72
- }
73
- /** @private */
74
- getAttribute(key) {
75
- if (key === 'tags') {
76
- return [...this.#tags];
77
- }
78
- return key === 'padding' ? this.#tags[0].length + 1 : super.getAttribute(key);
79
- }
80
- /** @private */
81
- getGaps() {
82
- return 1;
83
- }
84
- /** @override */
85
- print() {
86
- const [opening, closing] = this.#tags;
87
- return super.print(this.#selfClosing
88
- ? { pre: `&lt;${opening}`, post: '/&gt;' }
89
- : { pre: `&lt;${opening}`, sep: '&gt;', post: this.closed ? `&lt;/${closing}&gt;` : '' });
90
- }
91
- }
92
- exports.TagPairToken = TagPairToken;
93
- constants_1.classes['TagPairToken'] = __filename;
@@ -1,167 +0,0 @@
1
- import * as Parser from '../index';
2
- import { Token } from './index';
3
- import { ParameterToken } from './parameter';
4
- import { AtomToken } from './atom';
5
- import { SyntaxToken } from './syntax';
6
- import type { LintError } from '../base';
7
- /**
8
- * 模板或魔术字
9
- * @classdesc `{childNodes: [AtomToken|SyntaxToken, ...AtomToken, ...ParameterToken]}`
10
- */
11
- export declare class TranscludeToken extends Token {
12
- #private;
13
- type: 'template' | 'magic-word';
14
- readonly name: string;
15
- readonly modifier = "";
16
- readonly childNodes: [AtomToken | SyntaxToken, ...ParameterToken[]] | [SyntaxToken, AtomToken, AtomToken, ...ParameterToken[]];
17
- abstract get children(): [AtomToken | SyntaxToken, ...ParameterToken[]] | [SyntaxToken, AtomToken, AtomToken, ...ParameterToken[]];
18
- abstract get firstChild(): AtomToken | SyntaxToken;
19
- abstract get firstElementChild(): AtomToken | SyntaxToken;
20
- abstract get lastChild(): AtomToken | SyntaxToken | ParameterToken;
21
- abstract get lastElementChild(): AtomToken | SyntaxToken | ParameterToken;
22
- /** 是否存在重复参数 */
23
- get duplication(): boolean;
24
- set duplication(duplication: boolean);
25
- /**
26
- * @param title 模板标题或魔术字
27
- * @param parts 参数各部分
28
- * @throws `SyntaxError` 非法的模板名称
29
- */
30
- constructor(title: string, parts: ([string] | [string | number, string])[], config?: Parser.Config, accum?: Token[]);
31
- /**
32
- * 设置引用修饰符
33
- * @param modifier 引用修饰符
34
- */
35
- setModifier(modifier: string): boolean;
36
- /** 是否是模板或模块 */
37
- isTemplate(): boolean;
38
- /** @override */
39
- text(): string;
40
- /** @override */
41
- lint(start?: number): LintError[];
42
- /**
43
- * @override
44
- * @param token 待插入的子节点
45
- * @param i 插入位置
46
- */
47
- insertAt<T extends ParameterToken>(token: T, i?: number): T;
48
- /** 获取所有参数 */
49
- getAllArgs(): readonly ParameterToken[];
50
- /** 获取所有匿名参数 */
51
- getAnonArgs(): readonly ParameterToken[];
52
- /**
53
- * 获取指定参数
54
- * @param key 参数名
55
- * @param exact 是否匹配匿名性
56
- * @param copy 是否返回一个备份
57
- */
58
- getArgs(key: string | number, exact?: boolean, copy?: boolean): Set<ParameterToken>;
59
- /**
60
- * 获取重名参数
61
- * @throws `Error` 仅用于模板
62
- */
63
- getDuplicatedArgs(): readonly [string, ParameterToken[]][];
64
- /**
65
- * 对特定魔术字获取可能的取值
66
- * @throws `Error` 不是可接受的魔术字
67
- */
68
- getPossibleValues(): readonly Token[];
69
- /** @override */
70
- print(): string;
71
- /** @override */
72
- cloneNode(): this;
73
- /** 替换引用 */
74
- subst(): void;
75
- /** 安全的替换引用 */
76
- safesubst(): void;
77
- /**
78
- * @override
79
- * @param i 移除位置
80
- */
81
- removeAt(i: number): ParameterToken;
82
- /**
83
- * 是否具有某参数
84
- * @param key 参数名
85
- * @param exact 是否匹配匿名性
86
- */
87
- hasArg(key: string | number, exact?: boolean): boolean;
88
- /**
89
- * 获取生效的指定参数
90
- * @param key 参数名
91
- * @param exact 是否匹配匿名性
92
- */
93
- getArg(key: string | number, exact?: boolean): ParameterToken | undefined;
94
- /**
95
- * 移除指定参数
96
- * @param key 参数名
97
- * @param exact 是否匹配匿名性
98
- */
99
- removeArg(key: string | number, exact?: boolean): void;
100
- /** 获取所有参数名 */
101
- getKeys(): readonly string[];
102
- /**
103
- * 获取参数值
104
- * @param key 参数名
105
- */
106
- getValues(key: string | number): readonly string[];
107
- /** 获取所有生效的参数值 */
108
- getValue(): Record<string, string>;
109
- /**
110
- * 获取生效的指定参数值
111
- * @param key 参数名
112
- */
113
- getValue(key: string | number): string | undefined;
114
- /**
115
- * 插入匿名参数
116
- * @param val 参数值
117
- */
118
- newAnonArg(val: string): ParameterToken;
119
- /**
120
- * 设置参数值
121
- * @param key 参数名
122
- * @param value 参数值
123
- * @throws `Error` 仅用于模板
124
- */
125
- setValue(key: string, value: string): void;
126
- /**
127
- * 将匿名参数改写为命名参数
128
- * @throws `Error` 仅用于模板
129
- */
130
- anonToNamed(): void;
131
- /**
132
- * 替换模板名
133
- * @param title 模板名
134
- * @throws `Error` 仅用于模板
135
- */
136
- replaceTemplate(title: string): void;
137
- /**
138
- * 替换模块名
139
- * @param title 模块名
140
- * @throws `Error` 仅用于模块
141
- */
142
- replaceModule(title: string): void;
143
- /**
144
- * 替换模块函数
145
- * @param func 模块函数名
146
- * @throws `Error` 仅用于模块
147
- * @throws `Error` 尚未指定模块名称
148
- */
149
- replaceFunction(func: string): void;
150
- /**
151
- * 重复参数计数
152
- * @throws `Error` 仅用于模板
153
- */
154
- hasDuplicatedArgs(): number;
155
- /**
156
- * 修复重名参数:
157
- * `aggressive = false`时只移除空参数和全同参数,优先保留匿名参数,否则将所有匿名参数更改为命名。
158
- * `aggressive = true`时还会尝试处理连续的以数字编号的参数。
159
- * @param aggressive 是否使用有更大风险的修复手段
160
- */
161
- fixDuplication(aggressive?: boolean): readonly string[];
162
- /**
163
- * 转义模板内的表格
164
- * @throws `Error` 转义失败
165
- */
166
- escapeTables(): TranscludeToken;
167
- }