wikiparser-node 1.3.3-b → 1.3.3

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 (154) hide show
  1. package/config/.schema.json +172 -0
  2. package/config/llwiki.json +35 -1
  3. package/config/moegirl.json +44 -1
  4. package/config/zhwiki.json +466 -1
  5. package/dist/addon/table.d.ts +6 -0
  6. package/dist/addon/table.js +564 -0
  7. package/dist/base.d.ts +45 -0
  8. package/dist/bin/toc.js +18 -0
  9. package/dist/index.d.ts +31 -0
  10. package/dist/index.js +209 -0
  11. package/dist/internal.d.ts +44 -0
  12. package/dist/lib/element.d.ts +155 -0
  13. package/dist/lib/element.js +634 -0
  14. package/dist/lib/node.d.ts +146 -0
  15. package/dist/lib/node.js +419 -0
  16. package/dist/lib/range.d.ts +104 -0
  17. package/dist/lib/range.js +385 -0
  18. package/dist/lib/ranges.d.ts +26 -0
  19. package/dist/lib/ranges.js +117 -0
  20. package/dist/lib/text.d.ts +62 -0
  21. package/dist/lib/text.js +248 -0
  22. package/dist/lib/title.d.ts +38 -0
  23. package/dist/lib/title.js +162 -0
  24. package/dist/mixin/attributesParent.js +94 -0
  25. package/dist/mixin/fixed.js +32 -0
  26. package/dist/mixin/flagsParent.js +70 -0
  27. package/dist/mixin/hidden.js +26 -0
  28. package/dist/mixin/magicLinkParent.js +41 -0
  29. package/dist/mixin/singleLine.js +25 -0
  30. package/dist/mixin/sol.js +43 -0
  31. package/dist/mixin/syntax.js +56 -0
  32. package/dist/parser/braces.js +121 -0
  33. package/dist/parser/commentAndExt.js +69 -0
  34. package/dist/parser/converter.js +40 -0
  35. package/dist/parser/externalLinks.js +28 -0
  36. package/dist/parser/hrAndDoubleUnderscore.js +38 -0
  37. package/dist/parser/html.js +36 -0
  38. package/dist/parser/links.js +94 -0
  39. package/dist/parser/list.js +59 -0
  40. package/dist/parser/magicLinks.js +40 -0
  41. package/dist/parser/quotes.js +67 -0
  42. package/dist/parser/selector.js +162 -0
  43. package/dist/parser/table.js +112 -0
  44. package/dist/src/arg.d.ts +58 -0
  45. package/dist/src/arg.js +189 -0
  46. package/dist/src/atom.d.ts +12 -0
  47. package/dist/src/atom.js +27 -0
  48. package/dist/src/attribute.d.ts +87 -0
  49. package/dist/src/attribute.js +392 -0
  50. package/dist/src/attributes.d.ts +107 -0
  51. package/dist/src/attributes.js +341 -0
  52. package/dist/src/converter.d.ts +52 -0
  53. package/dist/src/converter.js +79 -0
  54. package/dist/src/converterFlags.d.ts +87 -0
  55. package/dist/src/converterFlags.js +224 -0
  56. package/dist/src/converterRule.d.ts +81 -0
  57. package/dist/src/converterRule.js +212 -0
  58. package/dist/src/extLink.d.ts +54 -0
  59. package/dist/src/extLink.js +122 -0
  60. package/dist/src/gallery.d.ts +55 -0
  61. package/dist/src/gallery.js +122 -0
  62. package/dist/src/heading.d.ts +74 -0
  63. package/dist/src/heading.js +127 -0
  64. package/dist/src/hidden.d.ts +22 -0
  65. package/dist/src/hidden.js +23 -0
  66. package/dist/src/html.d.ts +101 -0
  67. package/dist/src/html.js +227 -0
  68. package/dist/src/imageParameter.d.ts +66 -0
  69. package/dist/src/imageParameter.js +247 -0
  70. package/dist/src/imagemap.d.ts +57 -0
  71. package/dist/src/imagemap.js +148 -0
  72. package/dist/src/imagemapLink.d.ts +59 -0
  73. package/dist/src/imagemapLink.js +40 -0
  74. package/dist/src/index.d.ts +146 -0
  75. package/dist/src/index.js +777 -0
  76. package/dist/src/link/base.d.ts +52 -0
  77. package/dist/src/link/base.js +209 -0
  78. package/dist/src/link/category.d.ts +13 -0
  79. package/dist/src/link/category.js +29 -0
  80. package/dist/src/link/file.d.ts +96 -0
  81. package/dist/src/link/file.js +255 -0
  82. package/dist/src/link/galleryImage.d.ts +44 -0
  83. package/dist/src/link/galleryImage.js +106 -0
  84. package/dist/src/link/index.d.ts +53 -0
  85. package/dist/src/link/index.js +123 -0
  86. package/dist/src/magicLink.d.ts +70 -0
  87. package/dist/src/magicLink.js +147 -0
  88. package/dist/src/nested.d.ts +44 -0
  89. package/dist/src/nested.js +87 -0
  90. package/dist/src/nowiki/base.d.ts +47 -0
  91. package/dist/src/nowiki/base.js +42 -0
  92. package/dist/src/nowiki/comment.d.ts +40 -0
  93. package/dist/src/nowiki/comment.js +67 -0
  94. package/dist/src/nowiki/dd.d.ts +8 -0
  95. package/dist/src/nowiki/dd.js +25 -0
  96. package/dist/src/nowiki/doubleUnderscore.d.ts +45 -0
  97. package/dist/src/nowiki/doubleUnderscore.js +50 -0
  98. package/dist/src/nowiki/hr.d.ts +31 -0
  99. package/dist/src/nowiki/hr.js +14 -0
  100. package/dist/src/nowiki/index.d.ts +16 -0
  101. package/dist/src/nowiki/index.js +21 -0
  102. package/dist/src/nowiki/list.d.ts +30 -0
  103. package/dist/src/nowiki/list.js +48 -0
  104. package/dist/src/nowiki/listBase.d.ts +19 -0
  105. package/dist/src/nowiki/listBase.js +12 -0
  106. package/dist/src/nowiki/noinclude.d.ts +26 -0
  107. package/dist/src/nowiki/noinclude.js +25 -0
  108. package/dist/src/nowiki/quote.d.ts +23 -0
  109. package/dist/src/nowiki/quote.js +45 -0
  110. package/dist/src/onlyinclude.d.ts +16 -0
  111. package/dist/src/onlyinclude.js +57 -0
  112. package/dist/src/paramTag/index.d.ts +37 -0
  113. package/dist/src/paramTag/index.js +68 -0
  114. package/dist/src/paramTag/inputbox.d.ts +8 -0
  115. package/dist/src/paramTag/inputbox.js +23 -0
  116. package/dist/src/parameter.d.ts +85 -0
  117. package/dist/src/parameter.js +205 -0
  118. package/dist/src/pre.d.ts +28 -0
  119. package/dist/src/pre.js +51 -0
  120. package/dist/src/syntax.d.ts +28 -0
  121. package/dist/src/syntax.js +34 -0
  122. package/dist/src/table/base.d.ts +53 -0
  123. package/dist/src/table/base.js +78 -0
  124. package/dist/src/table/index.d.ts +229 -0
  125. package/dist/src/table/index.js +379 -0
  126. package/dist/src/table/td.d.ts +104 -0
  127. package/dist/src/table/td.js +261 -0
  128. package/dist/src/table/tr.d.ts +32 -0
  129. package/dist/src/table/tr.js +56 -0
  130. package/dist/src/table/trBase.d.ts +54 -0
  131. package/dist/src/table/trBase.js +159 -0
  132. package/dist/src/tagPair/ext.d.ts +56 -0
  133. package/dist/src/tagPair/ext.js +142 -0
  134. package/dist/src/tagPair/include.d.ts +53 -0
  135. package/dist/src/tagPair/include.js +63 -0
  136. package/dist/src/tagPair/index.d.ts +48 -0
  137. package/dist/src/tagPair/index.js +93 -0
  138. package/dist/src/transclude.d.ts +167 -0
  139. package/dist/src/transclude.js +690 -0
  140. package/dist/util/constants.js +108 -0
  141. package/dist/util/debug.js +64 -0
  142. package/dist/util/diff.js +72 -0
  143. package/dist/util/lint.js +46 -0
  144. package/dist/util/string.js +61 -0
  145. package/errors/README +1 -0
  146. package/package.json +12 -32
  147. package/printed/README +1 -0
  148. package/bundle/bundle.min.js +0 -36
  149. package/extensions/dist/base.js +0 -68
  150. package/extensions/dist/editor.js +0 -159
  151. package/extensions/dist/highlight.js +0 -30
  152. package/extensions/dist/lint.js +0 -48
  153. package/extensions/editor.css +0 -63
  154. package/extensions/ui.css +0 -114
@@ -0,0 +1,248 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AstText = void 0;
4
+ const constants_1 = require("../util/constants");
5
+ const Parser = require("../index");
6
+ const node_1 = require("./node");
7
+ const errorSyntax = /<\s*\/?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*\])|(?<=^|\])([^[]*?)\]+|\]{2,}|https?[:/]\/+/giu, errorSyntaxUrl = /<\s*\/?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*\])|(?<=^|\])([^[]*?)\]+|\]{2,}/giu, disallowedTags = [
8
+ 'html',
9
+ 'base',
10
+ 'head',
11
+ 'style',
12
+ 'title',
13
+ 'body',
14
+ 'menu',
15
+ 'a',
16
+ 'area',
17
+ 'audio',
18
+ 'img',
19
+ 'map',
20
+ 'track',
21
+ 'video',
22
+ 'embed',
23
+ 'iframe',
24
+ 'object',
25
+ 'picture',
26
+ 'source',
27
+ 'canvas',
28
+ 'script',
29
+ 'col',
30
+ 'colgroup',
31
+ 'tbody',
32
+ 'tfoot',
33
+ 'thead',
34
+ 'button',
35
+ 'datalist',
36
+ 'fieldset',
37
+ 'form',
38
+ 'input',
39
+ 'label',
40
+ 'legend',
41
+ 'meter',
42
+ 'optgroup',
43
+ 'option',
44
+ 'output',
45
+ 'progress',
46
+ 'select',
47
+ 'textarea',
48
+ 'details',
49
+ 'dialog',
50
+ 'slot',
51
+ 'template',
52
+ 'dir',
53
+ 'frame',
54
+ 'frameset',
55
+ 'marquee',
56
+ 'param',
57
+ 'xmp',
58
+ ];
59
+ /** 文本节点 */
60
+ class AstText extends node_1.AstNode {
61
+ type = 'text';
62
+ data = '';
63
+ /* NOT FOR BROWSER */
64
+ /** 文本长度 */
65
+ get length() {
66
+ return this.data.length;
67
+ }
68
+ /* NOT FOR BROWSER END */
69
+ /** @param text 包含文本 */
70
+ constructor(text) {
71
+ super();
72
+ Object.defineProperties(this, {
73
+ data: { value: text, writable: false },
74
+ childNodes: { enumerable: false, configurable: false },
75
+ type: { enumerable: false, writable: false, configurable: false },
76
+ });
77
+ }
78
+ /** @private */
79
+ toString() {
80
+ return this.data;
81
+ }
82
+ /** 可见部分 */
83
+ text() {
84
+ return this.data;
85
+ }
86
+ /**
87
+ * @override
88
+ * @param start
89
+ * @throws `Error` 孤立文本节点
90
+ */
91
+ lint(start = this.getAbsoluteIndex()) {
92
+ const { data, parentNode, nextSibling, previousSibling } = this;
93
+ if (!parentNode) {
94
+ throw new Error('无法对孤立文本节点进行语法分析!');
95
+ }
96
+ const { NowikiToken } = require('../src/nowiki');
97
+ const { type, name } = parentNode, nextType = nextSibling?.type, previousType = previousSibling?.type;
98
+ let errorRegex;
99
+ if (type === 'ext-inner' && (name === 'pre' || parentNode instanceof NowikiToken)) {
100
+ errorRegex = new RegExp(`<\\s*\\/?(${name})\\b`, 'giu');
101
+ }
102
+ else if (type === 'free-ext-link'
103
+ || type === 'ext-link-url'
104
+ || type === 'image-parameter' && name === 'link'
105
+ || type === 'attr-value') {
106
+ errorRegex = errorSyntaxUrl;
107
+ }
108
+ else {
109
+ errorRegex = errorSyntax;
110
+ }
111
+ const errors = [...data.matchAll(errorRegex)], { ext, html } = this.getRootNode().getAttribute('config');
112
+ if (errors.length > 0) {
113
+ const root = this.getRootNode(), { top, left } = root.posFromIndex(start), tags = new Set(['onlyinclude', 'noinclude', 'includeonly', ext, html, disallowedTags].flat(2));
114
+ return errors
115
+ .map(({ 0: error, 1: tag, 2: prefix, index }) => {
116
+ if (prefix) {
117
+ const { length } = prefix;
118
+ index += length;
119
+ error = error.slice(length);
120
+ }
121
+ const startIndex = start + index, lines = data.slice(0, index).split('\n'), startLine = lines.length + top - 1, line = lines.at(-1), startCol = lines.length === 1 ? left + line.length : line.length, { 0: char, length } = error, endIndex = startIndex + length, rootStr = String(root), nextChar = rootStr[endIndex], previousChar = rootStr[startIndex - 1], severity = length > 1 && (char !== '<' || /[\s/>]/u.test(nextChar ?? ''))
122
+ || char === '{' && (nextChar === char || previousChar === '-')
123
+ || char === '}' && (previousChar === char || nextChar === '-')
124
+ || char === '[' && (nextChar === char
125
+ || type === 'ext-link-text'
126
+ || !data.slice(index + 1).trim() && nextType === 'free-ext-link')
127
+ || char === ']' && (previousChar === char
128
+ || !data.slice(0, index).trim() && previousType === 'free-ext-link')
129
+ ? 'error'
130
+ : 'warning';
131
+ return (char !== '<' || tags.has(tag.toLowerCase())) && {
132
+ message: Parser.msg('lonely "$1"', char === 'h' ? error : char),
133
+ severity,
134
+ startIndex,
135
+ endIndex,
136
+ startLine,
137
+ endLine: startLine,
138
+ startCol,
139
+ endCol: startCol + length,
140
+ };
141
+ }).filter(Boolean);
142
+ }
143
+ return [];
144
+ }
145
+ /**
146
+ * 修改内容
147
+ * @param text 新内容
148
+ */
149
+ #setData(text) {
150
+ const { data } = this, e = new Event('text', { bubbles: true });
151
+ this.setAttribute('data', text);
152
+ if (data !== text) {
153
+ this.dispatchEvent(e, { type: 'text', oldText: data });
154
+ }
155
+ }
156
+ /**
157
+ * 替换字符串
158
+ * @param text 替换的字符串
159
+ */
160
+ replaceData(text) {
161
+ this.#setData(text);
162
+ }
163
+ /** @override */
164
+ print() {
165
+ const entities = { '&': 'amp', '<': 'lt', '>': 'gt' };
166
+ return this.data.replace(/[&<>]/gu, p => `&${entities[p]};`);
167
+ }
168
+ /* NOT FOR BROWSER */
169
+ /** 复制 */
170
+ cloneNode() {
171
+ return new AstText(this.data);
172
+ }
173
+ /**
174
+ * 在后方添加字符串
175
+ * @param text 添加的字符串
176
+ */
177
+ appendData(text) {
178
+ this.#setData(this.data + text);
179
+ }
180
+ /**
181
+ * 删减字符串
182
+ * @param offset 起始位置
183
+ * @param count 删减字符数
184
+ */
185
+ deleteData(offset, count) {
186
+ this.#setData(this.data.slice(0, offset) + (offset < 0 && offset + count >= 0 ? '' : this.data.slice(offset + count)));
187
+ }
188
+ /**
189
+ * 插入字符串
190
+ * @param offset 插入位置
191
+ * @param text 待插入的字符串
192
+ */
193
+ insertData(offset, text) {
194
+ this.#setData(this.data.slice(0, offset) + text + this.data.slice(offset));
195
+ }
196
+ /**
197
+ * 提取子串
198
+ * @param offset 起始位置
199
+ * @param count 字符数
200
+ */
201
+ substringData(offset, count) {
202
+ return this.data.substr(offset, count);
203
+ }
204
+ /**
205
+ * 将文本子节点分裂为两部分
206
+ * @param offset 分裂位置
207
+ * @throws `RangeError` 错误的断开位置
208
+ * @throws `Error` 没有父节点
209
+ */
210
+ splitText(offset) {
211
+ if (offset > this.length || offset < -this.length) {
212
+ throw new RangeError(`错误的断开位置:${offset}`);
213
+ }
214
+ const { parentNode, data } = this;
215
+ if (!parentNode) {
216
+ throw new Error('待分裂的文本节点没有父节点!');
217
+ }
218
+ const newText = new AstText(data.slice(offset)), childNodes = [...parentNode.childNodes];
219
+ this.setAttribute('data', data.slice(0, offset));
220
+ childNodes.splice(childNodes.indexOf(this) + 1, 0, newText);
221
+ newText.setAttribute('parentNode', parentNode);
222
+ parentNode.setAttribute('childNodes', childNodes);
223
+ return newText;
224
+ }
225
+ /** @private */
226
+ getRelativeIndex(j) {
227
+ if (j === undefined) {
228
+ return super.getRelativeIndex();
229
+ }
230
+ else if (j < 0 || j > this.length) {
231
+ throw new RangeError(`超出文本长度范围!`);
232
+ }
233
+ return j;
234
+ }
235
+ /** 转义 `=` */
236
+ escape() {
237
+ const { TranscludeToken } = require('../src/transclude');
238
+ for (let i = this.data.lastIndexOf('='); i >= 0; i = this.data.lastIndexOf('=', i - 1)) {
239
+ if (i < this.length - 1) {
240
+ this.splitText(i + 1);
241
+ }
242
+ this.after(new TranscludeToken('=', [], this.parentNode.getAttribute('config')));
243
+ this.setAttribute('data', this.data.slice(0, i));
244
+ }
245
+ }
246
+ }
247
+ exports.AstText = AstText;
248
+ constants_1.classes['AstText'] = __filename;
@@ -0,0 +1,38 @@
1
+ import * as Parser from '../index';
2
+ /** MediaWiki页面标题对象 */
3
+ export declare class Title {
4
+ #private;
5
+ readonly valid: boolean;
6
+ ns: number;
7
+ fragment: string | undefined;
8
+ interwiki: string;
9
+ /** 不含命名空间的标题主体部分 */
10
+ get main(): string;
11
+ set main(title: string);
12
+ /** 命名空间前缀 */
13
+ get prefix(): string;
14
+ /** 完整标题 */
15
+ get title(): string;
16
+ /** 扩展名 */
17
+ get extension(): string | undefined;
18
+ set extension(extension: string | undefined);
19
+ /**
20
+ * @param title 标题(含或不含命名空间前缀)
21
+ * @param defaultNs 命名空间
22
+ * @param decode 是否需要解码
23
+ * @param selfLink 是否允许selfLink
24
+ */
25
+ constructor(title: string, defaultNs?: number, config?: Parser.Config, decode?: boolean, selfLink?: boolean);
26
+ /** 执行单向转换 */
27
+ autoConvert(): void;
28
+ /** 转换为主页面 */
29
+ toSubjectPage(): void;
30
+ /** 转换为讨论页面 */
31
+ toTalkPage(): void;
32
+ /** 是否是讨论页 */
33
+ isTalkPage(): boolean;
34
+ /** 转换为上一级页面 */
35
+ toBasePage(): void;
36
+ /** 转换为根页面 */
37
+ toRootPage(): void;
38
+ }
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Title = void 0;
4
+ const string_1 = require("../util/string");
5
+ const constants_1 = require("../util/constants");
6
+ const Parser = require("../index");
7
+ /** MediaWiki页面标题对象 */
8
+ class Title {
9
+ valid;
10
+ ns;
11
+ fragment;
12
+ /** @private */
13
+ encoded = false;
14
+ /* NOT FOR BROWSER */
15
+ #namespaces;
16
+ #main;
17
+ interwiki = '';
18
+ /** @private */
19
+ conversionTable = new Map();
20
+ /** @private */
21
+ redirects = new Map();
22
+ /** 不含命名空间的标题主体部分 */
23
+ get main() {
24
+ return this.#main;
25
+ }
26
+ set main(title) {
27
+ title = title.replaceAll('_', ' ').trim();
28
+ this.#main = title && `${title[0].toUpperCase()}${title.slice(1)}`;
29
+ }
30
+ /** 命名空间前缀 */
31
+ get prefix() {
32
+ const namespace = this.#namespaces[this.ns];
33
+ return `${namespace}${namespace && ':'}`;
34
+ }
35
+ /** 完整标题 */
36
+ get title() {
37
+ const prefix = `${this.interwiki}${this.interwiki && ':'}${this.prefix}`;
38
+ let title = `${prefix}${this.main}`.replaceAll(' ', '_');
39
+ const redirected = this.redirects.get(title);
40
+ if (redirected) {
41
+ return redirected;
42
+ }
43
+ this.autoConvert();
44
+ title = `${prefix}${this.main}`.replaceAll(' ', '_');
45
+ return this.redirects.get(title) ?? title;
46
+ }
47
+ /** 扩展名 */
48
+ get extension() {
49
+ const { main } = this, i = main.lastIndexOf('.');
50
+ return i === -1 ? undefined : main.slice(i + 1).toLowerCase();
51
+ }
52
+ set extension(extension) {
53
+ const { main } = this, i = main.lastIndexOf('.');
54
+ this.main = `${i === -1 ? main : main.slice(0, i)}.${extension}`;
55
+ }
56
+ /* NOT FOR BROWSER END */
57
+ /**
58
+ * @param title 标题(含或不含命名空间前缀)
59
+ * @param defaultNs 命名空间
60
+ * @param decode 是否需要解码
61
+ * @param selfLink 是否允许selfLink
62
+ */
63
+ constructor(title, defaultNs = 0, config = Parser.getConfig(), decode = false, selfLink = false) {
64
+ Object.defineProperties(this, {
65
+ encoded: { enumerable: false },
66
+ conversionTable: { enumerable: false },
67
+ redirects: { enumerable: false },
68
+ });
69
+ const { namespaces, nsid, } = config;
70
+ this.#namespaces = namespaces;
71
+ title = (0, string_1.decodeHtml)(title);
72
+ if (decode && title.includes('%')) {
73
+ try {
74
+ const encoded = /%(?!21|3[ce]|5[bd]|7[b-d])[\da-f]{2}/iu.test(title);
75
+ title = decodeURIComponent(title);
76
+ this.encoded = encoded;
77
+ }
78
+ catch { }
79
+ }
80
+ title = title.replaceAll('_', ' ').trim();
81
+ let ns = defaultNs;
82
+ if (title.startsWith(':')) {
83
+ ns = 0;
84
+ title = title.slice(1).trim();
85
+ }
86
+ const iw = defaultNs ? null : Parser.isInterwiki(title, config);
87
+ if (iw) {
88
+ this.interwiki = iw[1].toLowerCase();
89
+ title = title.slice(iw.indices[0][1]);
90
+ }
91
+ const m = title.split(':');
92
+ if (m.length > 1) {
93
+ const id = nsid[m[0].trim().toLowerCase()];
94
+ if (id !== undefined) {
95
+ ns = id;
96
+ title = m.slice(1).join(':').trim();
97
+ }
98
+ }
99
+ this.ns = ns;
100
+ const i = title.indexOf('#');
101
+ if (i !== -1) {
102
+ let fragment = title.slice(i + 1).trimEnd();
103
+ if (fragment.includes('%')) {
104
+ try {
105
+ fragment = decodeURIComponent(fragment);
106
+ }
107
+ catch { }
108
+ }
109
+ else if (fragment.includes('.')) {
110
+ try {
111
+ fragment = decodeURIComponent(fragment.replaceAll('.', '%'));
112
+ }
113
+ catch { }
114
+ }
115
+ this.fragment = fragment;
116
+ title = title.slice(0, i).trim();
117
+ }
118
+ this.valid = Boolean(title
119
+ || this.interwiki
120
+ || selfLink && this.fragment !== undefined) && !/\0\d+[eh!+-]\x7F|[<>[\]{}|]|%[\da-f]{2}/iu.test(title);
121
+ this.main = title;
122
+ }
123
+ /* NOT FOR BROWSER */
124
+ /** @private */
125
+ toString() {
126
+ return `${this.title}${this.fragment === undefined ? '' : `#${this.fragment}`}`;
127
+ }
128
+ /** 执行单向转换 */
129
+ autoConvert() {
130
+ const { conversionTable } = this;
131
+ if (conversionTable.size > 0) {
132
+ const regex = new RegExp([...conversionTable.keys()].sort().reverse().map(string_1.escapeRegExp).join('|'), 'gu');
133
+ this.main = this.main.replace(regex, p => conversionTable.get(p));
134
+ }
135
+ }
136
+ /** 转换为主页面 */
137
+ toSubjectPage() {
138
+ if (this.isTalkPage()) {
139
+ this.ns--;
140
+ }
141
+ }
142
+ /** 转换为讨论页面 */
143
+ toTalkPage() {
144
+ if (!this.isTalkPage()) {
145
+ this.ns++;
146
+ }
147
+ }
148
+ /** 是否是讨论页 */
149
+ isTalkPage() {
150
+ return this.ns % 2 === 1;
151
+ }
152
+ /** 转换为上一级页面 */
153
+ toBasePage() {
154
+ this.main = this.main.replace(/\/[^/]*$/u, '');
155
+ }
156
+ /** 转换为根页面 */
157
+ toRootPage() {
158
+ this.main = this.main.replace(/\/.*/u, '');
159
+ }
160
+ }
161
+ exports.Title = Title;
162
+ constants_1.classes['Title'] = __filename;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.attributesParent = void 0;
4
+ const constants_1 = require("../util/constants");
5
+ /**
6
+ * 子节点含有AttributesToken的类
7
+ * @param constructor 基类
8
+ * @param i AttributesToken子节点的位置
9
+ */
10
+ const attributesParent = (constructor, i = 0) => {
11
+ /** 子节点含有AttributesToken的类 */
12
+ class AttributesParent extends constructor {
13
+ /** AttributesToken子节点 */
14
+ get #attributesChild() {
15
+ return this.childNodes.at(i);
16
+ }
17
+ /** getAttrs()方法的getter写法 */
18
+ get attributes() {
19
+ return this.#attributesChild.attributes;
20
+ }
21
+ set attributes(attributes) {
22
+ this.#attributesChild.attributes = attributes;
23
+ }
24
+ /** 以字符串表示的class属性 */
25
+ get className() {
26
+ return this.#attributesChild.className;
27
+ }
28
+ set className(className) {
29
+ this.#attributesChild.className = className;
30
+ }
31
+ /** 以Set表示的class属性 */
32
+ get classList() {
33
+ return this.#attributesChild.classList;
34
+ }
35
+ set classList(classList) {
36
+ this.#attributesChild.classList = classList;
37
+ }
38
+ /** id属性 */
39
+ get id() {
40
+ return this.#attributesChild.id;
41
+ }
42
+ set id(id) {
43
+ this.#attributesChild.id = id;
44
+ }
45
+ /**
46
+ * AttributesToken子节点是否具有某属性
47
+ * @param key 属性键
48
+ */
49
+ hasAttr(key) {
50
+ return this.#attributesChild.hasAttr(key);
51
+ }
52
+ /**
53
+ * 获取AttributesToken子节点的属性
54
+ * @param key 属性键
55
+ */
56
+ getAttr(key) {
57
+ return this.#attributesChild.getAttr(key);
58
+ }
59
+ /** 列举AttributesToken子节点的属性键 */
60
+ getAttrNames() {
61
+ return this.#attributesChild.getAttrNames();
62
+ }
63
+ /** 获取AttributesToken子节点的全部标签属性 */
64
+ getAttrs() {
65
+ return this.#attributesChild.getAttrs();
66
+ }
67
+ /**
68
+ * 对AttributesToken子节点设置属性
69
+ * @param key 属性键
70
+ * @param value 属性值
71
+ */
72
+ setAttr(key, value) {
73
+ this.#attributesChild.setAttr(key, value);
74
+ }
75
+ /**
76
+ * 移除AttributesToken子节点的某属性
77
+ * @param key 属性键
78
+ */
79
+ removeAttr(key) {
80
+ this.#attributesChild.removeAttr(key);
81
+ }
82
+ /**
83
+ * 开关AttributesToken子节点的某属性
84
+ * @param key 属性键
85
+ * @param force 强制开启或关闭
86
+ */
87
+ toggleAttr(key, force) {
88
+ this.#attributesChild.toggleAttr(key, force);
89
+ }
90
+ }
91
+ return AttributesParent;
92
+ };
93
+ exports.attributesParent = attributesParent;
94
+ constants_1.mixins['attributesParent'] = __filename;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fixed = void 0;
4
+ const debug_1 = require("../util/debug");
5
+ const constants_1 = require("../util/constants");
6
+ /**
7
+ * 不可增删子节点的类
8
+ * @param constructor 基类
9
+ */
10
+ const fixed = (constructor) => {
11
+ /** 不可增删子节点的类 */
12
+ class FixedToken extends constructor {
13
+ static fixed = true;
14
+ /**
15
+ * @override
16
+ * @throws `Error` 不可用
17
+ */
18
+ removeAt() {
19
+ throw new Error(`${this.constructor.name} 不可删除元素!`);
20
+ }
21
+ /** @ignore */
22
+ insertAt(token, i) {
23
+ if (debug_1.Shadow.running) {
24
+ return super.insertAt(token, i);
25
+ }
26
+ throw new Error(`${this.constructor.name} 不可插入元素!`);
27
+ }
28
+ }
29
+ return FixedToken;
30
+ };
31
+ exports.fixed = fixed;
32
+ constants_1.mixins['fixed'] = __filename;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.flagsParent = void 0;
4
+ const constants_1 = require("../util/constants");
5
+ /**
6
+ * ConverterToken
7
+ * @param constructor 基类
8
+ */
9
+ const flagsParent = (constructor) => {
10
+ /** 子节点含有ConverterFlagsToken的类 */
11
+ class FlagsParent extends constructor {
12
+ /** 所有转换类型标记 */
13
+ get flags() {
14
+ return this.firstChild.flags;
15
+ }
16
+ set flags(value) {
17
+ this.firstChild.flags = value;
18
+ }
19
+ /** 获取所有转换类型标记 */
20
+ getAllFlags() {
21
+ return this.firstChild.getAllFlags();
22
+ }
23
+ /** 获取有效的转换类型标记 */
24
+ getEffectiveFlags() {
25
+ return this.firstChild.getEffectiveFlags();
26
+ }
27
+ /** 获取未知的转换类型标记 */
28
+ getUnknownFlags() {
29
+ return this.firstChild.getUnknownFlags();
30
+ }
31
+ /**
32
+ * 是否具有某转换类型标记
33
+ * @param flag 转换类型标记
34
+ */
35
+ hasFlag(flag) {
36
+ return this.firstChild.hasFlag(flag);
37
+ }
38
+ /**
39
+ * 是否具有某有效的转换类型标记
40
+ * @param flag 转换类型标记
41
+ */
42
+ hasEffectiveFlag(flag) {
43
+ return this.firstChild.hasEffectiveFlag(flag);
44
+ }
45
+ /**
46
+ * 移除转换类型标记
47
+ * @param flag 转换类型标记
48
+ */
49
+ removeFlag(flag) {
50
+ this.firstChild.removeFlag(flag);
51
+ }
52
+ /**
53
+ * 设置转换类型标记
54
+ * @param flag 转换类型标记
55
+ */
56
+ setFlag(flag) {
57
+ this.firstChild.setFlag(flag);
58
+ }
59
+ /**
60
+ * 开关某转换类型标记
61
+ * @param flag 转换类型标记
62
+ */
63
+ toggleFlag(flag) {
64
+ this.firstChild.toggleFlag(flag);
65
+ }
66
+ }
67
+ return FlagsParent;
68
+ };
69
+ exports.flagsParent = flagsParent;
70
+ constants_1.mixins['flagsParent'] = __filename;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hidden = void 0;
4
+ const constants_1 = require("../util/constants");
5
+ /**
6
+ * 解析后不可见的类
7
+ * @param constructor 基类
8
+ */
9
+ const hidden = (constructor) => {
10
+ /** 解析后不可见的类 */
11
+ class AnyHiddenToken extends constructor {
12
+ static hidden = true;
13
+ /** 没有可见部分 */
14
+ // eslint-disable-next-line class-methods-use-this
15
+ text() {
16
+ return '';
17
+ }
18
+ /** @override */
19
+ lint() {
20
+ return [];
21
+ }
22
+ }
23
+ return AnyHiddenToken;
24
+ };
25
+ exports.hidden = hidden;
26
+ constants_1.mixins['hidden'] = __filename;