wikiparser-node 1.6.2 → 1.7.0-beta.0

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 (167) hide show
  1. package/bundle/bundle.min.js +38 -0
  2. package/config/default.json +5 -0
  3. package/config/enwiki.json +4 -814
  4. package/config/llwiki.json +5 -35
  5. package/config/minimum.json +3 -0
  6. package/config/moegirl.json +5 -44
  7. package/config/zhwiki.json +6 -466
  8. package/extensions/dist/base.js +64 -0
  9. package/extensions/dist/editor.js +159 -0
  10. package/extensions/dist/highlight.js +58 -0
  11. package/extensions/dist/lint.js +60 -0
  12. package/extensions/editor.css +64 -0
  13. package/extensions/ui.css +144 -0
  14. package/i18n/zh-hans.json +2 -1
  15. package/i18n/zh-hant.json +2 -1
  16. package/package.json +31 -16
  17. package/config/.schema.json +0 -172
  18. package/dist/addon/table.d.ts +0 -1
  19. package/dist/addon/table.js +0 -485
  20. package/dist/base.d.ts +0 -69
  21. package/dist/base.js +0 -38
  22. package/dist/index.d.ts +0 -31
  23. package/dist/index.js +0 -212
  24. package/dist/internal.d.ts +0 -44
  25. package/dist/lib/element.d.ts +0 -151
  26. package/dist/lib/element.js +0 -618
  27. package/dist/lib/node.d.ts +0 -146
  28. package/dist/lib/node.js +0 -426
  29. package/dist/lib/range.d.ts +0 -104
  30. package/dist/lib/range.js +0 -385
  31. package/dist/lib/ranges.d.ts +0 -28
  32. package/dist/lib/ranges.js +0 -126
  33. package/dist/lib/text.d.ts +0 -63
  34. package/dist/lib/text.js +0 -354
  35. package/dist/lib/title.d.ts +0 -40
  36. package/dist/lib/title.js +0 -179
  37. package/dist/mixin/attributesParent.d.ts +0 -50
  38. package/dist/mixin/attributesParent.js +0 -81
  39. package/dist/mixin/fixed.d.ts +0 -6
  40. package/dist/mixin/fixed.js +0 -30
  41. package/dist/mixin/flagsParent.d.ts +0 -72
  42. package/dist/mixin/flagsParent.js +0 -59
  43. package/dist/mixin/hidden.d.ts +0 -5
  44. package/dist/mixin/hidden.js +0 -24
  45. package/dist/mixin/magicLinkParent.d.ts +0 -40
  46. package/dist/mixin/magicLinkParent.js +0 -42
  47. package/dist/mixin/singleLine.d.ts +0 -6
  48. package/dist/mixin/singleLine.js +0 -26
  49. package/dist/mixin/sol.d.ts +0 -6
  50. package/dist/mixin/sol.js +0 -43
  51. package/dist/mixin/syntax.d.ts +0 -9
  52. package/dist/mixin/syntax.js +0 -50
  53. package/dist/parser/braces.js +0 -130
  54. package/dist/parser/commentAndExt.js +0 -89
  55. package/dist/parser/converter.js +0 -40
  56. package/dist/parser/externalLinks.js +0 -45
  57. package/dist/parser/hrAndDoubleUnderscore.js +0 -40
  58. package/dist/parser/html.js +0 -38
  59. package/dist/parser/links.js +0 -97
  60. package/dist/parser/list.js +0 -97
  61. package/dist/parser/magicLinks.js +0 -42
  62. package/dist/parser/quotes.js +0 -67
  63. package/dist/parser/selector.js +0 -190
  64. package/dist/parser/table.js +0 -123
  65. package/dist/src/arg.d.ts +0 -58
  66. package/dist/src/arg.js +0 -214
  67. package/dist/src/atom.d.ts +0 -12
  68. package/dist/src/atom.js +0 -27
  69. package/dist/src/attribute.d.ts +0 -71
  70. package/dist/src/attribute.js +0 -502
  71. package/dist/src/attributes.d.ts +0 -109
  72. package/dist/src/attributes.js +0 -356
  73. package/dist/src/converter.d.ts +0 -33
  74. package/dist/src/converter.js +0 -134
  75. package/dist/src/converterFlags.d.ts +0 -87
  76. package/dist/src/converterFlags.js +0 -242
  77. package/dist/src/converterRule.d.ts +0 -77
  78. package/dist/src/converterRule.js +0 -209
  79. package/dist/src/extLink.d.ts +0 -43
  80. package/dist/src/extLink.js +0 -191
  81. package/dist/src/gallery.d.ts +0 -54
  82. package/dist/src/gallery.js +0 -139
  83. package/dist/src/heading.d.ts +0 -47
  84. package/dist/src/heading.js +0 -190
  85. package/dist/src/hidden.d.ts +0 -7
  86. package/dist/src/hidden.js +0 -23
  87. package/dist/src/html.d.ts +0 -65
  88. package/dist/src/html.js +0 -358
  89. package/dist/src/imageParameter.d.ts +0 -65
  90. package/dist/src/imageParameter.js +0 -257
  91. package/dist/src/imagemap.d.ts +0 -54
  92. package/dist/src/imagemap.js +0 -144
  93. package/dist/src/imagemapLink.d.ts +0 -31
  94. package/dist/src/imagemapLink.js +0 -93
  95. package/dist/src/index.d.ts +0 -143
  96. package/dist/src/index.js +0 -851
  97. package/dist/src/link/base.d.ts +0 -52
  98. package/dist/src/link/base.js +0 -228
  99. package/dist/src/link/category.d.ts +0 -13
  100. package/dist/src/link/category.js +0 -28
  101. package/dist/src/link/file.d.ts +0 -98
  102. package/dist/src/link/file.js +0 -272
  103. package/dist/src/link/galleryImage.d.ts +0 -32
  104. package/dist/src/link/galleryImage.js +0 -158
  105. package/dist/src/link/index.d.ts +0 -56
  106. package/dist/src/link/index.js +0 -133
  107. package/dist/src/magicLink.d.ts +0 -59
  108. package/dist/src/magicLink.js +0 -223
  109. package/dist/src/nested.d.ts +0 -43
  110. package/dist/src/nested.js +0 -105
  111. package/dist/src/nowiki/base.d.ts +0 -31
  112. package/dist/src/nowiki/base.js +0 -93
  113. package/dist/src/nowiki/comment.d.ts +0 -25
  114. package/dist/src/nowiki/comment.js +0 -76
  115. package/dist/src/nowiki/dd.d.ts +0 -8
  116. package/dist/src/nowiki/dd.js +0 -24
  117. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -18
  118. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  119. package/dist/src/nowiki/hr.d.ts +0 -5
  120. package/dist/src/nowiki/hr.js +0 -63
  121. package/dist/src/nowiki/index.d.ts +0 -16
  122. package/dist/src/nowiki/index.js +0 -27
  123. package/dist/src/nowiki/list.d.ts +0 -16
  124. package/dist/src/nowiki/list.js +0 -109
  125. package/dist/src/nowiki/listBase.d.ts +0 -5
  126. package/dist/src/nowiki/listBase.js +0 -61
  127. package/dist/src/nowiki/noinclude.d.ts +0 -10
  128. package/dist/src/nowiki/noinclude.js +0 -23
  129. package/dist/src/nowiki/quote.d.ts +0 -14
  130. package/dist/src/nowiki/quote.js +0 -131
  131. package/dist/src/onlyinclude.d.ts +0 -16
  132. package/dist/src/onlyinclude.js +0 -57
  133. package/dist/src/paramTag/index.d.ts +0 -37
  134. package/dist/src/paramTag/index.js +0 -77
  135. package/dist/src/paramTag/inputbox.d.ts +0 -8
  136. package/dist/src/paramTag/inputbox.js +0 -22
  137. package/dist/src/parameter.d.ts +0 -70
  138. package/dist/src/parameter.js +0 -264
  139. package/dist/src/pre.d.ts +0 -31
  140. package/dist/src/pre.js +0 -59
  141. package/dist/src/syntax.d.ts +0 -20
  142. package/dist/src/syntax.js +0 -86
  143. package/dist/src/table/base.d.ts +0 -27
  144. package/dist/src/table/base.js +0 -81
  145. package/dist/src/table/index.d.ts +0 -242
  146. package/dist/src/table/index.js +0 -497
  147. package/dist/src/table/td.d.ts +0 -86
  148. package/dist/src/table/td.js +0 -355
  149. package/dist/src/table/tr.d.ts +0 -32
  150. package/dist/src/table/tr.js +0 -58
  151. package/dist/src/table/trBase.d.ts +0 -53
  152. package/dist/src/table/trBase.js +0 -156
  153. package/dist/src/tagPair/ext.d.ts +0 -32
  154. package/dist/src/tagPair/ext.js +0 -203
  155. package/dist/src/tagPair/include.d.ts +0 -35
  156. package/dist/src/tagPair/include.js +0 -74
  157. package/dist/src/tagPair/index.d.ts +0 -27
  158. package/dist/src/tagPair/index.js +0 -128
  159. package/dist/src/transclude.d.ts +0 -167
  160. package/dist/src/transclude.js +0 -717
  161. package/dist/util/constants.js +0 -27
  162. package/dist/util/debug.js +0 -81
  163. package/dist/util/diff.js +0 -83
  164. package/dist/util/lint.js +0 -31
  165. package/dist/util/string.js +0 -60
  166. package/errors/README +0 -1
  167. package/printed/README +0 -1
@@ -1,191 +0,0 @@
1
- "use strict";
2
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
- var _, done = false;
8
- for (var i = decorators.length - 1; i >= 0; i--) {
9
- var context = {};
10
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
- if (kind === "accessor") {
15
- if (result === void 0) continue;
16
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
- if (_ = accept(result.get)) descriptor.get = _;
18
- if (_ = accept(result.set)) descriptor.set = _;
19
- if (_ = accept(result.init)) initializers.unshift(_);
20
- }
21
- else if (_ = accept(result)) {
22
- if (kind === "field") initializers.unshift(_);
23
- else descriptor[key] = _;
24
- }
25
- }
26
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
- done = true;
28
- };
29
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
- var useValue = arguments.length > 2;
31
- for (var i = 0; i < initializers.length; i++) {
32
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
- }
34
- return useValue ? value : void 0;
35
- };
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.ExtLinkToken = void 0;
38
- const constants_1 = require("../util/constants");
39
- const lint_1 = require("../util/lint");
40
- const string_1 = require("../util/string");
41
- const debug_1 = require("../util/debug");
42
- const magicLinkParent_1 = require("../mixin/magicLinkParent");
43
- const index_1 = require("../index");
44
- const index_2 = require("./index");
45
- const magicLink_1 = require("./magicLink");
46
- /**
47
- * 外链
48
- * @classdesc `{childNodes: [MagicLinkToken, ?Token]}`
49
- */
50
- let ExtLinkToken = (() => {
51
- let _classDecorators = [magicLinkParent_1.magicLinkParent];
52
- let _classDescriptor;
53
- let _classExtraInitializers = [];
54
- let _classThis;
55
- let _classSuper = index_2.Token;
56
- var ExtLinkToken = class extends _classSuper {
57
- static { _classThis = this; }
58
- static {
59
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
60
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
61
- ExtLinkToken = _classThis = _classDescriptor.value;
62
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
63
- __runInitializers(_classThis, _classExtraInitializers);
64
- }
65
- type = 'ext-link';
66
- #space;
67
- /** 链接显示文字 */
68
- get innerText() {
69
- return this.length > 1
70
- ? this.lastChild.text()
71
- : `[${this.getRootNode().querySelectorAll('ext-link[childElementCount=1]').indexOf(this) + 1}]`;
72
- }
73
- set innerText(text) {
74
- this.setLinkText(text);
75
- }
76
- /* NOT FOR BROWSER END */
77
- /**
78
- * @param url 网址
79
- * @param space 空白字符
80
- * @param text 链接文字
81
- */
82
- constructor(url, space = '', text = '', config = index_1.default.getConfig(), accum = []) {
83
- super(undefined, config, accum, {
84
- MagicLinkToken: 0, Token: 1,
85
- });
86
- const link = url && /\0\d+f\x7F/u.test(url)
87
- ? accum[Number(url.slice(1, -2))]
88
- // @ts-expect-error abstract class
89
- : new magicLink_1.MagicLinkToken(url, true, config, accum);
90
- this.insertAt(link);
91
- this.#space = space;
92
- if (text) {
93
- const inner = new index_2.Token(text, config, accum, {
94
- 'Stage-7': ':', ConverterToken: ':',
95
- });
96
- inner.type = 'ext-link-text';
97
- inner.setAttribute('stage', constants_1.MAX_STAGE - 1);
98
- this.insertAt(inner);
99
- }
100
- /* NOT FOR BROWSER */
101
- this.protectChildren(0);
102
- }
103
- /** @private */
104
- toString() {
105
- if (this.length === 1) {
106
- return `[${super.toString()}${this.#space}]`;
107
- }
108
- /* NOT FOR BROWSER */
109
- this.#correct();
110
- (0, string_1.normalizeSpace)(this.lastChild);
111
- /* NOT FOR BROWSER END */
112
- return `[${super.toString(this.#space)}]`;
113
- }
114
- /** @override */
115
- text() {
116
- /* NOT FOR BROWSER */
117
- (0, string_1.normalizeSpace)(this.childNodes[1]);
118
- /* NOT FOR BROWSER END */
119
- return `[${super.text(' ')}]`;
120
- }
121
- /** @private */
122
- getAttribute(key) {
123
- return key === 'padding' ? 1 : super.getAttribute(key);
124
- }
125
- /** @private */
126
- getGaps() {
127
- /* NOT FOR BROWSER */
128
- this.#correct();
129
- /* NOT FOR BROWSER END */
130
- return this.#space.length;
131
- }
132
- /** @override */
133
- lint(start = this.getAbsoluteIndex(), re) {
134
- const errors = super.lint(start, re);
135
- if (this.length === 1 && this.closest('heading-title')) {
136
- errors.push((0, lint_1.generateForSelf)(this, { start }, 'var-anchor', 'variable anchor in a section header'));
137
- }
138
- return errors;
139
- }
140
- /** @override */
141
- print() {
142
- return super.print(this.length === 1 ? { pre: '[', post: `${this.#space}]` } : { pre: '[', sep: this.#space, post: ']' });
143
- }
144
- /* NOT FOR BROWSER */
145
- /** @override */
146
- cloneNode() {
147
- const [url, text] = this.cloneChildNodes();
148
- return debug_1.Shadow.run(() => {
149
- // @ts-expect-error abstract class
150
- const token = new ExtLinkToken(undefined, '', '', this.getAttribute('config'));
151
- token.firstChild.safeReplaceWith(url);
152
- if (text) {
153
- token.insertAt(text);
154
- }
155
- return token;
156
- });
157
- }
158
- /** 修正空白字符 */
159
- #correct() {
160
- const { lastChild, length } = this, { firstChild } = lastChild;
161
- if (!this.#space
162
- && length > 1
163
- && (firstChild?.type === 'text' || firstChild?.type === 'converter')
164
- // 都替换成`<`肯定不对,但无妨
165
- && /^[^[\]<>"\0-\x1F\x7F\p{Zs}\uFFFD]/u.test(lastChild.text().replace(/&[lg]t;/u, '<'))) {
166
- this.#space = ' ';
167
- }
168
- }
169
- /**
170
- * 设置链接显示文字
171
- * @param str 链接显示文字
172
- */
173
- setLinkText(str) {
174
- const root = index_1.default.parse(str, this.getAttribute('include'), 7, this.getAttribute('config'));
175
- if (this.length === 1) {
176
- root.type = 'ext-link-text';
177
- root.setAttribute('acceptable', {
178
- 'Stage-7': ':', ConverterToken: ':',
179
- });
180
- this.insertAt(root);
181
- }
182
- else {
183
- this.lastChild.replaceChildren(...root.childNodes);
184
- }
185
- this.#space ||= ' ';
186
- }
187
- };
188
- return ExtLinkToken = _classThis;
189
- })();
190
- exports.ExtLinkToken = ExtLinkToken;
191
- constants_1.classes['ExtLinkToken'] = __filename;
@@ -1,54 +0,0 @@
1
- import 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 { AstText, AttributesToken, ExtToken, AstNodes } from '../internal';
7
- /**
8
- * gallery标签
9
- * @classdesc `{childNodes: ...(GalleryImageToken|NoincludeToken|AstText)}`
10
- */
11
- export declare abstract class GalleryToken extends Token {
12
- #private;
13
- readonly type = "ext-inner";
14
- readonly name: 'gallery';
15
- readonly childNodes: readonly (GalleryImageToken | NoincludeToken | AstText)[];
16
- abstract get firstChild(): GalleryImageToken | NoincludeToken | AstText | undefined;
17
- abstract get lastChild(): GalleryImageToken | NoincludeToken | AstText | undefined;
18
- abstract get nextSibling(): undefined;
19
- abstract get previousSibling(): AttributesToken;
20
- abstract get parentNode(): ExtToken | undefined;
21
- abstract get children(): (GalleryImageToken | NoincludeToken)[];
22
- abstract get firstElementChild(): GalleryImageToken | NoincludeToken | undefined;
23
- abstract get lastElementChild(): GalleryImageToken | NoincludeToken | undefined;
24
- abstract get nextElementSibling(): undefined;
25
- abstract get previousElementSibling(): AttributesToken;
26
- abstract get parentElement(): ExtToken | undefined;
27
- /** 所有图片 */
28
- get images(): 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, re?: RegExp): 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,139 +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 index_1 = require("../index");
7
- const index_2 = 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_2.Token {
15
- type = 'ext-inner';
16
- /** 所有图片 */
17
- get images() {
18
- return this.childNodes.filter((0, debug_1.isToken)('gallery-image'));
19
- }
20
- /* NOT FOR BROWSER END */
21
- /** @param inner 标签内部wikitext */
22
- constructor(inner, config = index_1.default.getConfig(), accum = []) {
23
- super(undefined, config, accum, {
24
- AstText: ':', GalleryImageToken: ':', NoincludeToken: ':',
25
- });
26
- for (const line of inner?.split('\n') ?? []) {
27
- const matches = /^([^|]+)(?:\|(.*))?/u.exec(line);
28
- if (!matches) {
29
- // @ts-expect-error abstract class
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
- // @ts-expect-error abstract class
36
- super.insertAt(new galleryImage_1.GalleryImageToken('gallery', file, alt, config, accum));
37
- }
38
- else {
39
- // @ts-expect-error abstract class
40
- super.insertAt(new noinclude_1.NoincludeToken(line, config));
41
- }
42
- }
43
- }
44
- /**
45
- * 检查文件名是否有效
46
- * @param file 文件名
47
- */
48
- #checkFile(file) {
49
- return this.normalizeTitle(file, 6, true, true).valid;
50
- }
51
- /** @private */
52
- toString() {
53
- return super.toString('\n');
54
- }
55
- /** @override */
56
- text() {
57
- return super.text('\n').replace(/\n\s*\n/gu, '\n');
58
- }
59
- /** @private */
60
- getGaps() {
61
- return 1;
62
- }
63
- /** @override */
64
- lint(start = this.getAbsoluteIndex(), re) {
65
- const { top, left } = this.getRootNode().posFromIndex(start), errors = [];
66
- for (let i = 0; i < this.length; i++) {
67
- const child = this.childNodes[i], str = String(child), { length } = str, trimmed = str.trim(), startLine = top + i, startCol = i ? 0 : left;
68
- if (child.type === 'noinclude' && trimmed && !/^<!--.*-->$/u.test(trimmed)) {
69
- errors.push({
70
- rule: 'no-ignored',
71
- message: index_1.default.msg('invalid content in <$1>', 'gallery'),
72
- severity: trimmed.startsWith('|') ? 'warning' : 'error',
73
- startIndex: start,
74
- endIndex: start + length,
75
- startLine,
76
- endLine: startLine,
77
- startCol,
78
- endCol: startCol + length,
79
- suggestions: [
80
- {
81
- desc: 'remove',
82
- range: [start, start + length],
83
- text: '',
84
- },
85
- {
86
- desc: 'comment',
87
- range: [start, start + length],
88
- text: `<!--${str}-->`,
89
- },
90
- ],
91
- });
92
- }
93
- else if (child.type !== 'noinclude' && child.type !== 'text') {
94
- errors.push(...child.lint(start, re));
95
- }
96
- start += length + 1;
97
- }
98
- return errors;
99
- }
100
- /** @override */
101
- print() {
102
- return super.print({ sep: '\n' });
103
- }
104
- /* NOT FOR BROWSER */
105
- /** @override */
106
- cloneNode() {
107
- const cloned = this.cloneChildNodes();
108
- return debug_1.Shadow.run(() => {
109
- // @ts-expect-error abstract class
110
- const token = new GalleryToken(undefined, this.getAttribute('config'));
111
- token.append(...cloned);
112
- return token;
113
- });
114
- }
115
- /**
116
- * 插入图片
117
- * @param file 图片文件名
118
- * @param i 插入位置
119
- * @throws `SyntaxError` 非法的文件名
120
- */
121
- insertImage(file, i) {
122
- if (this.#checkFile(file)) {
123
- const token = debug_1.Shadow.run(
124
- // @ts-expect-error abstract class
125
- () => new galleryImage_1.GalleryImageToken('gallery', file, undefined, this.getAttribute('config')));
126
- token.afterBuild();
127
- return this.insertAt(token, i);
128
- }
129
- throw new SyntaxError(`非法的文件名:${file}`);
130
- }
131
- insertAt(token, i = this.length) {
132
- if (typeof token === 'string' && token.trim() || token instanceof noinclude_1.NoincludeToken) {
133
- throw new RangeError('请勿向图库中插入不可见内容!');
134
- }
135
- return super.insertAt(token, i);
136
- }
137
- }
138
- exports.GalleryToken = GalleryToken;
139
- constants_1.classes['GalleryToken'] = __filename;
@@ -1,47 +0,0 @@
1
- import Parser from '../index';
2
- import { Token } from './index';
3
- import { SyntaxToken } from './syntax';
4
- import type { LintError, AST } from '../base';
5
- /**
6
- * 章节标题
7
- * @classdesc `{childNodes: [Token, SyntaxToken]}`
8
- */
9
- export declare abstract class HeadingToken extends Token {
10
- #private;
11
- readonly type = "heading";
12
- readonly childNodes: readonly [Token, SyntaxToken];
13
- abstract get firstChild(): Token;
14
- abstract get lastChild(): SyntaxToken;
15
- abstract get children(): [Token, SyntaxToken];
16
- abstract get firstElementChild(): Token;
17
- abstract get lastElementChild(): SyntaxToken;
18
- /** 标题层级 */
19
- get level(): number;
20
- set level(n: number);
21
- /** 内部wikitext */
22
- get innerText(): string;
23
- /** @throws `Error` 首尾包含`=` */
24
- set innerText(text: string);
25
- /**
26
- * @param level 标题层级
27
- * @param input 标题文字
28
- */
29
- constructor(level: number, input: readonly [string?, string?], config?: Parser.Config, accum?: Token[]);
30
- /** @override */
31
- text(): string;
32
- /** @override */
33
- lint(start?: number, re?: RegExp): LintError[];
34
- /** @override */
35
- print(): string;
36
- /** @override */
37
- json(): AST;
38
- /** @override */
39
- cloneNode(): this;
40
- /**
41
- * 设置标题层级
42
- * @param n 标题层级
43
- */
44
- setLevel(n: number): void;
45
- /** 移除标题后的不可见内容 */
46
- removeTrail(): void;
47
- }
@@ -1,190 +0,0 @@
1
- "use strict";
2
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
- var _, done = false;
8
- for (var i = decorators.length - 1; i >= 0; i--) {
9
- var context = {};
10
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
- if (kind === "accessor") {
15
- if (result === void 0) continue;
16
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
- if (_ = accept(result.get)) descriptor.get = _;
18
- if (_ = accept(result.set)) descriptor.set = _;
19
- if (_ = accept(result.init)) initializers.unshift(_);
20
- }
21
- else if (_ = accept(result)) {
22
- if (kind === "field") initializers.unshift(_);
23
- else descriptor[key] = _;
24
- }
25
- }
26
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
- done = true;
28
- };
29
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
- var useValue = arguments.length > 2;
31
- for (var i = 0; i < initializers.length; i++) {
32
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
- }
34
- return useValue ? value : void 0;
35
- };
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.HeadingToken = void 0;
38
- const lint_1 = require("../util/lint");
39
- const debug_1 = require("../util/debug");
40
- const constants_1 = require("../util/constants");
41
- const fixed_1 = require("../mixin/fixed");
42
- const sol_1 = require("../mixin/sol");
43
- const index_1 = require("../index");
44
- const index_2 = require("./index");
45
- const syntax_1 = require("./syntax");
46
- /**
47
- * 章节标题
48
- * @classdesc `{childNodes: [Token, SyntaxToken]}`
49
- */
50
- let HeadingToken = (() => {
51
- let _classDecorators = [fixed_1.fixedToken, sol_1.sol];
52
- let _classDescriptor;
53
- let _classExtraInitializers = [];
54
- let _classThis;
55
- let _classSuper = index_2.Token;
56
- var HeadingToken = class extends _classSuper {
57
- static { _classThis = this; }
58
- static {
59
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
60
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
61
- HeadingToken = _classThis = _classDescriptor.value;
62
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
63
- __runInitializers(_classThis, _classExtraInitializers);
64
- }
65
- type = 'heading';
66
- #level;
67
- /* NOT FOR BROWSER END */
68
- /** 标题格式的等号 */
69
- get #equals() {
70
- return '='.repeat(this.level);
71
- }
72
- /** 标题层级 */
73
- get level() {
74
- return this.#level;
75
- }
76
- /* NOT FOR BROWSER */
77
- set level(n) {
78
- this.setLevel(n);
79
- }
80
- /** 内部wikitext */
81
- get innerText() {
82
- return this.firstChild.text().trim();
83
- }
84
- /** @throws `Error` 首尾包含`=` */
85
- set innerText(text) {
86
- if (text.length > 1 && text.startsWith('=') && text.endsWith('=')) {
87
- throw new Error('修改标题层级请使用 setLevel 方法!');
88
- }
89
- const { childNodes } = index_1.default.parse(text, this.getAttribute('include'), undefined, this.getAttribute('config'));
90
- this.firstChild.replaceChildren(...childNodes);
91
- }
92
- /* NOT FOR BROWSER END */
93
- /**
94
- * @param level 标题层级
95
- * @param input 标题文字
96
- */
97
- constructor(level, input, config = index_1.default.getConfig(), accum = []) {
98
- super(undefined, config, accum);
99
- this.#level = level;
100
- const token = new index_2.Token(input[0], config, accum);
101
- token.type = 'heading-title';
102
- token.setAttribute('stage', 2);
103
- const trail = new syntax_1.SyntaxToken(input[1], /^[^\S\n]*$/u, 'heading-trail', config, accum, {
104
- 'Stage-1': ':', '!ExtToken': '',
105
- });
106
- this.append(token, trail);
107
- }
108
- /** @private */
109
- toString() {
110
- const equals = this.#equals;
111
- return `${equals}${String(this.firstChild)}${equals}${String(this.lastChild)}`;
112
- }
113
- /** @override */
114
- text() {
115
- const equals = this.#equals;
116
- return `${equals}${this.firstChild.text()}${equals}`;
117
- }
118
- /** @private */
119
- getAttribute(key) {
120
- return key === 'padding' ? this.level : super.getAttribute(key);
121
- }
122
- /** @private */
123
- getGaps() {
124
- return this.level;
125
- }
126
- /** @override */
127
- lint(start = this.getAbsoluteIndex(), re) {
128
- const errors = super.lint(start, re), { firstChild, level } = this, innerStr = String(firstChild), quotes = firstChild.childNodes.filter((node) => node.type === 'quote'), boldQuotes = quotes.filter(({ bold }) => bold), italicQuotes = quotes.filter(({ italic }) => italic);
129
- let rect;
130
- if (this.level === 1) {
131
- rect = { start, ...this.getRootNode().posFromIndex(start) };
132
- errors.push((0, lint_1.generateForChild)(firstChild, rect, 'h1', '<h1>'));
133
- }
134
- if (innerStr.startsWith('=') || innerStr.endsWith('=')) {
135
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
136
- errors.push((0, lint_1.generateForChild)(firstChild, rect, 'unbalanced-header', index_1.default.msg('unbalanced $1 in a section header', '"="')));
137
- }
138
- if (this.closest('html-attrs, table-attrs')) {
139
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
140
- errors.push((0, lint_1.generateForSelf)(this, rect, 'parsing-order', 'section header in a HTML tag'));
141
- }
142
- if (boldQuotes.length % 2) {
143
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
144
- errors.push((0, lint_1.generateForChild)(boldQuotes[boldQuotes.length - 1], { ...rect, start: start + level, left: rect.left + level }, 'format-leakage', index_1.default.msg('unbalanced $1 in a section header', 'bold apostrophes')));
145
- }
146
- if (italicQuotes.length % 2) {
147
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
148
- errors.push((0, lint_1.generateForChild)(italicQuotes[italicQuotes.length - 1], { start: start + level }, 'format-leakage', index_1.default.msg('unbalanced $1 in a section header', 'italic apostrophes')));
149
- }
150
- return errors;
151
- }
152
- /** @override */
153
- print() {
154
- const equals = this.#equals;
155
- return super.print({ pre: equals, sep: equals });
156
- }
157
- /** @override */
158
- json() {
159
- const json = super.json();
160
- json['level'] = this.level;
161
- return json;
162
- }
163
- /* NOT FOR BROWSER */
164
- /** @override */
165
- cloneNode() {
166
- const [title, trail] = this.cloneChildNodes();
167
- return debug_1.Shadow.run(() => {
168
- // @ts-expect-error abstract class
169
- const token = new HeadingToken(this.level, [], this.getAttribute('config'));
170
- token.firstChild.safeReplaceWith(title);
171
- token.lastChild.safeReplaceWith(trail);
172
- return token;
173
- });
174
- }
175
- /**
176
- * 设置标题层级
177
- * @param n 标题层级
178
- */
179
- setLevel(n) {
180
- this.#level = Math.min(Math.max(n, 1), 6);
181
- }
182
- /** 移除标题后的不可见内容 */
183
- removeTrail() {
184
- this.lastChild.replaceChildren();
185
- }
186
- };
187
- return HeadingToken = _classThis;
188
- })();
189
- exports.HeadingToken = HeadingToken;
190
- constants_1.classes['HeadingToken'] = __filename;
@@ -1,7 +0,0 @@
1
- import { Token } from './index';
2
- export declare class HiddenToken extends Token {
3
- readonly type = "hidden";
4
- /** @override */
5
- cloneNode(): this;
6
- }
7
- 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.hiddenToken)(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;