wikiparser-node 1.5.2-b → 1.5.2

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 (163) hide show
  1. package/config/.schema.json +172 -0
  2. package/config/enwiki.json +814 -1
  3. package/config/llwiki.json +35 -1
  4. package/config/moegirl.json +44 -1
  5. package/config/zhwiki.json +466 -1
  6. package/dist/addon/table.d.ts +6 -0
  7. package/dist/addon/table.js +564 -0
  8. package/dist/base.d.ts +72 -0
  9. package/dist/base.js +38 -0
  10. package/dist/index.d.ts +30 -0
  11. package/dist/index.js +214 -0
  12. package/dist/internal.d.ts +44 -0
  13. package/dist/lib/element.d.ts +150 -0
  14. package/dist/lib/element.js +613 -0
  15. package/dist/lib/node.d.ts +146 -0
  16. package/dist/lib/node.js +428 -0
  17. package/dist/lib/range.d.ts +104 -0
  18. package/dist/lib/range.js +385 -0
  19. package/dist/lib/ranges.d.ts +26 -0
  20. package/dist/lib/ranges.js +118 -0
  21. package/dist/lib/text.d.ts +62 -0
  22. package/dist/lib/text.js +361 -0
  23. package/dist/lib/title.d.ts +38 -0
  24. package/dist/lib/title.js +166 -0
  25. package/dist/mixin/attributesParent.d.ts +50 -0
  26. package/dist/mixin/attributesParent.js +78 -0
  27. package/dist/mixin/fixed.d.ts +6 -0
  28. package/dist/mixin/fixed.js +30 -0
  29. package/dist/mixin/flagsParent.d.ts +72 -0
  30. package/dist/mixin/flagsParent.js +59 -0
  31. package/dist/mixin/hidden.d.ts +5 -0
  32. package/dist/mixin/hidden.js +24 -0
  33. package/dist/mixin/magicLinkParent.d.ts +40 -0
  34. package/dist/mixin/magicLinkParent.js +42 -0
  35. package/dist/mixin/singleLine.d.ts +6 -0
  36. package/dist/mixin/singleLine.js +26 -0
  37. package/dist/mixin/sol.d.ts +6 -0
  38. package/dist/mixin/sol.js +43 -0
  39. package/dist/mixin/syntax.d.ts +9 -0
  40. package/dist/mixin/syntax.js +50 -0
  41. package/dist/parser/braces.js +131 -0
  42. package/dist/parser/commentAndExt.js +90 -0
  43. package/dist/parser/converter.js +41 -0
  44. package/dist/parser/externalLinks.js +32 -0
  45. package/dist/parser/hrAndDoubleUnderscore.js +41 -0
  46. package/dist/parser/html.js +39 -0
  47. package/dist/parser/links.js +95 -0
  48. package/dist/parser/list.js +98 -0
  49. package/dist/parser/magicLinks.js +43 -0
  50. package/dist/parser/quotes.js +68 -0
  51. package/dist/parser/selector.js +162 -0
  52. package/dist/parser/table.js +124 -0
  53. package/dist/src/arg.d.ts +58 -0
  54. package/dist/src/arg.js +214 -0
  55. package/dist/src/atom.d.ts +12 -0
  56. package/dist/src/atom.js +27 -0
  57. package/dist/src/attribute.d.ts +71 -0
  58. package/dist/src/attribute.js +502 -0
  59. package/dist/src/attributes.d.ts +109 -0
  60. package/dist/src/attributes.js +356 -0
  61. package/dist/src/converter.d.ts +33 -0
  62. package/dist/src/converter.js +134 -0
  63. package/dist/src/converterFlags.d.ts +87 -0
  64. package/dist/src/converterFlags.js +242 -0
  65. package/dist/src/converterRule.d.ts +77 -0
  66. package/dist/src/converterRule.js +209 -0
  67. package/dist/src/extLink.d.ts +43 -0
  68. package/dist/src/extLink.js +186 -0
  69. package/dist/src/gallery.d.ts +54 -0
  70. package/dist/src/gallery.js +139 -0
  71. package/dist/src/heading.d.ts +47 -0
  72. package/dist/src/heading.js +190 -0
  73. package/dist/src/hidden.d.ts +7 -0
  74. package/dist/src/hidden.js +23 -0
  75. package/dist/src/html.d.ts +65 -0
  76. package/dist/src/html.js +358 -0
  77. package/dist/src/imageParameter.d.ts +65 -0
  78. package/dist/src/imageParameter.js +257 -0
  79. package/dist/src/imagemap.d.ts +56 -0
  80. package/dist/src/imagemap.js +150 -0
  81. package/dist/src/imagemapLink.d.ts +31 -0
  82. package/dist/src/imagemapLink.js +93 -0
  83. package/dist/src/index.d.ts +143 -0
  84. package/dist/src/index.js +813 -0
  85. package/dist/src/link/base.d.ts +52 -0
  86. package/dist/src/link/base.js +229 -0
  87. package/dist/src/link/category.d.ts +13 -0
  88. package/dist/src/link/category.js +28 -0
  89. package/dist/src/link/file.d.ts +98 -0
  90. package/dist/src/link/file.js +272 -0
  91. package/dist/src/link/galleryImage.d.ts +32 -0
  92. package/dist/src/link/galleryImage.js +157 -0
  93. package/dist/src/link/index.d.ts +56 -0
  94. package/dist/src/link/index.js +133 -0
  95. package/dist/src/magicLink.d.ts +59 -0
  96. package/dist/src/magicLink.js +223 -0
  97. package/dist/src/nested.d.ts +43 -0
  98. package/dist/src/nested.js +105 -0
  99. package/dist/src/nowiki/base.d.ts +31 -0
  100. package/dist/src/nowiki/base.js +93 -0
  101. package/dist/src/nowiki/comment.d.ts +25 -0
  102. package/dist/src/nowiki/comment.js +76 -0
  103. package/dist/src/nowiki/dd.d.ts +8 -0
  104. package/dist/src/nowiki/dd.js +24 -0
  105. package/dist/src/nowiki/doubleUnderscore.d.ts +18 -0
  106. package/dist/src/nowiki/doubleUnderscore.js +101 -0
  107. package/dist/src/nowiki/hr.d.ts +5 -0
  108. package/dist/src/nowiki/hr.js +63 -0
  109. package/dist/src/nowiki/index.d.ts +16 -0
  110. package/dist/src/nowiki/index.js +27 -0
  111. package/dist/src/nowiki/list.d.ts +16 -0
  112. package/dist/src/nowiki/list.js +97 -0
  113. package/dist/src/nowiki/listBase.d.ts +5 -0
  114. package/dist/src/nowiki/listBase.js +61 -0
  115. package/dist/src/nowiki/noinclude.d.ts +10 -0
  116. package/dist/src/nowiki/noinclude.js +23 -0
  117. package/dist/src/nowiki/quote.d.ts +14 -0
  118. package/dist/src/nowiki/quote.js +131 -0
  119. package/dist/src/onlyinclude.d.ts +16 -0
  120. package/dist/src/onlyinclude.js +57 -0
  121. package/dist/src/paramTag/index.d.ts +37 -0
  122. package/dist/src/paramTag/index.js +77 -0
  123. package/dist/src/paramTag/inputbox.d.ts +8 -0
  124. package/dist/src/paramTag/inputbox.js +22 -0
  125. package/dist/src/parameter.d.ts +70 -0
  126. package/dist/src/parameter.js +264 -0
  127. package/dist/src/pre.d.ts +28 -0
  128. package/dist/src/pre.js +55 -0
  129. package/dist/src/syntax.d.ts +20 -0
  130. package/dist/src/syntax.js +86 -0
  131. package/dist/src/table/base.d.ts +30 -0
  132. package/dist/src/table/base.js +132 -0
  133. package/dist/src/table/index.d.ts +233 -0
  134. package/dist/src/table/index.js +396 -0
  135. package/dist/src/table/td.d.ts +86 -0
  136. package/dist/src/table/td.js +350 -0
  137. package/dist/src/table/tr.d.ts +32 -0
  138. package/dist/src/table/tr.js +58 -0
  139. package/dist/src/table/trBase.d.ts +53 -0
  140. package/dist/src/table/trBase.js +152 -0
  141. package/dist/src/tagPair/ext.d.ts +32 -0
  142. package/dist/src/tagPair/ext.js +203 -0
  143. package/dist/src/tagPair/include.d.ts +35 -0
  144. package/dist/src/tagPair/include.js +74 -0
  145. package/dist/src/tagPair/index.d.ts +27 -0
  146. package/dist/src/tagPair/index.js +128 -0
  147. package/dist/src/transclude.d.ts +167 -0
  148. package/dist/src/transclude.js +717 -0
  149. package/dist/util/constants.js +28 -0
  150. package/dist/util/debug.js +88 -0
  151. package/dist/util/diff.js +83 -0
  152. package/dist/util/lint.js +31 -0
  153. package/dist/util/string.js +54 -0
  154. package/errors/README +1 -0
  155. package/package.json +14 -27
  156. package/printed/README +1 -0
  157. package/bundle/bundle.min.js +0 -37
  158. package/extensions/dist/base.js +0 -64
  159. package/extensions/dist/editor.js +0 -159
  160. package/extensions/dist/highlight.js +0 -59
  161. package/extensions/dist/lint.js +0 -60
  162. package/extensions/editor.css +0 -63
  163. package/extensions/ui.css +0 -141
@@ -0,0 +1,186 @@
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
+ // @ts-expect-error abstract class
87
+ this.insertAt(new magicLink_1.MagicLinkToken(url, true, config, accum));
88
+ this.#space = space;
89
+ if (text) {
90
+ const inner = new index_2.Token(text, config, accum, {
91
+ 'Stage-7': ':', ConverterToken: ':',
92
+ });
93
+ inner.type = 'ext-link-text';
94
+ inner.setAttribute('stage', constants_1.MAX_STAGE - 1);
95
+ this.insertAt(inner);
96
+ }
97
+ /* NOT FOR BROWSER */
98
+ this.protectChildren(0);
99
+ }
100
+ /** @private */
101
+ toString() {
102
+ if (this.length === 1) {
103
+ return `[${super.toString()}${this.#space}]`;
104
+ }
105
+ /* NOT FOR BROWSER */
106
+ this.#correct();
107
+ (0, string_1.normalizeSpace)(this.lastChild);
108
+ /* NOT FOR BROWSER END */
109
+ return `[${super.toString(this.#space)}]`;
110
+ }
111
+ /** @override */
112
+ text() {
113
+ /* NOT FOR BROWSER */
114
+ (0, string_1.normalizeSpace)(this.childNodes[1]);
115
+ /* NOT FOR BROWSER END */
116
+ return `[${super.text(' ')}]`;
117
+ }
118
+ /** @private */
119
+ getAttribute(key) {
120
+ return key === 'padding' ? 1 : super.getAttribute(key);
121
+ }
122
+ /** @private */
123
+ getGaps() {
124
+ /* NOT FOR BROWSER */
125
+ this.#correct();
126
+ /* NOT FOR BROWSER END */
127
+ return this.#space.length;
128
+ }
129
+ /** @override */
130
+ lint(start = this.getAbsoluteIndex()) {
131
+ const errors = super.lint(start);
132
+ if (this.length === 1 && this.closest('heading-title')) {
133
+ errors.push((0, lint_1.generateForSelf)(this, { start }, 'var-anchor', 'variable anchor in a section header'));
134
+ }
135
+ return errors;
136
+ }
137
+ /** @override */
138
+ print() {
139
+ return super.print(this.length === 1 ? { pre: '[', post: `${this.#space}]` } : { pre: '[', sep: this.#space, post: ']' });
140
+ }
141
+ /* NOT FOR BROWSER */
142
+ /** @override */
143
+ cloneNode() {
144
+ const [url, text] = this.cloneChildNodes();
145
+ return debug_1.Shadow.run(() => {
146
+ // @ts-expect-error abstract class
147
+ const token = new ExtLinkToken(undefined, '', '', this.getAttribute('config'));
148
+ token.firstChild.safeReplaceWith(url);
149
+ if (text) {
150
+ token.insertAt(text);
151
+ }
152
+ return token;
153
+ });
154
+ }
155
+ /** 修正空白字符 */
156
+ #correct() {
157
+ if (!this.#space
158
+ && this.length > 1
159
+ // 都替换成`<`肯定不对,但无妨
160
+ && /^[^[\]<>"{\0-\x1F\x7F\p{Zs}\uFFFD]/u.test(this.lastChild.text().replace(/&[lg]t;/u, '<'))) {
161
+ this.#space = ' ';
162
+ }
163
+ }
164
+ /**
165
+ * 设置链接显示文字
166
+ * @param str 链接显示文字
167
+ */
168
+ setLinkText(str) {
169
+ const root = index_1.default.parse(str, this.getAttribute('include'), 7, this.getAttribute('config'));
170
+ if (this.length === 1) {
171
+ root.type = 'ext-link-text';
172
+ root.setAttribute('acceptable', {
173
+ 'Stage-7': ':', ConverterToken: ':',
174
+ });
175
+ this.insertAt(root);
176
+ }
177
+ else {
178
+ this.lastChild.replaceChildren(...root.childNodes);
179
+ }
180
+ this.#space ||= ' ';
181
+ }
182
+ };
183
+ return ExtLinkToken = _classThis;
184
+ })();
185
+ exports.ExtLinkToken = ExtLinkToken;
186
+ constants_1.classes['ExtLinkToken'] = __filename;
@@ -0,0 +1,54 @@
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): 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
+ }
@@ -0,0 +1,139 @@
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()) {
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: '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));
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;
@@ -0,0 +1,47 @@
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): 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
+ }
@@ -0,0 +1,190 @@
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();
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()) {
128
+ 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);
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;
@@ -0,0 +1,7 @@
1
+ import { Token } from './index';
2
+ export declare class HiddenToken extends Token {
3
+ readonly type = "hidden";
4
+ /** @override */
5
+ cloneNode(): this;
6
+ }
7
+ export {};
@@ -0,0 +1,23 @@
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;