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,148 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExtLinkToken = void 0;
4
- const string_1 = require("../util/string");
5
- const Parser = require("../index");
6
- const index_1 = require("./index");
7
- const magicLink_1 = require("./magicLink");
8
- /**
9
- * 外链
10
- * @classdesc `{childNodes: [MagicLinkToken, ?Token]}`
11
- */
12
- class ExtLinkToken extends index_1.Token {
13
- type = 'ext-link';
14
- #space;
15
- /* NOT FOR BROWSER */
16
- /** 协议 */
17
- get protocol() {
18
- return this.firstChild.protocol;
19
- }
20
- set protocol(value) {
21
- this.firstChild.protocol = value;
22
- }
23
- /** 和内链保持一致 */
24
- get link() {
25
- return this.firstChild.link;
26
- }
27
- set link(url) {
28
- this.setTarget(url);
29
- }
30
- /** 链接显示文字 */
31
- get innerText() {
32
- return this.length > 1
33
- ? this.lastChild.text()
34
- : `[${this.getRootNode().querySelectorAll('ext-link[childElementCount=1]').indexOf(this) + 1}]`;
35
- }
36
- /* NOT FOR BROWSER END */
37
- /**
38
- * @param url 网址
39
- * @param space 空白字符
40
- * @param text 链接文字
41
- */
42
- constructor(url, space = '', text = '', config = Parser.getConfig(), accum = []) {
43
- super(undefined, config, accum, {
44
- MagicLinkToken: 0, Token: 1,
45
- });
46
- this.insertAt(new magicLink_1.MagicLinkToken(url, true, config, accum));
47
- this.#space = space;
48
- if (text) {
49
- const inner = new index_1.Token(text, config, accum, {
50
- 'Stage-7': ':', ConverterToken: ':',
51
- });
52
- inner.type = 'ext-link-text';
53
- inner.setAttribute('stage', Parser.MAX_STAGE - 1);
54
- this.insertAt(inner);
55
- }
56
- this.protectChildren(0);
57
- }
58
- /** @private */
59
- toString(omit) {
60
- if (omit && this.matchesTypes(omit)) {
61
- return '';
62
- }
63
- else if (this.length === 1) {
64
- return `[${super.toString(omit)}${this.#space}]`;
65
- }
66
- this.#correct();
67
- (0, string_1.normalizeSpace)(this.lastChild);
68
- return `[${super.toString(omit, this.#space)}]`;
69
- }
70
- /** @override */
71
- text() {
72
- (0, string_1.normalizeSpace)(this.childNodes[1]);
73
- return `[${super.text(' ')}]`;
74
- }
75
- /** @private */
76
- getPadding() {
77
- return 1;
78
- }
79
- /** @private */
80
- getGaps(i) {
81
- this.#correct();
82
- return i === 0 ? this.#space.length : 0;
83
- }
84
- /** @override */
85
- print() {
86
- return super.print(this.length === 1 ? { pre: '[', post: `${this.#space}]` } : { pre: '[', sep: this.#space, post: ']' });
87
- }
88
- /* NOT FOR BROWSER */
89
- /** @override */
90
- cloneNode() {
91
- const [url, text] = this.cloneChildNodes();
92
- return Parser.run(() => {
93
- const token = new ExtLinkToken(undefined, '', '', this.getAttribute('config'));
94
- token.firstChild.safeReplaceWith(url);
95
- if (text) {
96
- token.insertAt(text);
97
- }
98
- return token;
99
- });
100
- }
101
- /** 修正空白字符 */
102
- #correct() {
103
- if (!this.#space && this.length > 1
104
- // 都替换成`<`肯定不对,但无妨
105
- && /^[^[\]<>"{\0-\x1F\x7F\p{Zs}\uFFFD]/u.test(this.lastChild.text().replace(/&[lg]t;/u, '<'))) {
106
- this.#space = ' ';
107
- }
108
- }
109
- /** 获取网址 */
110
- getUrl() {
111
- return this.firstChild.getUrl();
112
- }
113
- /**
114
- * 设置链接目标
115
- * @param url 网址
116
- * @throws `SyntaxError` 非法的外链目标
117
- */
118
- setTarget(url) {
119
- const root = Parser.parse(`[${url}]`, this.getAttribute('include'), 8, this.getAttribute('config')), { length, firstChild: extLink } = root;
120
- if (length !== 1 || !(extLink instanceof ExtLinkToken) || extLink.length !== 1) {
121
- throw new SyntaxError(`非法的外链目标:${url}`);
122
- }
123
- const { firstChild } = extLink;
124
- extLink.destroy();
125
- this.firstChild.safeReplaceWith(firstChild);
126
- }
127
- /**
128
- * 设置链接显示文字
129
- * @param str 链接显示文字
130
- * @throws `SyntaxError` 非法的链接显示文字
131
- */
132
- setLinkText(str) {
133
- const root = Parser.parse(`[//url ${str}]`, this.getAttribute('include'), 8, this.getAttribute('config')), { length, firstChild: extLink } = root;
134
- if (length !== 1 || !(extLink instanceof ExtLinkToken) || extLink.length !== 2) {
135
- throw new SyntaxError(`非法的外链文字:${(0, string_1.noWrap)(str)}`);
136
- }
137
- const { lastChild } = extLink;
138
- if (this.length === 1) {
139
- this.insertAt(lastChild);
140
- }
141
- else {
142
- this.lastChild.safeReplaceWith(lastChild);
143
- }
144
- this.#space ||= ' ';
145
- }
146
- }
147
- exports.ExtLinkToken = ExtLinkToken;
148
- Parser.classes['ExtLinkToken'] = __filename;
@@ -1,54 +0,0 @@
1
- import * as Parser from '../index';
2
- import { Token } from './index';
3
- import { GalleryImageToken } from './link/galleryImage';
4
- import { HiddenToken } from './hidden';
5
- import type { LintError } from '../index';
6
- import type { AstNodes, AstText, AttributesToken, ExtToken } from '../internal';
7
- /**
8
- * gallery标签
9
- * @classdesc `{childNodes: ...(GalleryImageToken|HiddenToken|AstText)}`
10
- */
11
- export declare class GalleryToken extends Token {
12
- readonly type = "ext-inner";
13
- name: 'gallery';
14
- childNodes: (GalleryImageToken | HiddenToken | AstText)[];
15
- abstract get children(): (GalleryImageToken | HiddenToken)[];
16
- abstract get firstChild(): GalleryImageToken | HiddenToken | AstText | undefined;
17
- abstract get firstElementChild(): GalleryImageToken | HiddenToken | undefined;
18
- abstract get lastChild(): GalleryImageToken | HiddenToken | AstText | undefined;
19
- abstract get lastElementChild(): GalleryImageToken | HiddenToken | undefined;
20
- abstract get nextSibling(): undefined;
21
- abstract get nextElementSibling(): undefined;
22
- abstract get previousSibling(): AttributesToken;
23
- abstract get previousElementSibling(): AttributesToken;
24
- abstract get parentNode(): ExtToken | undefined;
25
- abstract get parentElement(): ExtToken | undefined;
26
- /** 所有图片 */
27
- get images(): GalleryImageToken[];
28
- /** @param inner 标签内部wikitext */
29
- constructor(inner?: string, config?: Parser.Config, accum?: Token[]);
30
- /** @override */
31
- text(): string;
32
- /** @override */
33
- lint(start?: number): LintError[];
34
- /** @override */
35
- print(): string;
36
- /** @override */
37
- cloneNode(): this;
38
- /**
39
- * 插入图片
40
- * @param file 图片文件名
41
- * @param i 插入位置
42
- * @throws `SyntaxError` 非法的文件名
43
- */
44
- insertImage(file: string, i?: number): GalleryImageToken;
45
- /**
46
- * @override
47
- * @param token 待插入的节点
48
- * @param i 插入位置
49
- * @throws `RangeError` 插入不可见内容
50
- */
51
- insertAt(token: string, i?: number): AstText;
52
- /** @ignore */
53
- insertAt<T extends AstNodes>(token: T, i?: number): T;
54
- }
@@ -1,119 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GalleryToken = void 0;
4
- const Parser = require("../index");
5
- const index_1 = require("./index");
6
- const galleryImage_1 = require("./link/galleryImage");
7
- const hidden_1 = require("./hidden");
8
- /**
9
- * gallery标签
10
- * @classdesc `{childNodes: ...(GalleryImageToken|HiddenToken|AstText)}`
11
- */
12
- class GalleryToken extends index_1.Token {
13
- type = 'ext-inner';
14
- /* NOT FOR BROWSER */
15
- /** 所有图片 */
16
- get images() {
17
- return this.childNodes.filter(({ type }) => type === 'gallery-image');
18
- }
19
- /* NOT FOR BROWSER END */
20
- /** @param inner 标签内部wikitext */
21
- constructor(inner, config = Parser.getConfig(), accum = []) {
22
- super(undefined, config, accum, {
23
- AstText: ':', GalleryImageToken: ':', HiddenToken: ':',
24
- });
25
- for (const line of inner?.split('\n') ?? []) {
26
- const matches = /^([^|]+)(?:\|(.*))?/u.exec(line);
27
- if (!matches) {
28
- super.insertAt((line.trim()
29
- ? new hidden_1.HiddenToken(line, config, [], {
30
- AstText: ':',
31
- })
32
- : line));
33
- continue;
34
- }
35
- const [, file, alt] = matches;
36
- if (this.normalizeTitle(file, 6, true, true).valid) {
37
- super.insertAt(new galleryImage_1.GalleryImageToken('gallery', file, alt, config, accum));
38
- }
39
- else {
40
- super.insertAt(new hidden_1.HiddenToken(line, config, [], {
41
- AstText: ':',
42
- }));
43
- }
44
- }
45
- }
46
- /** @private */
47
- toString(omit) {
48
- return super.toString(omit, '\n');
49
- }
50
- /** @override */
51
- text() {
52
- return super.text('\n').replace(/\n\s*\n/gu, '\n');
53
- }
54
- /** @private */
55
- getGaps(i) {
56
- return i < this.length - 1 ? 1 : 0;
57
- }
58
- /** @override */
59
- lint(start = this.getAbsoluteIndex()) {
60
- const { top, left } = this.getRootNode().posFromIndex(start), errors = [];
61
- for (let i = 0; i < this.length; i++) {
62
- const child = this.childNodes[i], str = String(child), { length } = str, trimmed = str.trim(), startLine = top + i, startCol = i ? 0 : left;
63
- if (child.type === 'hidden' && trimmed && !/^<!--.*-->$/u.test(trimmed)) {
64
- errors.push({
65
- message: Parser.msg('invalid content in <$1>', 'gallery'),
66
- severity: 'error',
67
- startIndex: start,
68
- endIndex: start + length,
69
- startLine,
70
- endLine: startLine,
71
- startCol,
72
- endCol: startCol + length,
73
- excerpt: String(child).slice(0, 50),
74
- });
75
- }
76
- else if (child.type !== 'hidden' && child.type !== 'text') {
77
- errors.push(...child.lint(start));
78
- }
79
- start += length + 1;
80
- }
81
- return errors;
82
- }
83
- /** @override */
84
- print() {
85
- return super.print({ sep: '\n' });
86
- }
87
- /* NOT FOR BROWSER */
88
- /** @override */
89
- cloneNode() {
90
- const cloned = this.cloneChildNodes();
91
- return Parser.run(() => {
92
- const token = new GalleryToken(undefined, this.getAttribute('config'));
93
- token.append(...cloned);
94
- return token;
95
- });
96
- }
97
- /**
98
- * 插入图片
99
- * @param file 图片文件名
100
- * @param i 插入位置
101
- * @throws `SyntaxError` 非法的文件名
102
- */
103
- insertImage(file, i = this.length) {
104
- if (this.normalizeTitle(file, 6, true, true).valid) {
105
- const token = Parser.run(() => new galleryImage_1.GalleryImageToken('gallery', file, undefined, this.getAttribute('config')));
106
- return this.insertAt(token, i);
107
- }
108
- throw new SyntaxError(`非法的文件名:${file}`);
109
- }
110
- /** @ignore */
111
- insertAt(token, i = 0) {
112
- if (typeof token === 'string' && token.trim() || token instanceof hidden_1.HiddenToken) {
113
- throw new RangeError('请勿向图库中插入不可见内容!');
114
- }
115
- return super.insertAt(token, i);
116
- }
117
- }
118
- exports.GalleryToken = GalleryToken;
119
- Parser.classes['GalleryToken'] = __filename;
@@ -1,73 +0,0 @@
1
- import * as Parser from '../index';
2
- import { Token } from './index';
3
- import { SyntaxToken } from './syntax';
4
- import type { LintError } from '../index';
5
- declare const HeadingToken_base: (abstract new (...args: any[]) => {
6
- "__#7@#isRoot"(): boolean;
7
- prependNewLine(): string;
8
- toString(omit?: Set<string> | undefined): string;
9
- getPadding(): number;
10
- text(): string;
11
- length: number;
12
- insertAt(token: unknown, i?: number | undefined): unknown;
13
- afterBuild(): void;
14
- getAttribute<T extends string>(key: T): TokenAttributeGetter<T>;
15
- setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
16
- addEventListener(events: string | string[], listener: AstListener): void;
17
- replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
18
- }) & ((abstract new (...args: any[]) => {
19
- removeAt(): never;
20
- insertAt(token: string, i?: number | undefined): Parser.AstText;
21
- insertAt<T_2 extends Parser.AstNodes>(token: T_2, i?: number | undefined): T_2;
22
- length: number;
23
- toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
24
- text(separator?: string | undefined): string;
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
- }) & {
31
- readonly fixed: true;
32
- }) & typeof Parser.Token;
33
- /**
34
- * 章节标题
35
- * @classdesc `{childNodes: [Token, SyntaxToken]}`
36
- */
37
- export declare class HeadingToken extends HeadingToken_base {
38
- #private;
39
- readonly type = "heading";
40
- name: string;
41
- childNodes: [Token, SyntaxToken];
42
- abstract get children(): [Token, SyntaxToken];
43
- abstract get firstChild(): Token;
44
- abstract get firstElementChild(): Token;
45
- abstract get lastChild(): SyntaxToken;
46
- abstract get lastElementChild(): SyntaxToken;
47
- /** 标题层级 */
48
- get level(): number;
49
- set level(n: number);
50
- /** 内部wikitext */
51
- get innerText(): string;
52
- /**
53
- * @param level 标题层级
54
- * @param input 标题文字
55
- */
56
- constructor(level: number, input: [string?, string?], config?: Parser.Config, accum?: Token[]);
57
- /** @override */
58
- text(): string;
59
- /** @override */
60
- lint(start?: number): LintError[];
61
- /** @override */
62
- print(): string;
63
- /** @override */
64
- cloneNode(): this;
65
- /**
66
- * 设置标题层级
67
- * @param n 标题层级
68
- */
69
- setLevel(n: number): void;
70
- /** 移除标题后的不可见内容 */
71
- removeTrail(): void;
72
- }
73
- export {};
@@ -1,115 +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 fixed_1 = require("../mixin/fixed");
6
- const sol_1 = require("../mixin/sol");
7
- const Parser = require("../index");
8
- const index_1 = require("./index");
9
- const syntax_1 = require("./syntax");
10
- /**
11
- * 章节标题
12
- * @classdesc `{childNodes: [Token, SyntaxToken]}`
13
- */
14
- class HeadingToken extends (0, sol_1.sol)((0, fixed_1.fixed)(index_1.Token)) {
15
- type = 'heading';
16
- /** 标题格式的等号 */
17
- get #equals() {
18
- return '='.repeat(this.level);
19
- }
20
- /** 标题层级 */
21
- get level() {
22
- return Number(this.name);
23
- }
24
- /* NOT FOR BROWSER */
25
- set level(n) {
26
- this.setLevel(n);
27
- }
28
- /** 内部wikitext */
29
- get innerText() {
30
- return this.firstChild.text();
31
- }
32
- /* NOT FOR BROWSER END */
33
- /**
34
- * @param level 标题层级
35
- * @param input 标题文字
36
- */
37
- constructor(level, input, config = Parser.getConfig(), accum = []) {
38
- super(undefined, config, accum);
39
- this.setAttribute('name', String(level));
40
- const token = new index_1.Token(input[0], config, accum);
41
- token.type = 'heading-title';
42
- token.setAttribute('stage', 2);
43
- const trail = new syntax_1.SyntaxToken(input[1], /^[^\S\n]*$/u, 'heading-trail', config, accum, {
44
- 'Stage-1': ':', '!ExtToken': '',
45
- });
46
- this.append(token, trail);
47
- }
48
- /** @private */
49
- toString(omit) {
50
- const equals = this.#equals;
51
- return omit && this.matchesTypes(omit)
52
- ? ''
53
- : `${this.prependNewLine()}${equals}${this.firstChild.toString(omit)}${equals}${this.lastChild.toString(omit)}`;
54
- }
55
- /** @override */
56
- text() {
57
- const equals = this.#equals;
58
- return `${this.prependNewLine()}${equals}${this.firstChild.text()}${equals}`;
59
- }
60
- /** @private */
61
- getPadding() {
62
- return super.getPadding() + this.level;
63
- }
64
- /** @private */
65
- getGaps(i) {
66
- return i === 0 ? this.level : 0;
67
- }
68
- /** @override */
69
- lint(start = this.getAbsoluteIndex()) {
70
- const errors = super.lint(start), innerStr = String(this.firstChild);
71
- let refError;
72
- if (this.name === '1') {
73
- refError = (0, lint_1.generateForSelf)(this, { start }, '<h1>');
74
- errors.push(refError);
75
- }
76
- if (innerStr.startsWith('=') || innerStr.endsWith('=')) {
77
- refError ??= (0, lint_1.generateForSelf)(this, { start }, '');
78
- errors.push({ ...refError, message: Parser.msg('unbalanced "=" in a section header') });
79
- }
80
- if (this.closest('html-attrs, table-attrs')) {
81
- refError ??= (0, lint_1.generateForSelf)(this, { start }, '');
82
- errors.push({ ...refError, message: Parser.msg('section header in a HTML tag') });
83
- }
84
- return errors;
85
- }
86
- /** @override */
87
- print() {
88
- const equals = this.#equals;
89
- return super.print({ pre: equals, sep: equals });
90
- }
91
- /* NOT FOR BROWSER */
92
- /** @override */
93
- cloneNode() {
94
- const [title, trail] = this.cloneChildNodes();
95
- return Parser.run(() => {
96
- const token = new HeadingToken(this.level, [], this.getAttribute('config'));
97
- token.firstChild.safeReplaceWith(title);
98
- token.lastChild.safeReplaceWith(trail);
99
- return token;
100
- });
101
- }
102
- /**
103
- * 设置标题层级
104
- * @param n 标题层级
105
- */
106
- setLevel(n) {
107
- this.setAttribute('name', String(Math.min(Math.max(n, 1), 6)));
108
- }
109
- /** 移除标题后的不可见内容 */
110
- removeTrail() {
111
- this.lastChild.replaceChildren();
112
- }
113
- }
114
- exports.HeadingToken = HeadingToken;
115
- Parser.classes['HeadingToken'] = __filename;
@@ -1,21 +0,0 @@
1
- import * as Parser from '../index';
2
- declare const HiddenToken_base: ((abstract new (...args: any[]) => {
3
- text(): string;
4
- length: number;
5
- toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
6
- insertAt(token: unknown, i?: number | undefined): unknown;
7
- afterBuild(): void;
8
- getAttribute<T extends string>(key: T): TokenAttributeGetter<T>;
9
- setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
10
- addEventListener(events: string | string[], listener: AstListener): void;
11
- replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
12
- }) & {
13
- readonly hidden: true;
14
- }) & typeof Parser.Token;
15
- /** 不可见的节点 */
16
- export declare class HiddenToken extends HiddenToken_base {
17
- readonly type = "hidden";
18
- /** @override */
19
- cloneNode(): this;
20
- }
21
- export {};
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HiddenToken = void 0;
4
- const hidden_1 = require("../mixin/hidden");
5
- const Parser = require("../index");
6
- const index_1 = require("./index");
7
- /** 不可见的节点 */
8
- class HiddenToken extends (0, hidden_1.hidden)(index_1.Token) {
9
- type = 'hidden';
10
- /* NOT FOR BROWSER */
11
- /** @override */
12
- cloneNode() {
13
- const cloned = this.cloneChildNodes(), config = this.getAttribute('config'), acceptable = this.getAttribute('acceptable');
14
- return Parser.run(() => {
15
- const token = new HiddenToken(undefined, config, [], acceptable);
16
- token.append(...cloned);
17
- return token;
18
- });
19
- }
20
- }
21
- exports.HiddenToken = HiddenToken;
22
- Parser.classes['HiddenToken'] = __filename;
@@ -1,100 +0,0 @@
1
- import * as Parser from '../index';
2
- import { Token } from './index';
3
- import type { LintError } from '../index';
4
- import type { AttributesToken } from '../internal';
5
- declare const HtmlToken_base: (abstract new (...args: any[]) => {
6
- childNodes: Parser.AstNodes[];
7
- readonly "__#4@#attributesChild": Parser.AttributesToken;
8
- readonly attributes: Record<string, string | true>;
9
- className: string;
10
- readonly classList: Set<string>;
11
- id: string;
12
- hasAttr(key: string): boolean;
13
- getAttr(key: string): string | true | undefined;
14
- getAttrNames(): Set<string>;
15
- hasAttrs(): boolean;
16
- getAttrs(): Record<string, string | true>;
17
- setAttr(key: string, value: string | boolean): void;
18
- removeAttr(key: string): void;
19
- toggleAttr(key: string, force?: boolean | undefined): void;
20
- length: number;
21
- toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
22
- text(separator?: string | undefined): string;
23
- insertAt(token: unknown, i?: number | undefined): unknown;
24
- afterBuild(): void;
25
- getAttribute<T extends string>(key: T): TokenAttributeGetter<T>;
26
- setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
27
- addEventListener(events: string | string[], listener: AstListener): void;
28
- replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
29
- }) & ((abstract new (...args: any[]) => {
30
- removeAt(): never;
31
- insertAt(token: string, i?: number | undefined): Parser.AstText;
32
- insertAt<T_2 extends Parser.AstNodes>(token: T_2, i?: number | undefined): T_2;
33
- length: number;
34
- toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
35
- text(separator?: string | undefined): string;
36
- afterBuild(): void;
37
- getAttribute<T extends string>(key: T): TokenAttributeGetter<T>;
38
- setAttribute<T_1 extends string>(key: T_1, value: TokenAttributeSetter<T_1>): void;
39
- addEventListener(events: string | string[], listener: AstListener): void;
40
- replaceChildren(...elements: (string | Parser.AstNodes)[]): void;
41
- }) & {
42
- readonly fixed: true;
43
- }) & typeof Parser.Token;
44
- /**
45
- * HTML标签
46
- * @classdesc `{childNodes: [AttributesToken]}`
47
- */
48
- export declare class HtmlToken extends HtmlToken_base {
49
- #private;
50
- readonly type = "html";
51
- name: string;
52
- childNodes: [AttributesToken];
53
- abstract get children(): [AttributesToken];
54
- abstract get firstChild(): AttributesToken;
55
- abstract get firstElementChild(): AttributesToken;
56
- abstract get lastChild(): AttributesToken;
57
- abstract get lastElementChild(): AttributesToken;
58
- /** 是否是闭合标签 */
59
- get closing(): boolean;
60
- /** @throws `Error` 自封闭标签或空标签 */
61
- set closing(value: boolean);
62
- /** 是否自封闭 */
63
- get selfClosing(): boolean;
64
- /** @throws `Error` 闭合标签或无效自封闭标签 */
65
- set selfClosing(value: boolean);
66
- /**
67
- * @param name 标签名
68
- * @param attr 标签属性
69
- * @param closing 是否闭合
70
- * @param selfClosing 是否自封闭
71
- */
72
- constructor(name: string, attr: AttributesToken, closing: boolean, selfClosing: boolean, config?: Parser.Config, accum?: Token[]);
73
- /** @override */
74
- text(): string;
75
- /** @override */
76
- lint(start?: number): LintError[];
77
- /**
78
- * 搜索匹配的标签
79
- * @throws `SyntaxError` 同时闭合和自封闭的标签
80
- * @throws `SyntaxError` 无效自封闭标签
81
- * @throws `SyntaxError` 未闭合的标签
82
- */
83
- findMatchingTag(): this | undefined;
84
- /** @override */
85
- print(): string;
86
- /** @override */
87
- cloneNode(): this;
88
- /**
89
- * 更换标签名
90
- * @param tag 标签名
91
- * @throws `RangeError` 非法的HTML标签
92
- */
93
- replaceTag(tag: string): void;
94
- /**
95
- * 修复无效自封闭标签
96
- * @throws `Error` 无法修复无效自封闭标签
97
- */
98
- fix(): void;
99
- }
100
- export {};