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