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