wikiparser-node 1.3.9 → 1.4.0-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 (155) 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 +64 -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 +114 -0
  11. package/i18n/zh-hans.json +1 -0
  12. package/i18n/zh-hant.json +1 -0
  13. package/package.json +30 -13
  14. package/config/.schema.json +0 -172
  15. package/dist/addon/table.d.ts +0 -6
  16. package/dist/addon/table.js +0 -558
  17. package/dist/base.d.ts +0 -51
  18. package/dist/index.d.ts +0 -32
  19. package/dist/index.js +0 -211
  20. package/dist/internal.d.ts +0 -44
  21. package/dist/lib/element.d.ts +0 -154
  22. package/dist/lib/element.js +0 -630
  23. package/dist/lib/node.d.ts +0 -146
  24. package/dist/lib/node.js +0 -419
  25. package/dist/lib/range.d.ts +0 -104
  26. package/dist/lib/range.js +0 -385
  27. package/dist/lib/ranges.d.ts +0 -26
  28. package/dist/lib/ranges.js +0 -118
  29. package/dist/lib/text.d.ts +0 -62
  30. package/dist/lib/text.js +0 -255
  31. package/dist/lib/title.d.ts +0 -38
  32. package/dist/lib/title.js +0 -163
  33. package/dist/mixin/attributesParent.js +0 -89
  34. package/dist/mixin/fixed.js +0 -25
  35. package/dist/mixin/flagsParent.js +0 -70
  36. package/dist/mixin/hidden.js +0 -25
  37. package/dist/mixin/magicLinkParent.js +0 -41
  38. package/dist/mixin/singleLine.js +0 -25
  39. package/dist/mixin/sol.js +0 -43
  40. package/dist/mixin/syntax.js +0 -54
  41. package/dist/parser/braces.js +0 -128
  42. package/dist/parser/commentAndExt.js +0 -85
  43. package/dist/parser/converter.js +0 -40
  44. package/dist/parser/externalLinks.js +0 -31
  45. package/dist/parser/hrAndDoubleUnderscore.js +0 -38
  46. package/dist/parser/html.js +0 -36
  47. package/dist/parser/links.js +0 -94
  48. package/dist/parser/list.js +0 -66
  49. package/dist/parser/magicLinks.js +0 -42
  50. package/dist/parser/quotes.js +0 -67
  51. package/dist/parser/selector.js +0 -162
  52. package/dist/parser/table.js +0 -120
  53. package/dist/src/arg.d.ts +0 -58
  54. package/dist/src/arg.js +0 -194
  55. package/dist/src/atom.d.ts +0 -12
  56. package/dist/src/atom.js +0 -27
  57. package/dist/src/attribute.d.ts +0 -88
  58. package/dist/src/attribute.js +0 -422
  59. package/dist/src/attributes.d.ts +0 -109
  60. package/dist/src/attributes.js +0 -343
  61. package/dist/src/converter.d.ts +0 -53
  62. package/dist/src/converter.js +0 -79
  63. package/dist/src/converterFlags.d.ts +0 -87
  64. package/dist/src/converterFlags.js +0 -224
  65. package/dist/src/converterRule.d.ts +0 -77
  66. package/dist/src/converterRule.js +0 -208
  67. package/dist/src/extLink.d.ts +0 -55
  68. package/dist/src/extLink.js +0 -122
  69. package/dist/src/gallery.d.ts +0 -54
  70. package/dist/src/gallery.js +0 -121
  71. package/dist/src/heading.d.ts +0 -78
  72. package/dist/src/heading.js +0 -143
  73. package/dist/src/hidden.d.ts +0 -23
  74. package/dist/src/hidden.js +0 -23
  75. package/dist/src/html.d.ts +0 -106
  76. package/dist/src/html.js +0 -268
  77. package/dist/src/imageParameter.d.ts +0 -65
  78. package/dist/src/imageParameter.js +0 -247
  79. package/dist/src/imagemap.d.ts +0 -56
  80. package/dist/src/imagemap.js +0 -147
  81. package/dist/src/imagemapLink.d.ts +0 -61
  82. package/dist/src/imagemapLink.js +0 -40
  83. package/dist/src/index.d.ts +0 -140
  84. package/dist/src/index.js +0 -769
  85. package/dist/src/link/base.d.ts +0 -52
  86. package/dist/src/link/base.js +0 -213
  87. package/dist/src/link/category.d.ts +0 -13
  88. package/dist/src/link/category.js +0 -29
  89. package/dist/src/link/file.d.ts +0 -96
  90. package/dist/src/link/file.js +0 -256
  91. package/dist/src/link/galleryImage.d.ts +0 -45
  92. package/dist/src/link/galleryImage.js +0 -106
  93. package/dist/src/link/index.d.ts +0 -53
  94. package/dist/src/link/index.js +0 -124
  95. package/dist/src/magicLink.d.ts +0 -69
  96. package/dist/src/magicLink.js +0 -147
  97. package/dist/src/nested.d.ts +0 -43
  98. package/dist/src/nested.js +0 -86
  99. package/dist/src/nowiki/base.d.ts +0 -48
  100. package/dist/src/nowiki/base.js +0 -42
  101. package/dist/src/nowiki/comment.d.ts +0 -43
  102. package/dist/src/nowiki/comment.js +0 -74
  103. package/dist/src/nowiki/dd.d.ts +0 -8
  104. package/dist/src/nowiki/dd.js +0 -25
  105. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -47
  106. package/dist/src/nowiki/doubleUnderscore.js +0 -50
  107. package/dist/src/nowiki/hr.d.ts +0 -33
  108. package/dist/src/nowiki/hr.js +0 -14
  109. package/dist/src/nowiki/index.d.ts +0 -16
  110. package/dist/src/nowiki/index.js +0 -21
  111. package/dist/src/nowiki/list.d.ts +0 -31
  112. package/dist/src/nowiki/list.js +0 -48
  113. package/dist/src/nowiki/listBase.d.ts +0 -20
  114. package/dist/src/nowiki/listBase.js +0 -12
  115. package/dist/src/nowiki/noinclude.d.ts +0 -26
  116. package/dist/src/nowiki/noinclude.js +0 -24
  117. package/dist/src/nowiki/quote.d.ts +0 -30
  118. package/dist/src/nowiki/quote.js +0 -61
  119. package/dist/src/onlyinclude.d.ts +0 -16
  120. package/dist/src/onlyinclude.js +0 -57
  121. package/dist/src/paramTag/index.d.ts +0 -37
  122. package/dist/src/paramTag/index.js +0 -68
  123. package/dist/src/paramTag/inputbox.d.ts +0 -8
  124. package/dist/src/paramTag/inputbox.js +0 -23
  125. package/dist/src/parameter.d.ts +0 -88
  126. package/dist/src/parameter.js +0 -214
  127. package/dist/src/pre.d.ts +0 -28
  128. package/dist/src/pre.js +0 -51
  129. package/dist/src/syntax.d.ts +0 -30
  130. package/dist/src/syntax.js +0 -34
  131. package/dist/src/table/base.d.ts +0 -59
  132. package/dist/src/table/base.js +0 -78
  133. package/dist/src/table/index.d.ts +0 -230
  134. package/dist/src/table/index.js +0 -386
  135. package/dist/src/table/td.d.ts +0 -109
  136. package/dist/src/table/td.js +0 -270
  137. package/dist/src/table/tr.d.ts +0 -32
  138. package/dist/src/table/tr.js +0 -56
  139. package/dist/src/table/trBase.d.ts +0 -53
  140. package/dist/src/table/trBase.js +0 -153
  141. package/dist/src/tagPair/ext.d.ts +0 -57
  142. package/dist/src/tagPair/ext.js +0 -134
  143. package/dist/src/tagPair/include.d.ts +0 -56
  144. package/dist/src/tagPair/include.js +0 -70
  145. package/dist/src/tagPair/index.d.ts +0 -45
  146. package/dist/src/tagPair/index.js +0 -76
  147. package/dist/src/transclude.d.ts +0 -167
  148. package/dist/src/transclude.js +0 -694
  149. package/dist/util/constants.js +0 -113
  150. package/dist/util/debug.js +0 -83
  151. package/dist/util/diff.js +0 -72
  152. package/dist/util/lint.js +0 -30
  153. package/dist/util/string.js +0 -51
  154. package/errors/README +0 -1
  155. package/printed/README +0 -1
@@ -1,54 +0,0 @@
1
- import * as Parser from '../index';
2
- import { Token } from './index';
3
- import { GalleryImageToken } from './link/galleryImage';
4
- import { NoincludeToken } from './nowiki/noinclude';
5
- import type { LintError } from '../base';
6
- import type { AstNodes, AstText, AttributesToken, ExtToken } from '../internal';
7
- /**
8
- * gallery标签
9
- * @classdesc `{childNodes: ...(GalleryImageToken|NoincludeToken|AstText)}`
10
- */
11
- export declare class GalleryToken extends Token {
12
- #private;
13
- readonly type = "ext-inner";
14
- readonly name: 'gallery';
15
- readonly childNodes: (GalleryImageToken | NoincludeToken | AstText)[];
16
- abstract get children(): (GalleryImageToken | NoincludeToken)[];
17
- abstract get firstChild(): GalleryImageToken | NoincludeToken | AstText | undefined;
18
- abstract get firstElementChild(): GalleryImageToken | NoincludeToken | undefined;
19
- abstract get lastChild(): GalleryImageToken | NoincludeToken | AstText | undefined;
20
- abstract get lastElementChild(): GalleryImageToken | NoincludeToken | undefined;
21
- abstract get nextSibling(): undefined;
22
- abstract get nextElementSibling(): undefined;
23
- abstract get previousSibling(): AttributesToken;
24
- abstract get previousElementSibling(): AttributesToken;
25
- abstract get parentNode(): ExtToken | undefined;
26
- abstract get parentElement(): ExtToken | undefined;
27
- /** 所有图片 */
28
- get images(): readonly GalleryImageToken[];
29
- /** @param inner 标签内部wikitext */
30
- constructor(inner?: string, config?: Parser.Config, accum?: Token[]);
31
- /** @override */
32
- text(): string;
33
- /** @override */
34
- lint(start?: number): LintError[];
35
- /** @override */
36
- print(): string;
37
- /** @override */
38
- cloneNode(): this;
39
- /**
40
- * 插入图片
41
- * @param file 图片文件名
42
- * @param i 插入位置
43
- * @throws `SyntaxError` 非法的文件名
44
- */
45
- insertImage(file: string, i?: number): GalleryImageToken;
46
- /**
47
- * @override
48
- * @param token 待插入的节点
49
- * @param i 插入位置
50
- * @throws `RangeError` 插入不可见内容
51
- */
52
- insertAt(token: string, i?: number): AstText;
53
- insertAt<T extends AstNodes>(token: T, i?: number): T;
54
- }
@@ -1,121 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GalleryToken = void 0;
4
- const debug_1 = require("../util/debug");
5
- const constants_1 = require("../util/constants");
6
- const Parser = require("../index");
7
- const index_1 = require("./index");
8
- const galleryImage_1 = require("./link/galleryImage");
9
- const noinclude_1 = require("./nowiki/noinclude");
10
- /**
11
- * gallery标签
12
- * @classdesc `{childNodes: ...(GalleryImageToken|NoincludeToken|AstText)}`
13
- */
14
- class GalleryToken extends index_1.Token {
15
- type = 'ext-inner';
16
- /* NOT FOR BROWSER */
17
- /** 所有图片 */
18
- get images() {
19
- return this.childNodes.filter((0, debug_1.isToken)('gallery-image'));
20
- }
21
- /* NOT FOR BROWSER END */
22
- /** @param inner 标签内部wikitext */
23
- constructor(inner, config = Parser.getConfig(), accum = []) {
24
- super(undefined, config, accum, {
25
- AstText: ':', GalleryImageToken: ':', NoincludeToken: ':',
26
- });
27
- for (const line of inner?.split('\n') ?? []) {
28
- const matches = /^([^|]+)(?:\|(.*))?/u.exec(line);
29
- if (!matches) {
30
- super.insertAt((line.trim() ? new noinclude_1.NoincludeToken(line, config) : line));
31
- continue;
32
- }
33
- const [, file, alt] = matches;
34
- if (this.#checkFile(file)) {
35
- super.insertAt(new galleryImage_1.GalleryImageToken('gallery', file, alt, config, accum));
36
- }
37
- else {
38
- super.insertAt(new noinclude_1.NoincludeToken(line, config));
39
- }
40
- }
41
- }
42
- /**
43
- * 检查文件名是否有效
44
- * @param file 文件名
45
- */
46
- #checkFile(file) {
47
- return this.normalizeTitle(file, 6, true, true).valid;
48
- }
49
- /** @private */
50
- toString(omit) {
51
- return super.toString(omit, '\n');
52
- }
53
- /** @override */
54
- text() {
55
- return super.text('\n').replace(/\n\s*\n/gu, '\n');
56
- }
57
- /** @private */
58
- getGaps() {
59
- return 1;
60
- }
61
- /** @override */
62
- lint(start = this.getAbsoluteIndex()) {
63
- const { top, left } = this.getRootNode().posFromIndex(start), errors = [];
64
- for (let i = 0; i < this.length; i++) {
65
- const child = this.childNodes[i], str = String(child), { length } = str, trimmed = str.trim(), startLine = top + i, startCol = i ? 0 : left;
66
- if (child.type === 'noinclude' && trimmed && !/^<!--.*-->$/u.test(trimmed)) {
67
- errors.push({
68
- message: Parser.msg('invalid content in <$1>', 'gallery'),
69
- severity: 'error',
70
- startIndex: start,
71
- endIndex: start + length,
72
- startLine,
73
- endLine: startLine,
74
- startCol,
75
- endCol: startCol + length,
76
- });
77
- }
78
- else if (child.type !== 'noinclude' && child.type !== 'text') {
79
- errors.push(...child.lint(start));
80
- }
81
- start += length + 1;
82
- }
83
- return errors;
84
- }
85
- /** @override */
86
- print() {
87
- return super.print({ sep: '\n' });
88
- }
89
- /* NOT FOR BROWSER */
90
- /** @override */
91
- cloneNode() {
92
- const cloned = this.cloneChildNodes();
93
- return debug_1.Shadow.run(() => {
94
- const token = new GalleryToken(undefined, this.getAttribute('config'));
95
- token.append(...cloned);
96
- return token;
97
- });
98
- }
99
- /**
100
- * 插入图片
101
- * @param file 图片文件名
102
- * @param i 插入位置
103
- * @throws `SyntaxError` 非法的文件名
104
- */
105
- insertImage(file, i) {
106
- if (this.#checkFile(file)) {
107
- const token = debug_1.Shadow.run(() => new galleryImage_1.GalleryImageToken('gallery', file, undefined, this.getAttribute('config')));
108
- token.afterBuild();
109
- return this.insertAt(token, i);
110
- }
111
- throw new SyntaxError(`非法的文件名:${file}`);
112
- }
113
- insertAt(token, i = this.length) {
114
- if (typeof token === 'string' && token.trim() || token instanceof noinclude_1.NoincludeToken) {
115
- throw new RangeError('请勿向图库中插入不可见内容!');
116
- }
117
- return super.insertAt(token, i);
118
- }
119
- }
120
- exports.GalleryToken = GalleryToken;
121
- constants_1.classes['GalleryToken'] = __filename;
@@ -1,78 +0,0 @@
1
- import * as Parser from '../index';
2
- import { Token } from './index';
3
- import { SyntaxToken } from './syntax';
4
- import type { LintError } from '../base';
5
- declare const HeadingToken_base: (abstract new (...args: any[]) => {
6
- prependNewLine(): string;
7
- toString(omit?: Set<string> | undefined): string;
8
- getAttribute<S extends string>(key: S): TokenAttributeGetter<S>; /** 标题格式的等号 */
9
- text(): string;
10
- readonly length: number;
11
- lint(start?: number | undefined): Parser.LintError[];
12
- insertAt(token: unknown, i?: number | undefined): unknown;
13
- afterBuild(): void;
14
- setAttribute<T extends string>(key: T, value: TokenAttributeSetter<T>): void;
15
- addEventListener(events: string | string[], listener: AstListener): void;
16
- replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
17
- constructorError(msg: string): never;
18
- }) & ((abstract new (...args: any[]) => {
19
- removeAt(): never;
20
- insertAt(token: string, i?: number | undefined): Parser.AstText;
21
- insertAt<T_1 extends Parser.AstNodes>(token: T_1, i?: number | undefined): T_1;
22
- readonly length: number;
23
- toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
24
- text(separator?: string | undefined): string;
25
- lint(start?: number | undefined): Parser.LintError[];
26
- afterBuild(): void;
27
- getAttribute<T_2 extends string>(key: T_2): TokenAttributeGetter<T_2>;
28
- setAttribute<T extends string>(key: T, value: TokenAttributeSetter<T>): void;
29
- addEventListener(events: string | string[], listener: AstListener): void;
30
- replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
31
- constructorError(msg: string): never;
32
- }) & {
33
- readonly fixed: true;
34
- }) & typeof Parser.Token;
35
- /**
36
- * 章节标题
37
- * @classdesc `{childNodes: [Token, SyntaxToken]}`
38
- */
39
- export declare class HeadingToken extends HeadingToken_base {
40
- #private;
41
- readonly type = "heading";
42
- readonly childNodes: [Token, SyntaxToken];
43
- abstract get children(): [Token, SyntaxToken];
44
- abstract get firstChild(): Token;
45
- abstract get firstElementChild(): Token;
46
- abstract get lastChild(): SyntaxToken;
47
- abstract get lastElementChild(): SyntaxToken;
48
- /** 标题层级 */
49
- get level(): number;
50
- set level(n: number);
51
- /** 内部wikitext */
52
- get innerText(): string;
53
- /** @throws `Error` 首尾包含`=` */
54
- set innerText(text: string);
55
- /**
56
- * @param level 标题层级
57
- * @param input 标题文字
58
- */
59
- constructor(level: number, input: readonly [string?, string?], config?: Parser.Config, accum?: Token[]);
60
- /** @override */
61
- text(): string;
62
- /** @override */
63
- lint(start?: number): LintError[];
64
- /** @override */
65
- print(): string;
66
- /** @override */
67
- json(): object;
68
- /** @override */
69
- cloneNode(): this;
70
- /**
71
- * 设置标题层级
72
- * @param n 标题层级
73
- */
74
- setLevel(n: number): void;
75
- /** 移除标题后的不可见内容 */
76
- removeTrail(): void;
77
- }
78
- export {};
@@ -1,143 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HeadingToken = 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 fixed_1 = require("../mixin/fixed");
8
- const sol_1 = require("../mixin/sol");
9
- const Parser = require("../index");
10
- const index_1 = require("./index");
11
- const syntax_1 = require("./syntax");
12
- /**
13
- * 章节标题
14
- * @classdesc `{childNodes: [Token, SyntaxToken]}`
15
- */
16
- class HeadingToken extends (0, sol_1.sol)((0, fixed_1.fixed)(index_1.Token)) {
17
- type = 'heading';
18
- #level;
19
- /** 标题格式的等号 */
20
- get #equals() {
21
- return '='.repeat(this.level);
22
- }
23
- /** 标题层级 */
24
- get level() {
25
- return this.#level;
26
- }
27
- /* NOT FOR BROWSER */
28
- set level(n) {
29
- this.setLevel(n);
30
- }
31
- /** 内部wikitext */
32
- get innerText() {
33
- return this.firstChild.text();
34
- }
35
- /** @throws `Error` 首尾包含`=` */
36
- set innerText(text) {
37
- if (text.length > 1 && text.startsWith('=') && text.endsWith('=')) {
38
- throw new Error('修改标题层级请使用 setLevel 方法!');
39
- }
40
- const { childNodes } = Parser.parse(text, this.getAttribute('include'), undefined, this.getAttribute('config'));
41
- this.firstChild.replaceChildren(...childNodes);
42
- }
43
- /* NOT FOR BROWSER END */
44
- /**
45
- * @param level 标题层级
46
- * @param input 标题文字
47
- */
48
- constructor(level, input, config = Parser.getConfig(), accum = []) {
49
- super(undefined, config, accum);
50
- this.#level = level;
51
- const token = new index_1.Token(input[0], config, accum);
52
- token.type = 'heading-title';
53
- token.setAttribute('stage', 2);
54
- const trail = new syntax_1.SyntaxToken(input[1], /^[^\S\n]*$/u, 'heading-trail', config, accum, {
55
- 'Stage-1': ':', '!ExtToken': '',
56
- });
57
- this.append(token, trail);
58
- }
59
- /** @private */
60
- toString(omit) {
61
- const equals = this.#equals;
62
- return omit && this.matchesTypes(omit)
63
- ? ''
64
- : `${this.prependNewLine()}${equals}${this.firstChild.toString(omit)}${equals}${this.lastChild.toString(omit)}`;
65
- }
66
- /** @override */
67
- text() {
68
- const equals = this.#equals;
69
- return `${this.prependNewLine()}${equals}${this.firstChild.text()}${equals}`;
70
- }
71
- /** @private */
72
- getAttribute(key) {
73
- return key === 'padding'
74
- ? super.getAttribute('padding') + this.level
75
- : super.getAttribute(key);
76
- }
77
- /** @private */
78
- getGaps() {
79
- return this.level;
80
- }
81
- /** @override */
82
- lint(start = this.getAbsoluteIndex()) {
83
- const errors = super.lint(start), { firstChild, level } = this, innerStr = String(firstChild), quotes = firstChild.childNodes.filter((node) => node.type === 'quote'), boldQuotes = quotes.filter(({ bold }) => bold), italicQuotes = quotes.filter(({ italic }) => italic);
84
- let rect;
85
- if (this.level === 1) {
86
- rect = { start, ...this.getRootNode().posFromIndex(start) };
87
- errors.push((0, lint_1.generateForChild)(firstChild, rect, '<h1>'));
88
- }
89
- if (innerStr.startsWith('=') || innerStr.endsWith('=')) {
90
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
91
- errors.push((0, lint_1.generateForChild)(firstChild, rect, Parser.msg('unbalanced $1 in a section header', '"="')));
92
- }
93
- if (this.closest('html-attrs, table-attrs')) {
94
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
95
- errors.push((0, lint_1.generateForSelf)(this, rect, 'section header in a HTML tag'));
96
- }
97
- if (boldQuotes.length % 2) {
98
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
99
- errors.push((0, lint_1.generateForChild)(boldQuotes[boldQuotes.length - 1], { ...rect, start: start + level, left: rect.left + level }, Parser.msg('unbalanced $1 in a section header', 'bold apostrophes')));
100
- }
101
- if (italicQuotes.length % 2) {
102
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
103
- errors.push((0, lint_1.generateForChild)(italicQuotes[italicQuotes.length - 1], { start: start + level }, Parser.msg('unbalanced $1 in a section header', 'italic apostrophes')));
104
- }
105
- return errors;
106
- }
107
- /** @override */
108
- print() {
109
- const equals = this.#equals;
110
- return super.print({ pre: equals, sep: equals });
111
- }
112
- /** @override */
113
- json() {
114
- return {
115
- ...super.json(),
116
- level: this.level,
117
- };
118
- }
119
- /* NOT FOR BROWSER */
120
- /** @override */
121
- cloneNode() {
122
- const [title, trail] = this.cloneChildNodes();
123
- return debug_1.Shadow.run(() => {
124
- const token = new HeadingToken(this.level, [], this.getAttribute('config'));
125
- token.firstChild.safeReplaceWith(title);
126
- token.lastChild.safeReplaceWith(trail);
127
- return token;
128
- });
129
- }
130
- /**
131
- * 设置标题层级
132
- * @param n 标题层级
133
- */
134
- setLevel(n) {
135
- this.#level = Math.min(Math.max(n, 1), 6);
136
- }
137
- /** 移除标题后的不可见内容 */
138
- removeTrail() {
139
- this.lastChild.replaceChildren();
140
- }
141
- }
142
- exports.HeadingToken = HeadingToken;
143
- constants_1.classes['HeadingToken'] = __filename;
@@ -1,23 +0,0 @@
1
- import { Token } from './index';
2
- declare const HiddenToken_base: ((abstract new (...args: any[]) => {
3
- text(): string;
4
- lint(): import("..").LintError[];
5
- readonly length: number;
6
- toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
7
- insertAt(token: unknown, i?: number | undefined): unknown;
8
- afterBuild(): void;
9
- getAttribute<T extends string>(key: T): TokenAttributeGetter<T>;
10
- setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
11
- addEventListener(events: string | string[], listener: AstListener): void;
12
- replaceChildren(...elements: (string | import("..").AstNodes)[]): void;
13
- constructorError(msg: string): never;
14
- }) & {
15
- readonly hidden: true;
16
- }) & typeof Token;
17
- /** 不可见的节点 */
18
- export declare class HiddenToken extends HiddenToken_base {
19
- readonly type = "hidden";
20
- /** @override */
21
- cloneNode(): this;
22
- }
23
- export {};
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HiddenToken = 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 index_1 = require("./index");
8
- /** 不可见的节点 */
9
- class HiddenToken extends (0, hidden_1.hidden)(index_1.Token) {
10
- type = 'hidden';
11
- /* NOT FOR BROWSER */
12
- /** @override */
13
- cloneNode() {
14
- const cloned = this.cloneChildNodes(), config = this.getAttribute('config'), acceptable = this.getAttribute('acceptable');
15
- return debug_1.Shadow.run(() => {
16
- const token = new HiddenToken(undefined, config, [], acceptable);
17
- token.append(...cloned);
18
- return token;
19
- });
20
- }
21
- }
22
- exports.HiddenToken = HiddenToken;
23
- constants_1.classes['HiddenToken'] = __filename;
@@ -1,106 +0,0 @@
1
- import * as Parser from '../index';
2
- import { Token } from './index';
3
- import type { LintError } from '../base';
4
- import type { AttributesToken } from '../internal';
5
- declare const HtmlToken_base: (abstract new (...args: any[]) => {
6
- readonly childNodes: Parser.AstNodes[];
7
- readonly "__#7@#attributesChild": Parser.AttributesToken;
8
- attributes: Record<string, string | true>;
9
- className: string;
10
- classList: Set<string>;
11
- id: string;
12
- hasAttr(key: string): boolean;
13
- getAttr(key: string): string | true | undefined;
14
- getAttrNames(): Set<string>;
15
- getAttrs(): Record<string, string | true>;
16
- setAttr(key: string, value: string | boolean): void;
17
- setAttr(prop: Record<string, 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
- lint(start?: number | undefined): Parser.LintError[];
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
- constructorError(msg: string): never;
31
- }) & ((abstract new (...args: any[]) => {
32
- removeAt(): never;
33
- insertAt(token: string, i?: number | undefined): Parser.AstText;
34
- insertAt<T_2 extends Parser.AstNodes>(token: T_2, i?: number | undefined): T_2;
35
- readonly length: number;
36
- toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
37
- text(separator?: string | undefined): string;
38
- lint(start?: number | undefined): Parser.LintError[];
39
- afterBuild(): void;
40
- getAttribute<T extends string>(key: T): TokenAttributeGetter<T>;
41
- setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
42
- addEventListener(events: string | string[], listener: AstListener): void;
43
- replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
44
- constructorError(msg: string): never;
45
- }) & {
46
- readonly fixed: true;
47
- }) & typeof Parser.Token;
48
- /**
49
- * HTML标签
50
- * @classdesc `{childNodes: [AttributesToken]}`
51
- */
52
- export declare class HtmlToken extends HtmlToken_base {
53
- #private;
54
- readonly type = "html";
55
- readonly name: string;
56
- readonly childNodes: [AttributesToken];
57
- abstract get children(): [AttributesToken];
58
- abstract get firstChild(): AttributesToken;
59
- abstract get firstElementChild(): AttributesToken;
60
- abstract get lastChild(): AttributesToken;
61
- abstract get lastElementChild(): AttributesToken;
62
- /** 是否是闭合标签 */
63
- get closing(): boolean;
64
- /** @throws `Error` 自封闭标签或空标签 */
65
- set closing(value: boolean);
66
- /** 是否自封闭 */
67
- get selfClosing(): boolean;
68
- /** @throws `Error` 闭合标签或无效自封闭标签 */
69
- set selfClosing(value: boolean);
70
- /**
71
- * @param name 标签名
72
- * @param attr 标签属性
73
- * @param closing 是否闭合
74
- * @param selfClosing 是否自封闭
75
- */
76
- constructor(name: string, attr: AttributesToken, closing: boolean, selfClosing: boolean, config?: Parser.Config, accum?: Token[]);
77
- /** @override */
78
- text(): string;
79
- /** @override */
80
- lint(start?: number): LintError[];
81
- /**
82
- * 搜索匹配的标签
83
- * @throws `SyntaxError` 同时闭合和自封闭的标签
84
- * @throws `SyntaxError` 无效自封闭标签
85
- * @throws `SyntaxError` 未匹配的标签
86
- */
87
- findMatchingTag(): this | undefined;
88
- /** @override */
89
- print(): string;
90
- /** @override */
91
- json(): object;
92
- /** @override */
93
- cloneNode(): this;
94
- /**
95
- * 更换标签名
96
- * @param tag 标签名
97
- * @throws `RangeError` 非法的HTML标签
98
- */
99
- replaceTag(tag: string): void;
100
- /**
101
- * 修复无效自封闭标签
102
- * @throws `Error` 无法修复无效自封闭标签
103
- */
104
- fix(): void;
105
- }
106
- export {};