wikiparser-node 1.4.1-b → 1.4.1

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 (162) hide show
  1. package/config/.schema.json +172 -0
  2. package/config/enwiki.json +814 -1
  3. package/config/llwiki.json +35 -1
  4. package/config/moegirl.json +44 -1
  5. package/config/zhwiki.json +466 -1
  6. package/dist/addon/table.d.ts +6 -0
  7. package/dist/addon/table.js +560 -0
  8. package/dist/base.d.ts +53 -0
  9. package/dist/index.d.ts +32 -0
  10. package/dist/index.js +208 -0
  11. package/dist/internal.d.ts +44 -0
  12. package/dist/lib/element.d.ts +154 -0
  13. package/dist/lib/element.js +635 -0
  14. package/dist/lib/node.d.ts +146 -0
  15. package/dist/lib/node.js +419 -0
  16. package/dist/lib/range.d.ts +104 -0
  17. package/dist/lib/range.js +385 -0
  18. package/dist/lib/ranges.d.ts +26 -0
  19. package/dist/lib/ranges.js +118 -0
  20. package/dist/lib/text.d.ts +62 -0
  21. package/dist/lib/text.js +265 -0
  22. package/dist/lib/title.d.ts +38 -0
  23. package/dist/lib/title.js +163 -0
  24. package/dist/mixin/attributesParent.d.ts +20 -0
  25. package/dist/mixin/attributesParent.js +89 -0
  26. package/dist/mixin/fixed.d.ts +5 -0
  27. package/dist/mixin/fixed.js +28 -0
  28. package/dist/mixin/flagsParent.d.ts +61 -0
  29. package/dist/mixin/flagsParent.js +70 -0
  30. package/dist/mixin/hidden.d.ts +5 -0
  31. package/dist/mixin/hidden.js +24 -0
  32. package/dist/mixin/magicLinkParent.d.ts +34 -0
  33. package/dist/mixin/magicLinkParent.js +41 -0
  34. package/dist/mixin/singleLine.d.ts +5 -0
  35. package/dist/mixin/singleLine.js +25 -0
  36. package/dist/mixin/sol.d.ts +8 -0
  37. package/dist/mixin/sol.js +43 -0
  38. package/dist/mixin/syntax.d.ts +6 -0
  39. package/dist/mixin/syntax.js +54 -0
  40. package/dist/parser/braces.js +131 -0
  41. package/dist/parser/commentAndExt.js +90 -0
  42. package/dist/parser/converter.js +41 -0
  43. package/dist/parser/externalLinks.js +32 -0
  44. package/dist/parser/hrAndDoubleUnderscore.js +41 -0
  45. package/dist/parser/html.js +39 -0
  46. package/dist/parser/links.js +95 -0
  47. package/dist/parser/list.js +68 -0
  48. package/dist/parser/magicLinks.js +43 -0
  49. package/dist/parser/quotes.js +68 -0
  50. package/dist/parser/selector.js +162 -0
  51. package/dist/parser/table.js +124 -0
  52. package/dist/src/arg.d.ts +58 -0
  53. package/dist/src/arg.js +195 -0
  54. package/dist/src/atom.d.ts +12 -0
  55. package/dist/src/atom.js +27 -0
  56. package/dist/src/attribute.d.ts +67 -0
  57. package/dist/src/attribute.js +423 -0
  58. package/dist/src/attributes.d.ts +109 -0
  59. package/dist/src/attributes.js +347 -0
  60. package/dist/src/converter.d.ts +28 -0
  61. package/dist/src/converter.js +86 -0
  62. package/dist/src/converterFlags.d.ts +87 -0
  63. package/dist/src/converterFlags.js +225 -0
  64. package/dist/src/converterRule.d.ts +77 -0
  65. package/dist/src/converterRule.js +209 -0
  66. package/dist/src/extLink.d.ts +38 -0
  67. package/dist/src/extLink.js +133 -0
  68. package/dist/src/gallery.d.ts +54 -0
  69. package/dist/src/gallery.js +127 -0
  70. package/dist/src/heading.d.ts +47 -0
  71. package/dist/src/heading.js +144 -0
  72. package/dist/src/hidden.d.ts +7 -0
  73. package/dist/src/hidden.js +23 -0
  74. package/dist/src/html.d.ts +62 -0
  75. package/dist/src/html.js +285 -0
  76. package/dist/src/imageParameter.d.ts +65 -0
  77. package/dist/src/imageParameter.js +248 -0
  78. package/dist/src/imagemap.d.ts +56 -0
  79. package/dist/src/imagemap.js +152 -0
  80. package/dist/src/imagemapLink.d.ts +28 -0
  81. package/dist/src/imagemapLink.js +44 -0
  82. package/dist/src/index.d.ts +143 -0
  83. package/dist/src/index.js +791 -0
  84. package/dist/src/link/base.d.ts +52 -0
  85. package/dist/src/link/base.js +209 -0
  86. package/dist/src/link/category.d.ts +13 -0
  87. package/dist/src/link/category.js +28 -0
  88. package/dist/src/link/file.d.ts +96 -0
  89. package/dist/src/link/file.js +262 -0
  90. package/dist/src/link/galleryImage.d.ts +31 -0
  91. package/dist/src/link/galleryImage.js +105 -0
  92. package/dist/src/link/index.d.ts +56 -0
  93. package/dist/src/link/index.js +134 -0
  94. package/dist/src/magicLink.d.ts +51 -0
  95. package/dist/src/magicLink.js +148 -0
  96. package/dist/src/nested.d.ts +43 -0
  97. package/dist/src/nested.js +90 -0
  98. package/dist/src/nowiki/base.d.ts +27 -0
  99. package/dist/src/nowiki/base.js +42 -0
  100. package/dist/src/nowiki/comment.d.ts +27 -0
  101. package/dist/src/nowiki/comment.js +74 -0
  102. package/dist/src/nowiki/dd.d.ts +8 -0
  103. package/dist/src/nowiki/dd.js +24 -0
  104. package/dist/src/nowiki/doubleUnderscore.d.ts +18 -0
  105. package/dist/src/nowiki/doubleUnderscore.js +50 -0
  106. package/dist/src/nowiki/hr.d.ts +8 -0
  107. package/dist/src/nowiki/hr.js +13 -0
  108. package/dist/src/nowiki/index.d.ts +16 -0
  109. package/dist/src/nowiki/index.js +20 -0
  110. package/dist/src/nowiki/list.d.ts +19 -0
  111. package/dist/src/nowiki/list.js +47 -0
  112. package/dist/src/nowiki/listBase.d.ts +5 -0
  113. package/dist/src/nowiki/listBase.js +11 -0
  114. package/dist/src/nowiki/noinclude.d.ts +10 -0
  115. package/dist/src/nowiki/noinclude.js +23 -0
  116. package/dist/src/nowiki/quote.d.ts +14 -0
  117. package/dist/src/nowiki/quote.js +68 -0
  118. package/dist/src/onlyinclude.d.ts +16 -0
  119. package/dist/src/onlyinclude.js +57 -0
  120. package/dist/src/paramTag/index.d.ts +37 -0
  121. package/dist/src/paramTag/index.js +68 -0
  122. package/dist/src/paramTag/inputbox.d.ts +8 -0
  123. package/dist/src/paramTag/inputbox.js +22 -0
  124. package/dist/src/parameter.d.ts +67 -0
  125. package/dist/src/parameter.js +215 -0
  126. package/dist/src/pre.d.ts +28 -0
  127. package/dist/src/pre.js +54 -0
  128. package/dist/src/syntax.d.ts +14 -0
  129. package/dist/src/syntax.js +34 -0
  130. package/dist/src/table/base.d.ts +27 -0
  131. package/dist/src/table/base.js +80 -0
  132. package/dist/src/table/index.d.ts +230 -0
  133. package/dist/src/table/index.js +385 -0
  134. package/dist/src/table/td.d.ts +88 -0
  135. package/dist/src/table/td.js +273 -0
  136. package/dist/src/table/tr.d.ts +32 -0
  137. package/dist/src/table/tr.js +57 -0
  138. package/dist/src/table/trBase.d.ts +53 -0
  139. package/dist/src/table/trBase.js +154 -0
  140. package/dist/src/tagPair/ext.d.ts +29 -0
  141. package/dist/src/tagPair/ext.js +151 -0
  142. package/dist/src/tagPair/include.d.ts +37 -0
  143. package/dist/src/tagPair/include.js +71 -0
  144. package/dist/src/tagPair/index.d.ts +27 -0
  145. package/dist/src/tagPair/index.js +76 -0
  146. package/dist/src/transclude.d.ts +167 -0
  147. package/dist/src/transclude.js +700 -0
  148. package/dist/util/constants.js +113 -0
  149. package/dist/util/debug.js +83 -0
  150. package/dist/util/diff.js +72 -0
  151. package/dist/util/lint.js +30 -0
  152. package/dist/util/string.js +53 -0
  153. package/errors/README +1 -0
  154. package/package.json +14 -30
  155. package/printed/README +1 -0
  156. package/bundle/bundle.min.js +0 -36
  157. package/extensions/dist/base.js +0 -64
  158. package/extensions/dist/editor.js +0 -159
  159. package/extensions/dist/highlight.js +0 -59
  160. package/extensions/dist/lint.js +0 -48
  161. package/extensions/editor.css +0 -63
  162. package/extensions/ui.css +0 -141
@@ -0,0 +1,151 @@
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
+ /**
29
+ * @param name 标签名
30
+ * @param attr 标签属性
31
+ * @param inner 内部wikitext
32
+ * @param closed 是否封闭
33
+ */
34
+ constructor(name, attr, inner, closed, config = Parser.getConfig(), accum = []) {
35
+ const lcName = name.toLowerCase(),
36
+ // @ts-expect-error abstract class
37
+ attrToken = new attributes_1.AttributesToken(!attr || attr.trimStart() !== attr ? attr : ` ${attr}`, 'ext-attrs', lcName, config, accum), newConfig = { ...config, ext: del(config.ext, lcName), excludes: [...config.excludes ?? []] };
38
+ let innerToken;
39
+ switch (lcName) {
40
+ case 'tab':
41
+ newConfig.ext = del(newConfig.ext, 'tabs');
42
+ // fall through
43
+ case 'indicator':
44
+ case 'poem':
45
+ case 'ref':
46
+ case 'option':
47
+ case 'combooption':
48
+ case 'tabs':
49
+ case 'poll':
50
+ case 'seo':
51
+ if (lcName === 'poem') {
52
+ newConfig.excludes.push('heading');
53
+ }
54
+ innerToken = new index_1.Token(inner, newConfig, accum);
55
+ break;
56
+ case 'pre': {
57
+ const { PreToken } = require('../pre');
58
+ // @ts-expect-error abstract class
59
+ innerToken = new PreToken(inner, newConfig, accum);
60
+ break;
61
+ }
62
+ case 'dynamicpagelist': {
63
+ const { ParamTagToken } = require('../paramTag/index');
64
+ // @ts-expect-error abstract class
65
+ innerToken = new ParamTagToken(inner, newConfig, accum);
66
+ break;
67
+ }
68
+ case 'inputbox': {
69
+ newConfig.excludes.push('heading');
70
+ const { InputboxToken } = require('../paramTag/inputbox');
71
+ // @ts-expect-error abstract class
72
+ innerToken = new InputboxToken(inner, newConfig, accum);
73
+ break;
74
+ }
75
+ case 'references': {
76
+ const { NestedToken } = require('../nested');
77
+ // @ts-expect-error abstract class
78
+ innerToken = new NestedToken(inner, /<!--.*?(?:-->|$)|<(ref)(\s[^>]*)?>(.*?)<\/(ref\s*)>/gisu, ['ref'], newConfig, accum);
79
+ break;
80
+ }
81
+ case 'choose': {
82
+ const { NestedToken } = require('../nested');
83
+ // @ts-expect-error abstract class
84
+ innerToken = new NestedToken(inner, /<(option|choicetemplate)(\s[^>]*)?>(.*?)<\/(\1)>/gsu, ['option', 'choicetemplate'], newConfig, accum);
85
+ break;
86
+ }
87
+ case 'combobox': {
88
+ const { NestedToken } = require('../nested');
89
+ // @ts-expect-error abstract class
90
+ innerToken = new NestedToken(inner, /<(combooption)(\s[^>]*)?>(.*?)<\/(combooption\s*)>/gisu, ['combooption'], newConfig, accum);
91
+ break;
92
+ }
93
+ case 'gallery': {
94
+ const { GalleryToken } = require('../gallery');
95
+ // @ts-expect-error abstract class
96
+ innerToken = new GalleryToken(inner, newConfig, accum);
97
+ break;
98
+ }
99
+ case 'imagemap': {
100
+ const { ImagemapToken } = require('../imagemap');
101
+ // @ts-expect-error abstract class
102
+ innerToken = new ImagemapToken(inner, newConfig, accum);
103
+ break;
104
+ }
105
+ // 更多定制扩展的代码示例:
106
+ // ```
107
+ // case 'extensionName': {
108
+ // const {ExtensionToken}: typeof import('../extension') = require('../extension');
109
+ // innerToken = new ExtensionToken(inner, newConfig, accum);
110
+ // break;
111
+ // }
112
+ // ```
113
+ default: {
114
+ const { NowikiToken } = require('../nowiki/index');
115
+ // @ts-expect-error abstract class
116
+ innerToken = new NowikiToken(inner, newConfig);
117
+ }
118
+ }
119
+ innerToken.setAttribute('name', lcName);
120
+ innerToken.type = 'ext-inner';
121
+ super(name, attrToken, innerToken, closed, config, accum);
122
+ this.seal('closed', true);
123
+ }
124
+ /** @override */
125
+ lint(start = this.getAbsoluteIndex()) {
126
+ const errors = super.lint(start);
127
+ let rect;
128
+ if (this.name !== 'nowiki' && this.closest('html-attrs, table-attrs')) {
129
+ rect = { start, ...this.getRootNode().posFromIndex(start) };
130
+ errors.push((0, lint_1.generateForSelf)(this, rect, 'extension tag in HTML tag attributes'));
131
+ }
132
+ if (this.name === 'ref' && this.closest('heading-title')) {
133
+ rect ??= { start, ...this.getRootNode().posFromIndex(start) };
134
+ errors.push((0, lint_1.generateForSelf)(this, rect, 'variable anchor in a section header'));
135
+ }
136
+ return errors;
137
+ }
138
+ /* NOT FOR BROWSER */
139
+ /** @override */
140
+ cloneNode() {
141
+ const inner = this.lastChild.cloneNode(), tags = this.getAttribute('tags'), config = this.getAttribute('config'), attr = String(this.firstChild);
142
+ return debug_1.Shadow.run(() => {
143
+ // @ts-expect-error abstract class
144
+ const token = new ExtToken(tags[0], attr, '', this.selfClosing ? undefined : tags[1], config);
145
+ token.lastChild.safeReplaceWith(inner);
146
+ return token;
147
+ });
148
+ }
149
+ }
150
+ exports.ExtToken = ExtToken;
151
+ constants_1.classes['ExtToken'] = __filename;
@@ -0,0 +1,37 @@
1
+ import * as Parser from '../../index';
2
+ import { TagPairToken } from './index';
3
+ import type { LintError } from '../../base';
4
+ import type { AstText, Token } from '../../internal';
5
+ export declare abstract class IncludeToken extends TagPairToken {
6
+ readonly type = "include";
7
+ readonly childNodes: readonly [AstText, AstText];
8
+ abstract get children(): [];
9
+ abstract get firstChild(): AstText;
10
+ abstract get firstElementChild(): undefined;
11
+ abstract get lastChild(): AstText;
12
+ abstract get lastElementChild(): undefined;
13
+ /** @override */
14
+ get innerText(): string | undefined;
15
+ set innerText(text: string | undefined);
16
+ /**
17
+ * @param name 标签名
18
+ * @param attr 标签属性
19
+ * @param inner 内部wikitext
20
+ * @param closed 是否封闭
21
+ */
22
+ constructor(name: string, attr?: string, inner?: string, closed?: string, config?: Parser.Config, accum?: Token[]);
23
+ /** @override */
24
+ lint(start?: number): LintError[];
25
+ /** @override */
26
+ json(): object;
27
+ /** @override */
28
+ cloneNode(): this;
29
+ /**
30
+ * @override
31
+ * @param str 新文本
32
+ */
33
+ setText(str: string): string;
34
+ /** 清除标签属性 */
35
+ removeAttr(): void;
36
+ }
37
+ export {};
@@ -0,0 +1,71 @@
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 lint_1 = require("../../util/lint");
7
+ const hidden_1 = require("../../mixin/hidden");
8
+ const Parser = require("../../index");
9
+ const index_1 = require("./index");
10
+ /**
11
+ * `<includeonly>`或`<noinclude>`或`<onlyinclude>`
12
+ * @classdesc `{childNodes: [AstText, AstText]}`
13
+ */
14
+ class IncludeToken extends (0, hidden_1.hiddenToken)(index_1.TagPairToken) {
15
+ type = 'include';
16
+ /* NOT FOR BROWSER */
17
+ /** @override */
18
+ get innerText() {
19
+ return this.selfClosing ? undefined : this.lastChild.data;
20
+ }
21
+ set innerText(text) {
22
+ if (text === undefined) {
23
+ this.selfClosing = true;
24
+ }
25
+ else {
26
+ this.selfClosing = false;
27
+ this.setText(text);
28
+ }
29
+ }
30
+ /* NOT FOR BROWSER END */
31
+ /**
32
+ * @param name 标签名
33
+ * @param attr 标签属性
34
+ * @param inner 内部wikitext
35
+ * @param closed 是否封闭
36
+ */
37
+ constructor(name, attr = '', inner, closed, config = Parser.getConfig(), accum = []) {
38
+ super(name, attr, inner ?? '', inner === undefined ? closed : closed ?? '', config, accum);
39
+ }
40
+ /** @override */
41
+ lint(start = this.getAbsoluteIndex()) {
42
+ return this.closed ? [] : [(0, lint_1.generateForSelf)(this, { start }, Parser.msg('unclosed $1', `<${this.name}>`))];
43
+ }
44
+ /** @override */
45
+ json() {
46
+ return {
47
+ ...super.json(),
48
+ closed: this.closed,
49
+ };
50
+ }
51
+ /* NOT FOR BROWSER */
52
+ /** @override */
53
+ cloneNode() {
54
+ const tags = this.getAttribute('tags'), config = this.getAttribute('config'), { innerText } = this, closing = this.selfClosing || !this.closed ? undefined : tags[1];
55
+ // @ts-expect-error abstract class
56
+ return debug_1.Shadow.run(() => new IncludeToken(tags[0], this.firstChild.data, innerText, closing, config));
57
+ }
58
+ /**
59
+ * @override
60
+ * @param str 新文本
61
+ */
62
+ setText(str) {
63
+ return super.setText(str, 1);
64
+ }
65
+ /** 清除标签属性 */
66
+ removeAttr() {
67
+ super.setText('');
68
+ }
69
+ }
70
+ exports.IncludeToken = IncludeToken;
71
+ constants_1.classes['IncludeToken'] = __filename;
@@ -0,0 +1,27 @@
1
+ import * as Parser from '../../index';
2
+ import { Token } from '../index';
3
+ import type { AstNodes } from '../../lib/node';
4
+ export declare abstract class TagPairToken extends Token {
5
+ #private;
6
+ type: 'ext' | 'include';
7
+ readonly name: string;
8
+ closed: boolean;
9
+ selfClosing: boolean;
10
+ readonly childNodes: readonly [AstNodes, AstNodes];
11
+ abstract get firstChild(): AstNodes;
12
+ abstract get lastChild(): AstNodes;
13
+ /** 内部wikitext */
14
+ get innerText(): string | undefined;
15
+ /**
16
+ * @param name 标签名
17
+ * @param attr 标签属性
18
+ * @param inner 内部wikitext
19
+ * @param closed 是否封闭;约定`undefined`表示自封闭,`''`表示未闭合
20
+ */
21
+ constructor(name: string, attr: string | Token, inner: string | Token, closed?: string, config?: Parser.Config, accum?: Token[]);
22
+ /** @override */
23
+ text(): string;
24
+ /** @override */
25
+ print(): string;
26
+ }
27
+ export {};
@@ -0,0 +1,76 @@
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.fixedToken)(index_1.Token) {
10
+ #tags;
11
+ closed;
12
+ selfClosing;
13
+ /* NOT FOR BROWSER END */
14
+ /** 内部wikitext */
15
+ get innerText() {
16
+ return this.selfClosing ? undefined : this.lastChild.text();
17
+ }
18
+ /**
19
+ * @param name 标签名
20
+ * @param attr 标签属性
21
+ * @param inner 内部wikitext
22
+ * @param closed 是否封闭;约定`undefined`表示自封闭,`''`表示未闭合
23
+ */
24
+ constructor(name, attr, inner, closed, config = Parser.getConfig(), accum = []) {
25
+ super(undefined, config);
26
+ this.setAttribute('name', name.toLowerCase());
27
+ this.#tags = [name, closed || name];
28
+ this.closed = closed !== '';
29
+ this.selfClosing = closed === undefined;
30
+ this.append(attr, inner);
31
+ const index = typeof attr === 'string' ? -1 : accum.indexOf(attr);
32
+ accum.splice(index === -1 ? Infinity : index, 0, this);
33
+ Object.defineProperty(this, 'closed', { enumerable: false });
34
+ }
35
+ /** @private */
36
+ toString(omit) {
37
+ const { selfClosing, firstChild, lastChild, nextSibling, name, closed, } = this, [opening, closing] = this.#tags;
38
+ if (omit && this.matchesTypes(omit)) {
39
+ return '';
40
+ }
41
+ else if (!closed && nextSibling) {
42
+ Parser.error(`自动闭合 <${name}>`, lastChild);
43
+ this.closed = true;
44
+ }
45
+ return selfClosing
46
+ ? `<${opening}${firstChild.toString(omit)}/>`
47
+ : `<${opening}${firstChild.toString(omit)}>${lastChild.toString(omit)}${this.closed ? `</${closing}>` : ''}`;
48
+ }
49
+ /** @override */
50
+ text() {
51
+ const [opening, closing] = this.#tags;
52
+ return this.selfClosing
53
+ ? `<${opening}${this.firstChild.text()}/>`
54
+ : `<${opening}${super.text('>')}${this.closed ? `</${closing}>` : ''}`;
55
+ }
56
+ /** @private */
57
+ getAttribute(key) {
58
+ if (key === 'tags') {
59
+ return [...this.#tags];
60
+ }
61
+ return key === 'padding' ? this.#tags[0].length + 1 : super.getAttribute(key);
62
+ }
63
+ /** @private */
64
+ getGaps() {
65
+ return 1;
66
+ }
67
+ /** @override */
68
+ print() {
69
+ const [opening, closing] = this.#tags;
70
+ return super.print(this.selfClosing
71
+ ? { pre: `&lt;${opening}`, post: '/&gt;' }
72
+ : { pre: `&lt;${opening}`, sep: '&gt;', post: this.closed ? `&lt;/${closing}&gt;` : '' });
73
+ }
74
+ }
75
+ exports.TagPairToken = TagPairToken;
76
+ constants_1.classes['TagPairToken'] = __filename;
@@ -0,0 +1,167 @@
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 abstract class TranscludeToken extends Token {
12
+ #private;
13
+ type: 'template' | 'magic-word';
14
+ readonly name: string;
15
+ readonly modifier: string;
16
+ readonly childNodes: readonly [AtomToken | SyntaxToken, ...ParameterToken[]] | readonly [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(): ParameterToken[];
50
+ /** 获取所有匿名参数 */
51
+ getAnonArgs(): 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(): [string, ParameterToken[]][];
64
+ /**
65
+ * 对特定魔术字获取可能的取值
66
+ * @throws `Error` 不是可接受的魔术字
67
+ */
68
+ getPossibleValues(): 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(): string[];
102
+ /**
103
+ * 获取参数值
104
+ * @param key 参数名
105
+ */
106
+ getValues(key: string | number): 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): string[];
162
+ /**
163
+ * 转义模板内的表格
164
+ * @throws `Error` 转义失败
165
+ */
166
+ escapeTables(): TranscludeToken;
167
+ }