wikiparser-node 1.0.0-beta.4 → 1.0.1-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 (145) hide show
  1. package/README.md +10 -9
  2. package/bundle/bundle.min.js +37 -0
  3. package/config/llwiki.json +1 -35
  4. package/config/moegirl.json +1 -44
  5. package/config/zhwiki.json +1 -466
  6. package/extensions/dist/base.js +105 -0
  7. package/extensions/dist/editor.js +172 -0
  8. package/extensions/dist/highlight.js +46 -0
  9. package/extensions/dist/lint.js +43 -0
  10. package/extensions/editor.css +63 -0
  11. package/extensions/ui.css +119 -0
  12. package/package.json +29 -16
  13. package/config/.schema.json +0 -160
  14. package/dist/index.d.ts +0 -62
  15. package/dist/index.js +0 -305
  16. package/dist/internal.d.ts +0 -44
  17. package/dist/lib/element.d.ts +0 -190
  18. package/dist/lib/element.js +0 -674
  19. package/dist/lib/node.d.ts +0 -178
  20. package/dist/lib/node.js +0 -457
  21. package/dist/lib/range.d.ts +0 -132
  22. package/dist/lib/range.js +0 -384
  23. package/dist/lib/ranges.d.ts +0 -28
  24. package/dist/lib/ranges.js +0 -125
  25. package/dist/lib/text.d.ts +0 -78
  26. package/dist/lib/text.js +0 -227
  27. package/dist/lib/title.d.ts +0 -34
  28. package/dist/lib/title.js +0 -111
  29. package/dist/mixin/attributesParent.js +0 -93
  30. package/dist/mixin/fixed.js +0 -32
  31. package/dist/mixin/hidden.js +0 -23
  32. package/dist/mixin/singleLine.js +0 -26
  33. package/dist/mixin/sol.js +0 -44
  34. package/dist/parser/braces.js +0 -120
  35. package/dist/parser/commentAndExt.js +0 -64
  36. package/dist/parser/converter.js +0 -39
  37. package/dist/parser/externalLinks.js +0 -27
  38. package/dist/parser/hrAndDoubleUnderscore.js +0 -37
  39. package/dist/parser/html.js +0 -35
  40. package/dist/parser/links.js +0 -93
  41. package/dist/parser/list.js +0 -58
  42. package/dist/parser/magicLinks.js +0 -39
  43. package/dist/parser/quotes.js +0 -66
  44. package/dist/parser/selector.js +0 -162
  45. package/dist/parser/table.js +0 -108
  46. package/dist/src/arg.d.ts +0 -78
  47. package/dist/src/arg.js +0 -203
  48. package/dist/src/atom.d.ts +0 -12
  49. package/dist/src/atom.js +0 -24
  50. package/dist/src/attribute.d.ts +0 -107
  51. package/dist/src/attribute.js +0 -446
  52. package/dist/src/attributes.d.ts +0 -120
  53. package/dist/src/attributes.js +0 -360
  54. package/dist/src/converter.d.ts +0 -76
  55. package/dist/src/converter.js +0 -134
  56. package/dist/src/converterFlags.d.ts +0 -108
  57. package/dist/src/converterFlags.js +0 -237
  58. package/dist/src/converterRule.d.ts +0 -97
  59. package/dist/src/converterRule.js +0 -253
  60. package/dist/src/extLink.d.ts +0 -64
  61. package/dist/src/extLink.js +0 -156
  62. package/dist/src/gallery.d.ts +0 -72
  63. package/dist/src/gallery.js +0 -133
  64. package/dist/src/heading.d.ts +0 -84
  65. package/dist/src/heading.js +0 -134
  66. package/dist/src/hidden.d.ts +0 -20
  67. package/dist/src/hidden.js +0 -26
  68. package/dist/src/html.d.ts +0 -115
  69. package/dist/src/html.js +0 -247
  70. package/dist/src/imageParameter.d.ts +0 -83
  71. package/dist/src/imageParameter.js +0 -255
  72. package/dist/src/imagemap.d.ts +0 -79
  73. package/dist/src/imagemap.js +0 -164
  74. package/dist/src/imagemapLink.d.ts +0 -49
  75. package/dist/src/imagemapLink.js +0 -39
  76. package/dist/src/index.d.ts +0 -157
  77. package/dist/src/index.js +0 -818
  78. package/dist/src/link/base.d.ts +0 -70
  79. package/dist/src/link/base.js +0 -229
  80. package/dist/src/link/category.d.ts +0 -14
  81. package/dist/src/link/category.js +0 -29
  82. package/dist/src/link/file.d.ts +0 -106
  83. package/dist/src/link/file.js +0 -271
  84. package/dist/src/link/galleryImage.d.ts +0 -37
  85. package/dist/src/link/galleryImage.js +0 -101
  86. package/dist/src/link/index.d.ts +0 -50
  87. package/dist/src/link/index.js +0 -136
  88. package/dist/src/magicLink.d.ts +0 -47
  89. package/dist/src/magicLink.js +0 -130
  90. package/dist/src/nested.d.ts +0 -49
  91. package/dist/src/nested.js +0 -88
  92. package/dist/src/nowiki/base.d.ts +0 -39
  93. package/dist/src/nowiki/base.js +0 -31
  94. package/dist/src/nowiki/comment.d.ts +0 -43
  95. package/dist/src/nowiki/comment.js +0 -62
  96. package/dist/src/nowiki/dd.d.ts +0 -22
  97. package/dist/src/nowiki/dd.js +0 -47
  98. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -37
  99. package/dist/src/nowiki/doubleUnderscore.js +0 -48
  100. package/dist/src/nowiki/hr.d.ts +0 -24
  101. package/dist/src/nowiki/hr.js +0 -29
  102. package/dist/src/nowiki/index.d.ts +0 -20
  103. package/dist/src/nowiki/index.js +0 -24
  104. package/dist/src/nowiki/list.d.ts +0 -16
  105. package/dist/src/nowiki/list.js +0 -14
  106. package/dist/src/nowiki/noinclude.d.ts +0 -21
  107. package/dist/src/nowiki/noinclude.js +0 -25
  108. package/dist/src/nowiki/quote.d.ts +0 -20
  109. package/dist/src/nowiki/quote.js +0 -66
  110. package/dist/src/onlyinclude.d.ts +0 -39
  111. package/dist/src/onlyinclude.js +0 -66
  112. package/dist/src/paramTag/index.d.ts +0 -52
  113. package/dist/src/paramTag/index.js +0 -78
  114. package/dist/src/paramTag/inputbox.d.ts +0 -8
  115. package/dist/src/paramTag/inputbox.js +0 -22
  116. package/dist/src/parameter.d.ts +0 -96
  117. package/dist/src/parameter.js +0 -203
  118. package/dist/src/pre.d.ts +0 -29
  119. package/dist/src/pre.js +0 -49
  120. package/dist/src/syntax.d.ts +0 -23
  121. package/dist/src/syntax.js +0 -67
  122. package/dist/src/table/base.d.ts +0 -61
  123. package/dist/src/table/base.js +0 -78
  124. package/dist/src/table/index.d.ts +0 -248
  125. package/dist/src/table/index.js +0 -782
  126. package/dist/src/table/td.d.ts +0 -121
  127. package/dist/src/table/td.js +0 -267
  128. package/dist/src/table/tr.d.ts +0 -32
  129. package/dist/src/table/tr.js +0 -51
  130. package/dist/src/table/trBase.d.ts +0 -62
  131. package/dist/src/table/trBase.js +0 -157
  132. package/dist/src/tagPair/ext.d.ts +0 -55
  133. package/dist/src/tagPair/ext.js +0 -138
  134. package/dist/src/tagPair/include.d.ts +0 -43
  135. package/dist/src/tagPair/include.js +0 -42
  136. package/dist/src/tagPair/index.d.ts +0 -57
  137. package/dist/src/tagPair/index.js +0 -107
  138. package/dist/src/transclude.d.ts +0 -201
  139. package/dist/src/transclude.js +0 -727
  140. package/dist/util/debug.js +0 -42
  141. package/dist/util/diff.js +0 -71
  142. package/dist/util/lint.js +0 -48
  143. package/dist/util/string.js +0 -75
  144. package/errors/README +0 -1
  145. package/printed/README +0 -1
@@ -1,55 +0,0 @@
1
- import * as Parser from '../../index';
2
- import { Token } from '..';
3
- import { TagPairToken } from '.';
4
- import { AttributesToken } from '../attributes';
5
- import type { LintError } from '../../index';
6
- declare const ExtToken_base: (abstract new (...args: any[]) => {
7
- childNodes: Parser.AstNodes[];
8
- readonly "__#4@#attributesChild": Parser.AttributesToken;
9
- readonly attributes: Record<string, string | true>;
10
- className: string;
11
- readonly classList: Set<string>;
12
- id: string;
13
- hasAttr(key: string): boolean;
14
- getAttr(key: string): string | true | undefined;
15
- getAttrNames(): Set<string>;
16
- hasAttrs(): boolean;
17
- getAttrs(): Record<string, string | true>;
18
- setAttr(key: string, value: string | boolean): void;
19
- removeAttr(key: string): void;
20
- toggleAttr(key: string, force?: boolean | undefined): void;
21
- length: number;
22
- toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
23
- text(separator?: string | undefined): string;
24
- insertAt(token: unknown, i?: number | undefined): unknown;
25
- }) & typeof TagPairToken;
26
- /**
27
- * 扩展标签
28
- * @classdesc `{childNodes: [AttributesToken, Token]}`
29
- */
30
- export declare class ExtToken extends ExtToken_base {
31
- readonly type = "ext";
32
- childNodes: [AttributesToken, Token];
33
- abstract get children(): [AttributesToken, Token];
34
- abstract get firstChild(): AttributesToken;
35
- abstract get firstElementChild(): AttributesToken;
36
- abstract get lastChild(): Token;
37
- /** @override */
38
- get closed(): boolean;
39
- /**
40
- * @browser
41
- * @param name 标签名
42
- * @param attr 标签属性
43
- * @param inner 内部wikitext
44
- * @param closed 是否封闭
45
- */
46
- constructor(name: string, attr?: string, inner?: string, closed?: string, config?: Parser.Config, accum?: Token[]);
47
- /**
48
- * @override
49
- * @browser
50
- */
51
- lint(start?: number): LintError[];
52
- /** @override */
53
- cloneNode(): this;
54
- }
55
- export {};
@@ -1,138 +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 attributesParent_1 = require("../../mixin/attributesParent");
6
- const Parser = require("../../index");
7
- const __1 = require("..");
8
- const _1 = require(".");
9
- const attributes_1 = require("../attributes");
10
- /**
11
- * 从数组中删除指定元素
12
- * @param arr 数组
13
- * @param ele 元素
14
- */
15
- const del = (arr, ele) => {
16
- const set = new Set(arr);
17
- set.delete(ele);
18
- return [...set];
19
- };
20
- /**
21
- * 扩展标签
22
- * @classdesc `{childNodes: [AttributesToken, Token]}`
23
- */
24
- class ExtToken extends (0, attributesParent_1.attributesParent)(_1.TagPairToken) {
25
- type = 'ext';
26
- /** @override */
27
- // eslint-disable-next-line class-methods-use-this
28
- get closed() {
29
- return true;
30
- }
31
- /**
32
- * @browser
33
- * @param name 标签名
34
- * @param attr 标签属性
35
- * @param inner 内部wikitext
36
- * @param closed 是否封闭
37
- */
38
- constructor(name, attr, inner, closed, config = Parser.getConfig(), accum = []) {
39
- const lcName = name.toLowerCase(), 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 ?? []] };
40
- let innerToken;
41
- switch (lcName) {
42
- case 'tab':
43
- newConfig.ext = del(newConfig.ext, 'tabs');
44
- // fall through
45
- case 'indicator':
46
- case 'poem':
47
- case 'ref':
48
- case 'option':
49
- case 'combooption':
50
- case 'tabs':
51
- case 'poll':
52
- case 'seo':
53
- if (lcName === 'poem') {
54
- newConfig.excludes.push('heading');
55
- }
56
- innerToken = new __1.Token(inner, newConfig, true, accum);
57
- break;
58
- case 'pre': {
59
- const { PreToken } = require('../pre');
60
- innerToken = new PreToken(inner, newConfig, accum);
61
- break;
62
- }
63
- case 'dynamicpagelist': {
64
- const { ParamTagToken } = require('../paramTag');
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
- innerToken = new InputboxToken(inner, newConfig, accum);
72
- break;
73
- }
74
- case 'references': {
75
- const { NestedToken } = require('../nested');
76
- innerToken = new NestedToken(inner, /<!--.*?(?:-->|$)|<(ref)(\s[^>]*)?>(.*?)<\/(ref\s*)>/gisu, ['ref'], newConfig, accum);
77
- break;
78
- }
79
- case 'choose': {
80
- const { NestedToken } = require('../nested');
81
- innerToken = new NestedToken(inner, /<(option|choicetemplate)(\s[^>]*)?>(.*?)<\/(\1)>/gsu, ['option', 'choicetemplate'], newConfig, accum);
82
- break;
83
- }
84
- case 'combobox': {
85
- const { NestedToken } = require('../nested');
86
- innerToken = new NestedToken(inner, /<(combooption)(\s[^>]*)?>(.*?)<\/(combooption\s*)>/gisu, ['combooption'], newConfig, accum);
87
- break;
88
- }
89
- case 'gallery': {
90
- const { GalleryToken } = require('../gallery');
91
- innerToken = new GalleryToken(inner, newConfig, accum);
92
- break;
93
- }
94
- case 'imagemap': {
95
- const { ImagemapToken } = require('../imagemap');
96
- innerToken = new ImagemapToken(inner, newConfig, accum);
97
- break;
98
- }
99
- // 更多定制扩展的代码示例:
100
- // ```
101
- // case 'extensionName': {
102
- // const {ExtensionToken}: typeof import('../extension') = require('../extension');
103
- // innerToken = new ExtensionToken(inner, newConfig, accum);
104
- // break;
105
- // }
106
- // ```
107
- default: {
108
- const { NowikiToken } = require('../nowiki');
109
- innerToken = new NowikiToken(inner, newConfig);
110
- }
111
- }
112
- innerToken.setAttribute('name', lcName).type = 'ext-inner';
113
- super(name, attrToken, innerToken, closed, config, accum);
114
- }
115
- /**
116
- * @override
117
- * @browser
118
- */
119
- lint(start = this.getAbsoluteIndex()) {
120
- const errors = super.lint(start);
121
- if (this.name !== 'nowiki' && this.closest('html-attrs, table-attrs')) {
122
- const root = this.getRootNode(), excerpt = String(root).slice(Math.max(0, start - 25), start + 25), rect = { start, ...root.posFromIndex(start) };
123
- errors.push({ ...(0, lint_1.generateForSelf)(this, rect, 'extension tag in HTML tag attributes'), excerpt });
124
- }
125
- return errors;
126
- }
127
- /** @override */
128
- cloneNode() {
129
- const inner = this.lastChild.cloneNode(), tags = this.getAttribute('tags'), config = this.getAttribute('config'), attr = String(this.firstChild);
130
- return Parser.run(() => {
131
- const token = new ExtToken(tags[0], attr, '', this.selfClosing ? undefined : tags[1], config);
132
- token.lastChild.safeReplaceWith(inner);
133
- return token;
134
- });
135
- }
136
- }
137
- exports.ExtToken = ExtToken;
138
- Parser.classes['ExtToken'] = __filename;
@@ -1,43 +0,0 @@
1
- import * as Parser from '../../index';
2
- import { TagPairToken } from '.';
3
- import type { AstText, Token } from '../../internal';
4
- declare const IncludeToken_base: ((abstract new (...args: any[]) => {
5
- text(): string;
6
- length: number;
7
- toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
8
- insertAt(token: unknown, i?: number | undefined): unknown;
9
- }) & {
10
- readonly hidden: true; /** @browser */
11
- }) & typeof TagPairToken;
12
- /**
13
- * `<includeonly>`或`<noinclude>`或`<onlyinclude>`
14
- * @classdesc `{childNodes: [AstText, AstText]}`
15
- */
16
- export declare class IncludeToken extends IncludeToken_base {
17
- /** @browser */
18
- readonly type = "include";
19
- childNodes: [AstText, AstText];
20
- abstract get children(): [];
21
- abstract get firstChild(): AstText;
22
- abstract get firstElementChild(): undefined;
23
- abstract get lastChild(): AstText;
24
- abstract get lastElementChild(): undefined;
25
- /**
26
- * @browser
27
- * @param name 标签名
28
- * @param attr 标签属性
29
- * @param inner 内部wikitext
30
- * @param closed 是否封闭
31
- */
32
- constructor(name: string, attr?: string, inner?: string, closed?: string, config?: Parser.Config, accum?: Token[]);
33
- /** @override */
34
- cloneNode(): this;
35
- /**
36
- * @override
37
- * @param str 新文本
38
- */
39
- setText(str: string): string;
40
- /** 清除标签属性 */
41
- removeAttr(): void;
42
- }
43
- export {};
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IncludeToken = void 0;
4
- const hidden_1 = require("../../mixin/hidden");
5
- const Parser = require("../../index");
6
- const _1 = require(".");
7
- /**
8
- * `<includeonly>`或`<noinclude>`或`<onlyinclude>`
9
- * @classdesc `{childNodes: [AstText, AstText]}`
10
- */
11
- class IncludeToken extends (0, hidden_1.hidden)(_1.TagPairToken) {
12
- /** @browser */
13
- type = 'include';
14
- /**
15
- * @browser
16
- * @param name 标签名
17
- * @param attr 标签属性
18
- * @param inner 内部wikitext
19
- * @param closed 是否封闭
20
- */
21
- constructor(name, attr = '', inner, closed, config = Parser.getConfig(), accum = []) {
22
- super(name, attr, inner ?? '', inner === undefined ? closed : closed ?? '', config, accum);
23
- }
24
- /** @override */
25
- cloneNode() {
26
- const tags = this.getAttribute('tags'), config = this.getAttribute('config'), inner = this.selfClosing ? undefined : this.lastChild.data, closing = this.selfClosing || !this.closed ? undefined : tags[1];
27
- return Parser.run(() => new IncludeToken(tags[0], this.firstChild.data, inner, closing, config));
28
- }
29
- /**
30
- * @override
31
- * @param str 新文本
32
- */
33
- setText(str) {
34
- return super.setText(str, 1);
35
- }
36
- /** 清除标签属性 */
37
- removeAttr() {
38
- super.setText('');
39
- }
40
- }
41
- exports.IncludeToken = IncludeToken;
42
- Parser.classes['IncludeToken'] = __filename;
@@ -1,57 +0,0 @@
1
- import * as Parser from '../../index';
2
- import { Token } from '..';
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
- length: number;
9
- toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
10
- text(separator?: string | undefined): string;
11
- }) & {
12
- readonly fixed: true;
13
- }) & typeof Parser.Token;
14
- /** 成对标签 */
15
- export declare abstract class TagPairToken extends TagPairToken_base {
16
- #private;
17
- type: 'ext' | 'include';
18
- name: string;
19
- childNodes: [AstNodes, AstNodes];
20
- abstract get firstChild(): AstNodes;
21
- abstract get lastChild(): AstNodes;
22
- /**
23
- * 是否闭合
24
- * @browser
25
- */
26
- get closed(): boolean;
27
- set closed(value: boolean);
28
- /** 是否自封闭 */
29
- get selfClosing(): boolean;
30
- set selfClosing(value: boolean);
31
- /** 内部wikitext */
32
- get innerText(): string | undefined;
33
- /**
34
- * @browser
35
- * @param name 标签名
36
- * @param attr 标签属性
37
- * @param inner 内部wikitext
38
- * @param closed 是否封闭;约定`undefined`表示自封闭,`''`表示未闭合
39
- */
40
- constructor(name: string, attr: string | Token, inner: string | Token, closed?: string, config?: Parser.Config, accum?: Token[]);
41
- /**
42
- * @override
43
- * @browser
44
- */
45
- toString(omit?: Set<string>): string;
46
- /**
47
- * @override
48
- * @browser
49
- */
50
- text(): string;
51
- /**
52
- * @override
53
- * @browser
54
- */
55
- print(): string;
56
- }
57
- export {};
@@ -1,107 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TagPairToken = void 0;
4
- const fixed_1 = require("../../mixin/fixed");
5
- const Parser = require("../../index");
6
- const __1 = require("..");
7
- /** 成对标签 */
8
- class TagPairToken extends (0, fixed_1.fixed)(__1.Token) {
9
- /** @browser */
10
- #selfClosing;
11
- /** @browser */
12
- #closed;
13
- /** @browser */
14
- #tags;
15
- /**
16
- * 是否闭合
17
- * @browser
18
- */
19
- get closed() {
20
- return this.#closed;
21
- }
22
- set closed(value) {
23
- this.#closed ||= value;
24
- }
25
- /** 是否自封闭 */
26
- get selfClosing() {
27
- return this.#selfClosing;
28
- }
29
- set selfClosing(value) {
30
- if (value !== this.#selfClosing && this.lastChild.text()) {
31
- Parser.warn(`<${this.name}>标签内部的${value ? '文本将被隐藏' : '原有文本将再次可见'}!`);
32
- }
33
- this.#selfClosing = value;
34
- }
35
- /** 内部wikitext */
36
- get innerText() {
37
- return this.#selfClosing ? undefined : this.lastChild.text();
38
- }
39
- /**
40
- * @browser
41
- * @param name 标签名
42
- * @param attr 标签属性
43
- * @param inner 内部wikitext
44
- * @param closed 是否封闭;约定`undefined`表示自封闭,`''`表示未闭合
45
- */
46
- constructor(name, attr, inner, closed, config = Parser.getConfig(), accum = []) {
47
- super(undefined, config, true);
48
- this.setAttribute('name', name.toLowerCase());
49
- this.#tags = [name, closed || name];
50
- this.#selfClosing = closed === undefined;
51
- this.#closed = closed !== '';
52
- this.append(attr, inner);
53
- const index = typeof attr === 'string' ? -1 : accum.indexOf(attr);
54
- accum.splice(index === -1 ? Infinity : index, 0, this);
55
- }
56
- /**
57
- * @override
58
- * @browser
59
- */
60
- toString(omit) {
61
- const { firstChild, lastChild, nextSibling, name, closed } = this, [opening, closing] = this.#tags;
62
- if (omit && this.matchesTypes(omit)) {
63
- return '';
64
- }
65
- else if (!closed && nextSibling) {
66
- Parser.error(`自动闭合 <${name}>`, lastChild);
67
- this.#closed = true;
68
- }
69
- return this.#selfClosing
70
- ? `<${opening}${firstChild.toString(omit)}/>`
71
- : `<${opening}${firstChild.toString(omit)}>${lastChild.toString(omit)}${this.closed ? `</${closing}>` : ''}`;
72
- }
73
- /**
74
- * @override
75
- * @browser
76
- */
77
- text() {
78
- const [opening, closing] = this.#tags;
79
- return this.#selfClosing
80
- ? `<${opening}${this.firstChild.text()}/>`
81
- : `<${opening}${super.text('>')}${this.closed ? `</${closing}>` : ''}`;
82
- }
83
- /** @private */
84
- getPadding() {
85
- return this.#tags[0].length + 1;
86
- }
87
- /** @private */
88
- getGaps(i) {
89
- return i === 0 ? 1 : 1;
90
- }
91
- /**
92
- * @override
93
- * @browser
94
- */
95
- print() {
96
- const [opening, closing] = this.#tags;
97
- return super.print(this.#selfClosing
98
- ? { pre: `&lt;${opening}`, post: '/&gt;' }
99
- : { pre: `&lt;${opening}`, sep: '&gt;', post: this.closed ? `&lt;/${closing}&gt;` : '' });
100
- }
101
- /** @private */
102
- getAttribute(key) {
103
- return key === 'tags' ? [...this.#tags] : super.getAttribute(key);
104
- }
105
- }
106
- exports.TagPairToken = TagPairToken;
107
- Parser.classes['TagPairToken'] = __filename;
@@ -1,201 +0,0 @@
1
- import * as Parser from '../index';
2
- import { Token } from '.';
3
- import { ParameterToken } from './parameter';
4
- import { AtomToken } from './atom';
5
- import { SyntaxToken } from './syntax';
6
- import type { LintError } from '../index';
7
- /**
8
- * 模板或魔术字
9
- * @classdesc `{childNodes: [AtomToken|SyntaxToken, ...AtomToken, ...ParameterToken]}`
10
- */
11
- export declare class TranscludeToken extends Token {
12
- #private;
13
- /** @browser */
14
- type: 'template' | 'magic-word';
15
- name: string;
16
- /** @browser */
17
- modifier: string;
18
- childNodes: [AtomToken | SyntaxToken, ...Token[]];
19
- abstract get firstChild(): AtomToken | SyntaxToken;
20
- abstract get firstElementChild(): AtomToken | SyntaxToken;
21
- abstract get lastChild(): AtomToken | SyntaxToken | ParameterToken;
22
- abstract get lastElementChild(): AtomToken | SyntaxToken | ParameterToken;
23
- /** 是否存在重复参数 */
24
- get duplication(): boolean;
25
- /**
26
- * @browser
27
- * @param title 模板标题或魔术字
28
- * @param parts 参数各部分
29
- * @throws `SyntaxError` 非法的模板名称
30
- */
31
- constructor(title: string, parts: ([string] | [string | number, string])[], config?: Parser.Config, accum?: Token[]);
32
- /**
33
- * 设置引用修饰符
34
- * @browser
35
- * @param modifier 引用修饰符
36
- */
37
- setModifier(modifier: string): boolean;
38
- /**
39
- * 是否是模板
40
- * @browser
41
- */
42
- isTemplate(): boolean;
43
- /**
44
- * @override
45
- * @browser
46
- */
47
- toString(omit?: Set<string>): string;
48
- /**
49
- * @override
50
- * @browser
51
- */
52
- text(): string;
53
- /**
54
- * @override
55
- * @browser
56
- */
57
- lint(start?: number): LintError[];
58
- /**
59
- * @override
60
- * @browser
61
- * @param token 待插入的子节点
62
- * @param i 插入位置
63
- */
64
- insertAt<T extends ParameterToken>(token: T, i?: number): T;
65
- /**
66
- * 获取所有参数
67
- * @browser
68
- */
69
- getAllArgs(): ParameterToken[];
70
- /**
71
- * 获取匿名参数
72
- * @browser
73
- */
74
- getAnonArgs(): ParameterToken[];
75
- /**
76
- * 获取指定参数
77
- * @browser
78
- * @param key 参数名
79
- * @param exact 是否匹配匿名性
80
- * @param copy 是否返回一个备份
81
- */
82
- getArgs(key: string | number, exact?: boolean, copy?: boolean): Set<ParameterToken>;
83
- /**
84
- * 获取重名参数
85
- * @browser
86
- * @throws `Error` 仅用于模板
87
- */
88
- getDuplicatedArgs(): [string, ParameterToken[]][];
89
- /**
90
- * 对特定魔术字获取可能的取值
91
- * @browser
92
- * @throws `Error` 不是可接受的魔术字
93
- */
94
- getPossibleValues(): Token[];
95
- /**
96
- * @override
97
- * @browser
98
- */
99
- print(): string;
100
- /** @override */
101
- cloneNode(): this;
102
- /** 替换引用 */
103
- subst(): void;
104
- /** 安全的替换引用 */
105
- safesubst(): void;
106
- /**
107
- * @override
108
- * @param i 移除位置
109
- */
110
- removeAt(i: number): ParameterToken;
111
- /**
112
- * 是否具有某参数
113
- * @param key 参数名
114
- * @param exact 是否匹配匿名性
115
- */
116
- hasArg(key: string | number, exact?: boolean): boolean;
117
- /**
118
- * 获取生效的指定参数
119
- * @param key 参数名
120
- * @param exact 是否匹配匿名性
121
- */
122
- getArg(key: string | number, exact?: boolean): ParameterToken | undefined;
123
- /**
124
- * 移除指定参数
125
- * @param key 参数名
126
- * @param exact 是否匹配匿名性
127
- */
128
- removeArg(key: string | number, exact?: boolean): void;
129
- /** 获取所有参数名 */
130
- getKeys(): string[];
131
- /**
132
- * 获取参数值
133
- * @param key 参数名
134
- */
135
- getValues(key: string | number): string[];
136
- /** 获取所有生效的参数值 */
137
- getValue(): Record<string, string>;
138
- /**
139
- * 获取生效的指定参数值
140
- * @param key 参数名
141
- */
142
- getValue(key: string | number): string | undefined;
143
- /**
144
- * 插入匿名参数
145
- * @param val 参数值
146
- * @throws `SyntaxError` 非法的匿名参数
147
- */
148
- newAnonArg(val: string): ParameterToken;
149
- /**
150
- * 设置参数值
151
- * @param key 参数名
152
- * @param value 参数值
153
- * @throws `Error` 仅用于模板
154
- * @throws `SyntaxError` 非法的命名参数
155
- */
156
- setValue(key: string, value: string): void;
157
- /**
158
- * 将匿名参数改写为命名参数
159
- * @throws `Error` 仅用于模板
160
- */
161
- anonToNamed(): void;
162
- /**
163
- * 替换模板名
164
- * @param title 模板名
165
- * @throws `Error` 仅用于模板
166
- * @throws `SyntaxError` 非法的模板名称
167
- */
168
- replaceTemplate(title: string): void;
169
- /**
170
- * 替换模块名
171
- * @param title 模块名
172
- * @throws `Error` 仅用于模块
173
- * @throws `SyntaxError` 非法的模块名称
174
- */
175
- replaceModule(title: string): void;
176
- /**
177
- * 替换模块函数
178
- * @param func 模块函数名
179
- * @throws `Error` 仅用于模块
180
- * @throws `Error` 尚未指定模块名称
181
- * @throws `SyntaxError` 非法的模块函数名
182
- */
183
- replaceFunction(func: string): void;
184
- /**
185
- * 是否存在重名参数
186
- * @throws `Error` 仅用于模板
187
- */
188
- hasDuplicatedArgs(): number;
189
- /**
190
- * 修复重名参数:
191
- * `aggressive = false`时只移除空参数和全同参数,优先保留匿名参数,否则将所有匿名参数更改为命名。
192
- * `aggressive = true`时还会尝试处理连续的以数字编号的参数。
193
- * @param aggressive 是否使用有更大风险的修复手段
194
- */
195
- fixDuplication(aggressive?: boolean): string[];
196
- /**
197
- * 转义模板内的表格
198
- * @throws `Error` 转义失败
199
- */
200
- escapeTables(): TranscludeToken;
201
- }