wikiparser-node 1.13.1-b → 1.13.1
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/config/.schema.json +203 -0
- package/config/default.json +32 -31
- package/config/enwiki.json +829 -15
- package/config/llwiki.json +56 -21
- package/config/moegirl.json +65 -21
- package/config/zhwiki.json +498 -32
- package/dist/addon/table.js +494 -0
- package/dist/addon/token.js +392 -0
- package/dist/addon/transclude.js +184 -0
- package/dist/base.d.ts +110 -0
- package/dist/base.js +67 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +279 -0
- package/dist/internal.d.ts +47 -0
- package/dist/lib/element.d.ts +125 -0
- package/dist/lib/element.js +364 -0
- package/dist/lib/node.d.ts +173 -0
- package/dist/lib/node.js +478 -0
- package/dist/lib/range.d.ts +105 -0
- package/dist/lib/range.js +406 -0
- package/dist/lib/ranges.d.ts +28 -0
- package/dist/lib/ranges.js +126 -0
- package/dist/lib/rect.d.ts +18 -0
- package/dist/lib/rect.js +36 -0
- package/dist/lib/text.d.ts +58 -0
- package/dist/lib/text.js +414 -0
- package/dist/lib/title.d.ts +49 -0
- package/dist/lib/title.js +251 -0
- package/dist/mixin/attributesParent.d.ts +49 -0
- package/dist/mixin/attributesParent.js +80 -0
- package/dist/mixin/fixed.d.ts +5 -0
- package/dist/mixin/fixed.js +32 -0
- package/dist/mixin/flagsParent.d.ts +43 -0
- package/dist/mixin/flagsParent.js +64 -0
- package/dist/mixin/hidden.d.ts +7 -0
- package/dist/mixin/hidden.js +39 -0
- package/dist/mixin/magicLinkParent.d.ts +19 -0
- package/dist/mixin/magicLinkParent.js +43 -0
- package/dist/mixin/singleLine.d.ts +5 -0
- package/dist/mixin/singleLine.js +25 -0
- package/dist/mixin/sol.d.ts +6 -0
- package/dist/mixin/sol.js +45 -0
- package/dist/mixin/syntax.d.ts +8 -0
- package/dist/mixin/syntax.js +46 -0
- package/dist/parser/braces.js +152 -0
- package/dist/parser/commentAndExt.js +84 -0
- package/dist/parser/converter.js +41 -0
- package/dist/parser/externalLinks.js +39 -0
- package/dist/parser/hrAndDoubleUnderscore.js +44 -0
- package/dist/parser/html.js +40 -0
- package/dist/parser/links.js +103 -0
- package/dist/parser/list.js +116 -0
- package/dist/parser/magicLinks.js +55 -0
- package/dist/parser/quotes.js +69 -0
- package/dist/parser/redirect.js +28 -0
- package/dist/parser/selector.js +443 -0
- package/dist/parser/table.js +125 -0
- package/dist/src/arg.d.ts +49 -0
- package/dist/src/arg.js +220 -0
- package/dist/src/atom.d.ts +14 -0
- package/dist/src/atom.js +54 -0
- package/dist/src/attribute.d.ts +64 -0
- package/dist/src/attribute.js +482 -0
- package/dist/src/attributes.d.ts +103 -0
- package/dist/src/attributes.js +383 -0
- package/dist/src/converter.d.ts +28 -0
- package/dist/src/converter.js +153 -0
- package/dist/src/converterFlags.d.ts +80 -0
- package/dist/src/converterFlags.js +241 -0
- package/dist/src/converterRule.d.ts +71 -0
- package/dist/src/converterRule.js +218 -0
- package/dist/src/extLink.d.ts +36 -0
- package/dist/src/extLink.js +223 -0
- package/dist/src/gallery.d.ts +51 -0
- package/dist/src/gallery.js +166 -0
- package/dist/src/heading.d.ts +44 -0
- package/dist/src/heading.js +222 -0
- package/dist/src/hidden.d.ts +9 -0
- package/dist/src/hidden.js +82 -0
- package/dist/src/html.d.ts +61 -0
- package/dist/src/html.js +344 -0
- package/dist/src/imageParameter.d.ts +60 -0
- package/dist/src/imageParameter.js +262 -0
- package/dist/src/imagemap.d.ts +47 -0
- package/dist/src/imagemap.js +148 -0
- package/dist/src/imagemapLink.d.ts +35 -0
- package/dist/src/imagemapLink.js +99 -0
- package/dist/src/index.d.ts +136 -0
- package/dist/src/index.js +790 -0
- package/dist/src/link/base.d.ts +52 -0
- package/dist/src/link/base.js +258 -0
- package/dist/src/link/category.d.ts +22 -0
- package/dist/src/link/category.js +36 -0
- package/dist/src/link/file.d.ts +102 -0
- package/dist/src/link/file.js +345 -0
- package/dist/src/link/galleryImage.d.ts +29 -0
- package/dist/src/link/galleryImage.js +133 -0
- package/dist/src/link/index.d.ts +39 -0
- package/dist/src/link/index.js +100 -0
- package/dist/src/link/redirectTarget.d.ts +27 -0
- package/dist/src/link/redirectTarget.js +71 -0
- package/dist/src/magicLink.d.ts +57 -0
- package/dist/src/magicLink.js +261 -0
- package/dist/src/nested.d.ts +40 -0
- package/dist/src/nested.js +108 -0
- package/dist/src/nowiki/base.d.ts +28 -0
- package/dist/src/nowiki/base.js +90 -0
- package/dist/src/nowiki/comment.d.ts +14 -0
- package/dist/src/nowiki/comment.js +123 -0
- package/dist/src/nowiki/dd.d.ts +8 -0
- package/dist/src/nowiki/dd.js +74 -0
- package/dist/src/nowiki/doubleUnderscore.d.ts +15 -0
- package/dist/src/nowiki/doubleUnderscore.js +101 -0
- package/dist/src/nowiki/hr.d.ts +5 -0
- package/dist/src/nowiki/hr.js +72 -0
- package/dist/src/nowiki/index.d.ts +14 -0
- package/dist/src/nowiki/index.js +30 -0
- package/dist/src/nowiki/list.d.ts +5 -0
- package/dist/src/nowiki/list.js +67 -0
- package/dist/src/nowiki/listBase.d.ts +23 -0
- package/dist/src/nowiki/listBase.js +100 -0
- package/dist/src/nowiki/noinclude.d.ts +6 -0
- package/dist/src/nowiki/noinclude.js +77 -0
- package/dist/src/nowiki/quote.d.ts +14 -0
- package/dist/src/nowiki/quote.js +149 -0
- package/dist/src/onlyinclude.d.ts +13 -0
- package/dist/src/onlyinclude.js +60 -0
- package/dist/src/paramTag/index.d.ts +28 -0
- package/dist/src/paramTag/index.js +80 -0
- package/dist/src/paramTag/inputbox.d.ts +8 -0
- package/dist/src/paramTag/inputbox.js +38 -0
- package/dist/src/parameter.d.ts +60 -0
- package/dist/src/parameter.js +267 -0
- package/dist/src/pre.d.ts +28 -0
- package/dist/src/pre.js +70 -0
- package/dist/src/redirect.d.ts +30 -0
- package/dist/src/redirect.js +128 -0
- package/dist/src/syntax.d.ts +15 -0
- package/dist/src/syntax.js +87 -0
- package/dist/src/table/base.d.ts +28 -0
- package/dist/src/table/base.js +81 -0
- package/dist/src/table/index.d.ts +230 -0
- package/dist/src/table/index.js +506 -0
- package/dist/src/table/td.d.ts +72 -0
- package/dist/src/table/td.js +375 -0
- package/dist/src/table/tr.d.ts +30 -0
- package/dist/src/table/tr.js +61 -0
- package/dist/src/table/trBase.d.ts +49 -0
- package/dist/src/table/trBase.js +165 -0
- package/dist/src/tagPair/ext.d.ts +29 -0
- package/dist/src/tagPair/ext.js +229 -0
- package/dist/src/tagPair/include.d.ts +33 -0
- package/dist/src/tagPair/include.js +145 -0
- package/dist/src/tagPair/index.d.ts +23 -0
- package/dist/src/tagPair/index.js +130 -0
- package/dist/src/transclude.d.ts +159 -0
- package/dist/src/transclude.js +598 -0
- package/dist/util/constants.js +26 -0
- package/dist/util/debug.js +95 -0
- package/dist/util/diff.js +83 -0
- package/dist/util/html.js +146 -0
- package/dist/util/lint.js +32 -0
- package/dist/util/string.js +107 -0
- package/errors/README +3 -0
- package/package.json +21 -28
- package/printed/README +3 -0
- package/bundle/bundle.min.js +0 -37
- package/extensions/dist/base.js +0 -163
- package/extensions/dist/codejar.js +0 -53
- package/extensions/dist/editor.js +0 -159
- package/extensions/dist/highlight.js +0 -30
- package/extensions/dist/lint.js +0 -72
- package/extensions/editor.css +0 -59
- package/extensions/ui.css +0 -162
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sol = void 0;
|
|
4
|
+
const debug_1 = require("../util/debug");
|
|
5
|
+
const constants_1 = require("../util/constants");
|
|
6
|
+
/**
|
|
7
|
+
* 只能位于行首的类
|
|
8
|
+
* @param self 是否允许同类节点相邻
|
|
9
|
+
* @param constructor 基类
|
|
10
|
+
* @param _ context
|
|
11
|
+
*/
|
|
12
|
+
const sol = (self) => (constructor, _) => {
|
|
13
|
+
/** 只能位于行首的类 */
|
|
14
|
+
class SolToken extends constructor {
|
|
15
|
+
/** @implements */
|
|
16
|
+
#prependNewLine() {
|
|
17
|
+
const { previousVisibleSibling, parentNode, type } = this;
|
|
18
|
+
if (previousVisibleSibling) {
|
|
19
|
+
return self && previousVisibleSibling.type === type || previousVisibleSibling.toString().endsWith('\n')
|
|
20
|
+
? ''
|
|
21
|
+
: '\n';
|
|
22
|
+
}
|
|
23
|
+
return parentNode?.type === 'root'
|
|
24
|
+
|| type === 'list' && parentNode?.type === 'list-range'
|
|
25
|
+
|| type !== 'heading' && parentNode?.type === 'ext-inner' && parentNode.name === 'poem'
|
|
26
|
+
? ''
|
|
27
|
+
: '\n';
|
|
28
|
+
}
|
|
29
|
+
toString(skip) {
|
|
30
|
+
return this.#prependNewLine() + super.toString(skip);
|
|
31
|
+
}
|
|
32
|
+
getAttribute(key) {
|
|
33
|
+
return key === 'padding'
|
|
34
|
+
? this.#prependNewLine().length + super.getAttribute('padding')
|
|
35
|
+
: super.getAttribute(key);
|
|
36
|
+
}
|
|
37
|
+
text() {
|
|
38
|
+
return this.#prependNewLine() + super.text();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
(0, debug_1.mixin)(SolToken, constructor);
|
|
42
|
+
return SolToken;
|
|
43
|
+
};
|
|
44
|
+
exports.sol = sol;
|
|
45
|
+
constants_1.mixins['sol'] = __filename;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.syntax = void 0;
|
|
4
|
+
const debug_1 = require("../util/debug");
|
|
5
|
+
const constants_1 = require("../util/constants");
|
|
6
|
+
const string_1 = require("../util/string");
|
|
7
|
+
/**
|
|
8
|
+
* 满足特定语法格式的Token
|
|
9
|
+
* @param pattern 语法正则
|
|
10
|
+
* @param constructor 基类
|
|
11
|
+
* @param _ context
|
|
12
|
+
*/
|
|
13
|
+
const syntax = (pattern) => (constructor, _) => {
|
|
14
|
+
/** 满足特定语法格式的Token */
|
|
15
|
+
class SyntaxToken extends constructor {
|
|
16
|
+
/** @class */
|
|
17
|
+
constructor(...args) {
|
|
18
|
+
super(...args); // eslint-disable-line @typescript-eslint/no-unsafe-argument
|
|
19
|
+
if (pattern) {
|
|
20
|
+
this.pattern = pattern;
|
|
21
|
+
}
|
|
22
|
+
this.seal('pattern', true);
|
|
23
|
+
}
|
|
24
|
+
afterBuild() {
|
|
25
|
+
super.afterBuild();
|
|
26
|
+
const /** @implements */ syntaxListener = (e, data) => {
|
|
27
|
+
if (!debug_1.Shadow.running && !this.pattern.test((0, string_1.text)(this.childNodes))) {
|
|
28
|
+
(0, debug_1.undo)(e, data);
|
|
29
|
+
this.constructorError('cannot modify the syntax pattern');
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
this.addEventListener(['remove', 'insert', 'replace', 'text'], syntaxListener);
|
|
33
|
+
}
|
|
34
|
+
replaceChildren(...elements) {
|
|
35
|
+
if (debug_1.Shadow.running || this.pattern.test((0, string_1.text)(elements))) {
|
|
36
|
+
debug_1.Shadow.run(() => {
|
|
37
|
+
super.replaceChildren(...elements);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
(0, debug_1.mixin)(SyntaxToken, constructor);
|
|
43
|
+
return SyntaxToken;
|
|
44
|
+
};
|
|
45
|
+
exports.syntax = syntax;
|
|
46
|
+
constants_1.mixins['syntax'] = __filename;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseBraces = void 0;
|
|
4
|
+
const string_1 = require("../util/string");
|
|
5
|
+
const heading_1 = require("../src/heading");
|
|
6
|
+
const transclude_1 = require("../src/transclude");
|
|
7
|
+
const arg_1 = require("../src/arg");
|
|
8
|
+
/* NOT FOR BROWSER */
|
|
9
|
+
const constants_1 = require("../util/constants");
|
|
10
|
+
/* NOT FOR BROWSER END */
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
12
|
+
/\{\{\s*([!=]|!!|\(!|!\)|!-)\s*\}\}(?!\})/gu;
|
|
13
|
+
const closes = {
|
|
14
|
+
'=': String.raw `\n(?!(?:[^\S\n]|\0\d+[cn]\x7F)*\n)`,
|
|
15
|
+
'{': String.raw `\}{2,}|\|`,
|
|
16
|
+
'-': String.raw `\}-`,
|
|
17
|
+
'[': String.raw `\]\]`,
|
|
18
|
+
}, marks = new Map([['!', '!'], ['!!', '+'], ['(!', '{'], ['!)', '}'], ['!-', '-'], ['=', '~']]), re = new RegExp(String.raw `\{\{\s*(${[...marks.keys()].map(string_1.escapeRegExp).join('|')})\s*\}\}(?!\})`, 'gu');
|
|
19
|
+
/**
|
|
20
|
+
* 解析花括号
|
|
21
|
+
* @param wikitext
|
|
22
|
+
* @param config
|
|
23
|
+
* @param accum
|
|
24
|
+
* @throws TranscludeToken.constructor()
|
|
25
|
+
*/
|
|
26
|
+
const parseBraces = (wikitext, config, accum) => {
|
|
27
|
+
const source = String.raw `${config.excludes?.includes('heading') ? '' : String.raw `^((?:\0\d+[cno]\x7F)*)={1,6}|`}\[\[|-\{(?!\{)`, openBraces = String.raw `|\{{2,}`, { parserFunction: [, , , subst] } = config, stack = [];
|
|
28
|
+
wikitext = wikitext.replace(re, (m, p1) => {
|
|
29
|
+
// @ts-expect-error abstract class
|
|
30
|
+
new transclude_1.TranscludeToken(m.slice(2, -2), [], config, accum);
|
|
31
|
+
return `\0${accum.length - 2}${marks.get(p1)}\x7F`;
|
|
32
|
+
});
|
|
33
|
+
const lastBraces = wikitext.lastIndexOf('}}') - wikitext.length;
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
35
|
+
/^((?:\0\d+[cno]\x7F)*)={1,6}|\[\[|-\{(?!\{)|\{{2,}|\n(?!(?:[^\S\n]|\0\d+[cn]\x7F)*\n)|[|=]|\}{2,}|\}-|\]\]/gmu;
|
|
36
|
+
let moreBraces = lastBraces + wikitext.length !== -1, regex = new RegExp(source + (moreBraces ? openBraces : ''), 'gmu'), mt = regex.exec(wikitext), lastIndex;
|
|
37
|
+
while (mt
|
|
38
|
+
|| lastIndex !== undefined && lastIndex <= wikitext.length && stack[stack.length - 1]?.[0]?.startsWith('=')) {
|
|
39
|
+
if (mt?.[1]) {
|
|
40
|
+
const [, { length }] = mt;
|
|
41
|
+
mt[0] = mt[0].slice(length);
|
|
42
|
+
mt.index += length;
|
|
43
|
+
}
|
|
44
|
+
const { 0: syntax, index: curIndex } = mt ?? { 0: '\n', index: wikitext.length }, top = stack.pop() ?? {}, { 0: open, index, parts, findEqual: topFindEqual, pos: topPos } = top, innerEqual = syntax === '=' && topFindEqual;
|
|
45
|
+
/**
|
|
46
|
+
* 填入模板内容
|
|
47
|
+
* @param text wikitext全文
|
|
48
|
+
*/
|
|
49
|
+
const push = (text) => {
|
|
50
|
+
parts[parts.length - 1].push(text.slice(topPos, curIndex));
|
|
51
|
+
};
|
|
52
|
+
if (syntax === ']]' || syntax === '}-') { // 情形1:闭合内链或转换
|
|
53
|
+
lastIndex = curIndex + 2;
|
|
54
|
+
}
|
|
55
|
+
else if (syntax === '\n') { // 情形2:闭合标题或文末
|
|
56
|
+
lastIndex = curIndex + 1;
|
|
57
|
+
const { pos, findEqual } = stack[stack.length - 1] ?? {};
|
|
58
|
+
if (pos === undefined || findEqual || (0, string_1.removeComment)(wikitext.slice(pos, index)) !== '') {
|
|
59
|
+
const rmt = /^(={1,6})(.+)\1((?:\s|\0\d+[cn]\x7F)*)$/u
|
|
60
|
+
.exec(wikitext.slice(index, curIndex));
|
|
61
|
+
if (rmt) {
|
|
62
|
+
wikitext = `${wikitext.slice(0, index)}\0${accum.length}h\x7F${wikitext.slice(curIndex)}`;
|
|
63
|
+
lastIndex = index + 4 + String(accum.length).length;
|
|
64
|
+
// @ts-expect-error abstract class
|
|
65
|
+
new heading_1.HeadingToken(rmt[1].length, rmt.slice(2), config, accum);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else if (syntax === '|' || innerEqual) { // 情形3:模板内部,含行首单个'='
|
|
70
|
+
lastIndex = curIndex + 1;
|
|
71
|
+
push(wikitext);
|
|
72
|
+
if (syntax === '|') {
|
|
73
|
+
parts.push([]);
|
|
74
|
+
}
|
|
75
|
+
top.pos = lastIndex;
|
|
76
|
+
top.findEqual = syntax === '|';
|
|
77
|
+
stack.push(top);
|
|
78
|
+
}
|
|
79
|
+
else if (syntax.startsWith('}}')) { // 情形4:闭合模板
|
|
80
|
+
const close = syntax.slice(0, Math.min(open.length, 3)), rest = open.length - close.length, { length } = accum;
|
|
81
|
+
lastIndex = curIndex + close.length; // 这不是最终的lastIndex
|
|
82
|
+
push(wikitext);
|
|
83
|
+
let skip = false, ch = 't';
|
|
84
|
+
if (close.length === 3) {
|
|
85
|
+
const argParts = parts.map(part => part.join('=')), str = argParts.length > 1 && (0, string_1.removeComment)(argParts[1]).trim();
|
|
86
|
+
// @ts-expect-error abstract class
|
|
87
|
+
new arg_1.ArgToken(argParts, config, accum);
|
|
88
|
+
if (str && str.endsWith(':') && subst.includes(str.slice(0, -1).toLowerCase())) {
|
|
89
|
+
ch = 's';
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
try {
|
|
94
|
+
// @ts-expect-error abstract class
|
|
95
|
+
new transclude_1.TranscludeToken(parts[0][0], parts.slice(1), config, accum);
|
|
96
|
+
const name = (0, string_1.removeComment)(parts[0][0]).trim();
|
|
97
|
+
if (marks.has(name)) {
|
|
98
|
+
ch = marks.get(name); // 标记{{!}}等
|
|
99
|
+
}
|
|
100
|
+
else if (/^(?:filepath|(?:full|canonical)urle?):.|^server$/iu.test(name)) {
|
|
101
|
+
ch = 'm';
|
|
102
|
+
}
|
|
103
|
+
else if (/^#vardefine:./iu.test(name)) {
|
|
104
|
+
ch = 'n';
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
if (e instanceof SyntaxError && e.message === 'Invalid template name') {
|
|
109
|
+
skip = true;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
throw e;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (!skip) {
|
|
117
|
+
wikitext = `${wikitext.slice(0, index + rest)}\0${length}${ch}\x7F${wikitext.slice(lastIndex)}`;
|
|
118
|
+
lastIndex = index + rest + 3 + String(length).length;
|
|
119
|
+
if (rest > 1) {
|
|
120
|
+
stack.push({ 0: open.slice(0, rest), index: index, pos: index + rest, parts: [[]] });
|
|
121
|
+
}
|
|
122
|
+
else if (rest === 1 && wikitext[index - 1] === '-') {
|
|
123
|
+
stack.push({ 0: '-{', index: index - 1, pos: index + 1, parts: [[]] });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else { // 情形5:开启
|
|
128
|
+
lastIndex = curIndex + syntax.length;
|
|
129
|
+
if (syntax.startsWith('{')) {
|
|
130
|
+
mt.pos = lastIndex;
|
|
131
|
+
mt.parts = [[]];
|
|
132
|
+
}
|
|
133
|
+
stack.push(...'0' in top ? [top] : [], mt);
|
|
134
|
+
}
|
|
135
|
+
let curTop = stack[stack.length - 1];
|
|
136
|
+
if (moreBraces && lastBraces + wikitext.length < lastIndex) {
|
|
137
|
+
moreBraces = false;
|
|
138
|
+
while (curTop?.[0]?.startsWith('{')) {
|
|
139
|
+
stack.pop();
|
|
140
|
+
curTop = stack[stack.length - 1];
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
regex = new RegExp(source
|
|
144
|
+
+ (moreBraces ? openBraces : '')
|
|
145
|
+
+ (curTop ? `|${closes[curTop[0][0]]}${curTop.findEqual ? '|=' : ''}` : ''), 'gmu');
|
|
146
|
+
regex.lastIndex = lastIndex;
|
|
147
|
+
mt = regex.exec(wikitext);
|
|
148
|
+
}
|
|
149
|
+
return wikitext;
|
|
150
|
+
};
|
|
151
|
+
exports.parseBraces = parseBraces;
|
|
152
|
+
constants_1.parsers['parseBraces'] = __filename;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseCommentAndExt = void 0;
|
|
4
|
+
const onlyinclude_1 = require("../src/onlyinclude");
|
|
5
|
+
const noinclude_1 = require("../src/nowiki/noinclude");
|
|
6
|
+
const include_1 = require("../src/tagPair/include");
|
|
7
|
+
const ext_1 = require("../src/tagPair/ext");
|
|
8
|
+
const comment_1 = require("../src/nowiki/comment");
|
|
9
|
+
/* NOT FOR BROWSER */
|
|
10
|
+
const constants_1 = require("../util/constants");
|
|
11
|
+
/* NOT FOR BROWSER END */
|
|
12
|
+
/**
|
|
13
|
+
* 解析HTML注释和扩展标签
|
|
14
|
+
* @param wikitext
|
|
15
|
+
* @param config
|
|
16
|
+
* @param accum
|
|
17
|
+
* @param includeOnly 是否嵌入
|
|
18
|
+
*/
|
|
19
|
+
const parseCommentAndExt = (wikitext, config, accum, includeOnly) => {
|
|
20
|
+
const onlyincludeLeft = '<onlyinclude>', onlyincludeRight = '</onlyinclude>', { length } = onlyincludeLeft;
|
|
21
|
+
/** 更新`<onlyinclude>`和`</onlyinclude>`的位置 */
|
|
22
|
+
const update = () => {
|
|
23
|
+
const i = wikitext.indexOf(onlyincludeLeft);
|
|
24
|
+
return { i, j: wikitext.indexOf(onlyincludeRight, i + length) };
|
|
25
|
+
};
|
|
26
|
+
if (includeOnly) {
|
|
27
|
+
let { i, j } = update();
|
|
28
|
+
if (i !== -1 && j !== -1) { // `<onlyinclude>`拥有最高优先级
|
|
29
|
+
let str = '';
|
|
30
|
+
/**
|
|
31
|
+
* 忽略未被`<onlyinclude>`和`</onlyinclude>`包裹的内容
|
|
32
|
+
* @param text 未被包裹的内容
|
|
33
|
+
*/
|
|
34
|
+
const noinclude = (text) => {
|
|
35
|
+
// @ts-expect-error abstract class
|
|
36
|
+
new noinclude_1.NoincludeToken(text, config, accum);
|
|
37
|
+
str += `\0${accum.length - 1}n\x7F`;
|
|
38
|
+
};
|
|
39
|
+
while (i !== -1 && j !== -1) {
|
|
40
|
+
const token = `\0${accum.length}e\x7F`;
|
|
41
|
+
new onlyinclude_1.OnlyincludeToken(wikitext.slice(i + length, j), config, accum);
|
|
42
|
+
if (i > 0) {
|
|
43
|
+
noinclude(wikitext.slice(0, i));
|
|
44
|
+
}
|
|
45
|
+
str += token;
|
|
46
|
+
wikitext = wikitext.slice(j + length + 1);
|
|
47
|
+
({ i, j } = update());
|
|
48
|
+
}
|
|
49
|
+
if (wikitext) {
|
|
50
|
+
noinclude(wikitext);
|
|
51
|
+
}
|
|
52
|
+
return str;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
56
|
+
/<!--.*?(?:-->|$)|<foo(?:\s[^>]*)?\/?>|<\/foo\s*>|<(bar)(\s[^>]*?)?(?:\/>|>(.*?)<\/(\1\s*)>)|<(baz)(\s[^>]*?)?(?:\/>|>(.*?)(?:<\/(baz\s*)>|$))/gisu;
|
|
57
|
+
const ext = config.ext.join('|'), noincludeRegex = includeOnly ? 'includeonly' : '(?:no|only)include', includeRegex = includeOnly ? 'noinclude' : 'includeonly', regex = new RegExp(String.raw `<!--.*?(?:-->|$)|<${noincludeRegex}(?:\s[^>]*)?/?>|</${noincludeRegex}\s*>|<(${ext})(\s[^>]*?)?(?:/>|>(.*?)</(\1\s*)>)|<(${includeRegex})(\s[^>]*?)?(?:/>|>(.*?)(?:</(${includeRegex}\s*)>|$))`, 'gisu');
|
|
58
|
+
return wikitext.replace(regex, (substr, name, attr, inner, closing, include, includeAttr, includeInner, includeClosing) => {
|
|
59
|
+
const l = accum.length;
|
|
60
|
+
let ch = 'n';
|
|
61
|
+
if (name) {
|
|
62
|
+
ch = 'e';
|
|
63
|
+
// @ts-expect-error abstract class
|
|
64
|
+
new ext_1.ExtToken(name, attr, inner, closing, config, accum);
|
|
65
|
+
}
|
|
66
|
+
else if (substr.startsWith('<!--')) {
|
|
67
|
+
ch = 'c';
|
|
68
|
+
const closed = substr.endsWith('-->');
|
|
69
|
+
// @ts-expect-error abstract class
|
|
70
|
+
new comment_1.CommentToken(substr.slice(4, closed ? -3 : undefined), closed, config, accum);
|
|
71
|
+
}
|
|
72
|
+
else if (include) {
|
|
73
|
+
// @ts-expect-error abstract class
|
|
74
|
+
new include_1.IncludeToken(include, includeAttr, includeInner, includeClosing, config, accum);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
// @ts-expect-error abstract class
|
|
78
|
+
new noinclude_1.NoincludeToken(substr, config, accum);
|
|
79
|
+
}
|
|
80
|
+
return `\0${l}${ch}\x7F`;
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
exports.parseCommentAndExt = parseCommentAndExt;
|
|
84
|
+
constants_1.parsers['parseCommentAndExt'] = __filename;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseConverter = void 0;
|
|
4
|
+
const converter_1 = require("../src/converter");
|
|
5
|
+
/* NOT FOR BROWSER */
|
|
6
|
+
const constants_1 = require("../util/constants");
|
|
7
|
+
/* NOT FOR BROWSER END */
|
|
8
|
+
/**
|
|
9
|
+
* 解析语言变体转换
|
|
10
|
+
* @param text
|
|
11
|
+
* @param config
|
|
12
|
+
* @param accum
|
|
13
|
+
*/
|
|
14
|
+
const parseConverter = (text, config, accum) => {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
16
|
+
/;(?=(?:[^;]*?=>)?\s*zh\s*:|(?:\s|\0\d+[cn]\x7F)*$)/u;
|
|
17
|
+
const variants = `(?:${config.variants.join('|')})`, regex1 = /-\{/gu, regex2 = /-\{|\}-/gu, regex3 = new RegExp(String.raw `;(?=(?:[^;]*?=>)?\s*${variants}\s*:|(?:\s|\0\d+[cn]\x7F)*$)`, 'u'), stack = [];
|
|
18
|
+
let regex = regex1, mt = regex.exec(text);
|
|
19
|
+
while (mt) {
|
|
20
|
+
const { 0: syntax, index } = mt;
|
|
21
|
+
if (syntax === '}-') {
|
|
22
|
+
const top = stack.pop(), { length } = accum, str = text.slice(top.index + 2, index), i = str.indexOf('|'), [flags, raw] = i === -1 ? [[], str] : [str.slice(0, i).split(';'), str.slice(i + 1)], temp = raw.replace(/(&[#a-z\d]+);/giu, '$1\x01'), rules = temp.split(regex3).map(rule => rule.replace(/\x01/gu, ';'));
|
|
23
|
+
// @ts-expect-error abstract class
|
|
24
|
+
new converter_1.ConverterToken(flags, rules, config, accum);
|
|
25
|
+
text = `${text.slice(0, top.index)}\0${length}v\x7F${text.slice(index + 2)}`;
|
|
26
|
+
if (stack.length === 0) {
|
|
27
|
+
regex = regex1;
|
|
28
|
+
}
|
|
29
|
+
regex.lastIndex = top.index + 3 + String(length).length;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
stack.push(mt);
|
|
33
|
+
regex = regex2;
|
|
34
|
+
regex.lastIndex = index + 2;
|
|
35
|
+
}
|
|
36
|
+
mt = regex.exec(text);
|
|
37
|
+
}
|
|
38
|
+
return text;
|
|
39
|
+
};
|
|
40
|
+
exports.parseConverter = parseConverter;
|
|
41
|
+
constants_1.parsers['parseConverter'] = __filename;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseExternalLinks = void 0;
|
|
4
|
+
const string_1 = require("../util/string");
|
|
5
|
+
const extLink_1 = require("../src/extLink");
|
|
6
|
+
const magicLink_1 = require("../src/magicLink");
|
|
7
|
+
/* NOT FOR BROWSER */
|
|
8
|
+
const constants_1 = require("../util/constants");
|
|
9
|
+
/* NOT FOR BROWSER END */
|
|
10
|
+
/**
|
|
11
|
+
* 解析外部链接
|
|
12
|
+
* @param wikitext
|
|
13
|
+
* @param config
|
|
14
|
+
* @param accum
|
|
15
|
+
* @param inFile 是否在图链中
|
|
16
|
+
*/
|
|
17
|
+
const parseExternalLinks = (wikitext, config, accum, inFile) => {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
19
|
+
/\[((?:ftp:\/\/|\/\/)(?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])[^[\]<>"\t\n\p{Zs}]*(?=[[\]<>"\t\p{Zs}]|\0\d))(\p{Zs}*(?!\p{Zs}))([^\]\n]*)\]/giu;
|
|
20
|
+
const regex = new RegExp(String.raw `\[(\0\d+f\x7F|(?:(?:${config.protocol}|//)${string_1.extUrlCharFirst}|\0\d+m\x7F)${string_1.extUrlChar}(?=[[\]<>"\t\p{Zs}]|\0\d))(\p{Zs}*(?!\p{Zs}))([^\]\x01-\x08\x0A-\x1F\uFFFD]*)\]`, 'giu');
|
|
21
|
+
return wikitext.replace(regex, (_, url, space, text) => {
|
|
22
|
+
const { length } = accum, mt = /&[lg]t;/u.exec(url);
|
|
23
|
+
if (mt) {
|
|
24
|
+
url = url.slice(0, mt.index);
|
|
25
|
+
space = '';
|
|
26
|
+
text = url.slice(mt.index) + space + text;
|
|
27
|
+
}
|
|
28
|
+
if (inFile) {
|
|
29
|
+
// @ts-expect-error abstract class
|
|
30
|
+
new magicLink_1.MagicLinkToken(url, 'ext-link-url', config, accum);
|
|
31
|
+
return `[\0${length}f\x7F${space}${text}]`;
|
|
32
|
+
}
|
|
33
|
+
// @ts-expect-error abstract class
|
|
34
|
+
new extLink_1.ExtLinkToken(url, space, text, config, accum);
|
|
35
|
+
return `\0${length}w\x7F`;
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
exports.parseExternalLinks = parseExternalLinks;
|
|
39
|
+
constants_1.parsers['parseExternalLinks'] = __filename;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseHrAndDoubleUnderscore = void 0;
|
|
4
|
+
const hr_1 = require("../src/nowiki/hr");
|
|
5
|
+
const doubleUnderscore_1 = require("../src/nowiki/doubleUnderscore");
|
|
6
|
+
const heading_1 = require("../src/heading");
|
|
7
|
+
/* NOT FOR BROWSER */
|
|
8
|
+
const constants_1 = require("../util/constants");
|
|
9
|
+
/* NOT FOR BROWSER END */
|
|
10
|
+
/**
|
|
11
|
+
* 解析`<hr>`和状态开关
|
|
12
|
+
* @param {Token} root 根节点
|
|
13
|
+
* @param config
|
|
14
|
+
* @param accum
|
|
15
|
+
*/
|
|
16
|
+
const parseHrAndDoubleUnderscore = ({ firstChild: { data }, type, name }, config, accum) => {
|
|
17
|
+
const { doubleUnderscore } = config, insensitive = new Set(doubleUnderscore[0]), sensitive = new Set(doubleUnderscore[1]);
|
|
18
|
+
if (type !== 'root' && (type !== 'ext-inner' || name !== 'poem')) {
|
|
19
|
+
data = `\0${data}`;
|
|
20
|
+
}
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
22
|
+
/__(toc|notoc)__/giu;
|
|
23
|
+
data = data.replace(/^((?:\0\d+[cno]\x7F)*)(-{4,})/gmu, (_, lead, m) => {
|
|
24
|
+
// @ts-expect-error abstract class
|
|
25
|
+
new hr_1.HrToken(m, config, accum);
|
|
26
|
+
return `${lead}\0${accum.length - 1}r\x7F`;
|
|
27
|
+
}).replace(new RegExp(`__(${[...insensitive, ...sensitive].join('|')})__`, 'giu'), (m, p1) => {
|
|
28
|
+
const caseSensitive = sensitive.has(p1), lc = p1.toLowerCase(), caseInsensitive = insensitive.has(lc);
|
|
29
|
+
if (caseSensitive || caseInsensitive) {
|
|
30
|
+
// @ts-expect-error abstract class
|
|
31
|
+
new doubleUnderscore_1.DoubleUnderscoreToken(p1, caseSensitive, config, accum);
|
|
32
|
+
return `\0${accum.length - 1}${caseInsensitive && (doubleUnderscore[2]?.[lc] ?? lc) === 'toc' ? 'u' : 'n'}\x7F`;
|
|
33
|
+
}
|
|
34
|
+
return m;
|
|
35
|
+
}).replace(/^((?:\0\d+[cn]\x7F)*)(={1,6})(.+)\2((?:\s|\0\d+[cn]\x7F)*)$/gmu, (_, lead, equals, heading, trail) => {
|
|
36
|
+
const text = `${lead}\0${accum.length}h\x7F`;
|
|
37
|
+
// @ts-expect-error abstract class
|
|
38
|
+
new heading_1.HeadingToken(equals.length, [heading, trail], config, accum);
|
|
39
|
+
return text;
|
|
40
|
+
});
|
|
41
|
+
return type === 'root' || type === 'ext-inner' && name === 'poem' ? data : data.slice(1);
|
|
42
|
+
};
|
|
43
|
+
exports.parseHrAndDoubleUnderscore = parseHrAndDoubleUnderscore;
|
|
44
|
+
constants_1.parsers['parseHrAndDoubleUnderscore'] = __filename;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseHtml = void 0;
|
|
4
|
+
const attributes_1 = require("../src/attributes");
|
|
5
|
+
const html_1 = require("../src/html");
|
|
6
|
+
/* NOT FOR BROWSER */
|
|
7
|
+
const constants_1 = require("../util/constants");
|
|
8
|
+
/* NOT FOR BROWSER END */
|
|
9
|
+
/**
|
|
10
|
+
* 解析HTML标签
|
|
11
|
+
* @param wikitext
|
|
12
|
+
* @param config
|
|
13
|
+
* @param accum
|
|
14
|
+
*/
|
|
15
|
+
const parseHtml = (wikitext, config, accum) => {
|
|
16
|
+
const regex = /^(\/?)([a-z][^\s/>]*)((?:\s|\/(?!>))[^>]*?)?(\/?>)([^<]*)$/iu, { html } = config, elements = new Set([...html[0], ...html[1], ...html[2]]), bits = wikitext.split('<');
|
|
17
|
+
let text = bits.shift();
|
|
18
|
+
for (const x of bits) {
|
|
19
|
+
const mt = regex.exec(x), t = mt?.[2], name = t?.toLowerCase();
|
|
20
|
+
if (!mt || !elements.has(name)) {
|
|
21
|
+
text += `<${x}`;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const [, slash, , params = '', brace, rest] = mt, { length } = accum,
|
|
25
|
+
// @ts-expect-error abstract class
|
|
26
|
+
attrs = new attributes_1.AttributesToken(params, 'html-attrs', name, config, accum), itemprop = attrs.getAttr('itemprop');
|
|
27
|
+
if (name === 'meta' && (itemprop === undefined || attrs.getAttr('content') === undefined)
|
|
28
|
+
|| name === 'link' && (itemprop === undefined || attrs.getAttr('href') === undefined)) {
|
|
29
|
+
text += `<${x}`;
|
|
30
|
+
accum.length = length;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
text += `\0${accum.length}x\x7F${rest}`;
|
|
34
|
+
// @ts-expect-error abstract class
|
|
35
|
+
new html_1.HtmlToken(t, attrs, slash === '/', brace === '/>', config, accum);
|
|
36
|
+
}
|
|
37
|
+
return text;
|
|
38
|
+
};
|
|
39
|
+
exports.parseHtml = parseHtml;
|
|
40
|
+
constants_1.parsers['parseHtml'] = __filename;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseLinks = void 0;
|
|
4
|
+
const index_1 = require("../index");
|
|
5
|
+
const quotes_1 = require("./quotes");
|
|
6
|
+
const externalLinks_1 = require("./externalLinks");
|
|
7
|
+
const index_2 = require("../src/link/index");
|
|
8
|
+
const file_1 = require("../src/link/file");
|
|
9
|
+
const category_1 = require("../src/link/category");
|
|
10
|
+
/* NOT FOR BROWSER */
|
|
11
|
+
const constants_1 = require("../util/constants");
|
|
12
|
+
/* NOT FOR BROWSER END */
|
|
13
|
+
/**
|
|
14
|
+
* 解析内部链接
|
|
15
|
+
* @param wikitext
|
|
16
|
+
* @param config
|
|
17
|
+
* @param accum
|
|
18
|
+
*/
|
|
19
|
+
const parseLinks = (wikitext, config, accum) => {
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
21
|
+
/^\s*(?:ftp:\/\/|\/\/)/iu;
|
|
22
|
+
const regex = true // eslint-disable-line no-constant-condition, @typescript-eslint/no-unnecessary-condition
|
|
23
|
+
? /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(?:(\||\0\d+!\x7F)(.*?[^\]]))?\]\](.*)$/su
|
|
24
|
+
: /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(?:(\||\0\d+!\x7F)(.*?[^\]])?)?\]\](.*)$/su, regexImg = /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(\||\0\d+!\x7F)(.*)$/su, regexExt = new RegExp(String.raw `^\s*(?:${config.protocol}|//)`, 'iu'), bits = wikitext.split('[[');
|
|
25
|
+
let s = bits.shift();
|
|
26
|
+
for (let i = 0; i < bits.length; i++) {
|
|
27
|
+
let mightBeImg = false, link, delimiter, text, after;
|
|
28
|
+
const x = bits[i], m = regex.exec(x);
|
|
29
|
+
if (m) {
|
|
30
|
+
[, link, delimiter, text, after] = m;
|
|
31
|
+
if (after.startsWith(']') && text?.includes('[')) {
|
|
32
|
+
text += ']';
|
|
33
|
+
after = after.slice(1);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const m2 = regexImg.exec(x);
|
|
38
|
+
if (m2) {
|
|
39
|
+
mightBeImg = true;
|
|
40
|
+
[, link, delimiter, text] = m2;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (link === undefined || regexExt.test(link) || /\0\d+[exhbru]\x7F/u.test(link)) {
|
|
44
|
+
s += `[[${x}`;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const force = link.trim().startsWith(':');
|
|
48
|
+
if (force && mightBeImg) {
|
|
49
|
+
s += `[[${x}`;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const title = index_1.default.normalizeTitle(link, 0, false, config, true, true, true), { ns, valid, interwiki } = title;
|
|
53
|
+
if (!valid) {
|
|
54
|
+
s += `[[${x}`;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
else if (mightBeImg) {
|
|
58
|
+
if (interwiki || ns !== 6) {
|
|
59
|
+
s += `[[${x}`;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
let found = false;
|
|
63
|
+
for (i++; i < bits.length; i++) {
|
|
64
|
+
const next = bits[i], p = next.split(']]');
|
|
65
|
+
if (p.length > 2) {
|
|
66
|
+
found = true;
|
|
67
|
+
text += `[[${p[0]}]]${p[1]}`;
|
|
68
|
+
after = p.slice(2).join(']]');
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
else if (p.length === 2) {
|
|
72
|
+
text += `[[${p[0]}]]${p[1]}`;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
text += `[[${next}`;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
text = (0, exports.parseLinks)(text, config, accum);
|
|
80
|
+
if (!found) {
|
|
81
|
+
s += `[[${link}${delimiter}${text}`;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
text &&= (0, quotes_1.parseQuotes)(text, config, accum);
|
|
86
|
+
let SomeLinkToken = index_2.LinkToken;
|
|
87
|
+
if (!force) {
|
|
88
|
+
if (!interwiki && ns === 6) {
|
|
89
|
+
text &&= (0, externalLinks_1.parseExternalLinks)(text, config, accum, true);
|
|
90
|
+
SomeLinkToken = file_1.FileToken;
|
|
91
|
+
}
|
|
92
|
+
else if (!interwiki && ns === 14) {
|
|
93
|
+
SomeLinkToken = category_1.CategoryToken;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
s += `\0${accum.length}l\x7F${after}`;
|
|
97
|
+
// @ts-expect-error abstract class
|
|
98
|
+
new SomeLinkToken(link, text, config, accum, delimiter);
|
|
99
|
+
}
|
|
100
|
+
return s;
|
|
101
|
+
};
|
|
102
|
+
exports.parseLinks = parseLinks;
|
|
103
|
+
constants_1.parsers['parseLinks'] = __filename;
|