wikiparser-node 1.4.0 → 1.4.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/bundle/bundle.min.js +36 -0
- package/config/default.json +18 -3
- package/config/enwiki.json +411 -0
- package/config/llwiki.json +1 -35
- package/config/moegirl.json +1 -44
- package/config/zhwiki.json +1 -466
- package/extensions/dist/base.js +64 -0
- package/extensions/dist/editor.js +159 -0
- package/extensions/dist/highlight.js +59 -0
- package/extensions/dist/lint.js +48 -0
- package/extensions/editor.css +63 -0
- package/extensions/ui.css +141 -0
- package/i18n/zh-hans.json +4 -3
- package/i18n/zh-hant.json +5 -4
- package/package.json +39 -23
- package/config/.schema.json +0 -172
- package/dist/addon/table.d.ts +0 -6
- package/dist/addon/table.js +0 -558
- package/dist/base.d.ts +0 -53
- package/dist/index.d.ts +0 -32
- package/dist/index.js +0 -211
- package/dist/internal.d.ts +0 -44
- package/dist/lib/element.d.ts +0 -153
- package/dist/lib/element.js +0 -643
- package/dist/lib/node.d.ts +0 -145
- package/dist/lib/node.js +0 -419
- package/dist/lib/range.d.ts +0 -103
- package/dist/lib/range.js +0 -385
- package/dist/lib/ranges.d.ts +0 -25
- package/dist/lib/ranges.js +0 -118
- package/dist/lib/text.d.ts +0 -61
- package/dist/lib/text.js +0 -255
- package/dist/lib/title.d.ts +0 -37
- package/dist/lib/title.js +0 -163
- package/dist/mixin/attributesParent.d.ts +0 -80
- package/dist/mixin/attributesParent.js +0 -89
- package/dist/mixin/fixed.d.ts +0 -31
- package/dist/mixin/fixed.js +0 -28
- package/dist/mixin/flagsParent.d.ts +0 -61
- package/dist/mixin/flagsParent.js +0 -70
- package/dist/mixin/hidden.d.ts +0 -18
- package/dist/mixin/hidden.js +0 -24
- package/dist/mixin/magicLinkParent.d.ts +0 -34
- package/dist/mixin/magicLinkParent.js +0 -41
- package/dist/mixin/singleLine.d.ts +0 -14
- package/dist/mixin/singleLine.js +0 -25
- package/dist/mixin/sol.d.ts +0 -18
- package/dist/mixin/sol.js +0 -43
- package/dist/mixin/syntax.d.ts +0 -19
- package/dist/mixin/syntax.js +0 -54
- package/dist/parser/braces.js +0 -128
- package/dist/parser/commentAndExt.js +0 -85
- package/dist/parser/converter.js +0 -40
- package/dist/parser/externalLinks.js +0 -31
- package/dist/parser/hrAndDoubleUnderscore.js +0 -38
- package/dist/parser/html.js +0 -36
- package/dist/parser/links.js +0 -94
- package/dist/parser/list.js +0 -66
- package/dist/parser/magicLinks.js +0 -42
- package/dist/parser/quotes.js +0 -67
- package/dist/parser/selector.js +0 -162
- package/dist/parser/table.js +0 -120
- package/dist/src/arg.d.ts +0 -57
- package/dist/src/arg.js +0 -194
- package/dist/src/atom.d.ts +0 -12
- package/dist/src/atom.js +0 -27
- package/dist/src/attribute.d.ts +0 -70
- package/dist/src/attribute.js +0 -422
- package/dist/src/attributes.d.ts +0 -108
- package/dist/src/attributes.js +0 -343
- package/dist/src/converter.d.ts +0 -35
- package/dist/src/converter.js +0 -79
- package/dist/src/converterFlags.d.ts +0 -86
- package/dist/src/converterFlags.js +0 -224
- package/dist/src/converterRule.d.ts +0 -77
- package/dist/src/converterRule.js +0 -208
- package/dist/src/extLink.d.ts +0 -36
- package/dist/src/extLink.js +0 -122
- package/dist/src/gallery.d.ts +0 -53
- package/dist/src/gallery.js +0 -121
- package/dist/src/heading.d.ts +0 -51
- package/dist/src/heading.js +0 -143
- package/dist/src/hidden.d.ts +0 -9
- package/dist/src/hidden.js +0 -23
- package/dist/src/html.d.ts +0 -77
- package/dist/src/html.js +0 -284
- package/dist/src/imageParameter.d.ts +0 -64
- package/dist/src/imageParameter.js +0 -247
- package/dist/src/imagemap.d.ts +0 -56
- package/dist/src/imagemap.js +0 -147
- package/dist/src/imagemapLink.d.ts +0 -34
- package/dist/src/imagemapLink.js +0 -40
- package/dist/src/index.d.ts +0 -139
- package/dist/src/index.js +0 -769
- package/dist/src/link/base.d.ts +0 -51
- package/dist/src/link/base.js +0 -209
- package/dist/src/link/category.d.ts +0 -13
- package/dist/src/link/category.js +0 -29
- package/dist/src/link/file.d.ts +0 -95
- package/dist/src/link/file.js +0 -259
- package/dist/src/link/galleryImage.d.ts +0 -29
- package/dist/src/link/galleryImage.js +0 -106
- package/dist/src/link/index.d.ts +0 -55
- package/dist/src/link/index.js +0 -135
- package/dist/src/magicLink.d.ts +0 -56
- package/dist/src/magicLink.js +0 -147
- package/dist/src/nested.d.ts +0 -42
- package/dist/src/nested.js +0 -86
- package/dist/src/nowiki/base.d.ts +0 -31
- package/dist/src/nowiki/base.js +0 -42
- package/dist/src/nowiki/comment.d.ts +0 -29
- package/dist/src/nowiki/comment.js +0 -74
- package/dist/src/nowiki/dd.d.ts +0 -8
- package/dist/src/nowiki/dd.js +0 -25
- package/dist/src/nowiki/doubleUnderscore.d.ts +0 -26
- package/dist/src/nowiki/doubleUnderscore.js +0 -50
- package/dist/src/nowiki/hr.d.ts +0 -14
- package/dist/src/nowiki/hr.js +0 -14
- package/dist/src/nowiki/index.d.ts +0 -16
- package/dist/src/nowiki/index.js +0 -21
- package/dist/src/nowiki/list.d.ts +0 -18
- package/dist/src/nowiki/list.js +0 -48
- package/dist/src/nowiki/listBase.d.ts +0 -10
- package/dist/src/nowiki/listBase.js +0 -12
- package/dist/src/nowiki/noinclude.d.ts +0 -12
- package/dist/src/nowiki/noinclude.js +0 -24
- package/dist/src/nowiki/quote.d.ts +0 -20
- package/dist/src/nowiki/quote.js +0 -69
- package/dist/src/onlyinclude.d.ts +0 -16
- package/dist/src/onlyinclude.js +0 -57
- package/dist/src/paramTag/index.d.ts +0 -37
- package/dist/src/paramTag/index.js +0 -68
- package/dist/src/paramTag/inputbox.d.ts +0 -8
- package/dist/src/paramTag/inputbox.js +0 -23
- package/dist/src/parameter.d.ts +0 -71
- package/dist/src/parameter.js +0 -214
- package/dist/src/pre.d.ts +0 -28
- package/dist/src/pre.js +0 -51
- package/dist/src/syntax.d.ts +0 -19
- package/dist/src/syntax.js +0 -34
- package/dist/src/table/base.d.ts +0 -37
- package/dist/src/table/base.js +0 -78
- package/dist/src/table/index.d.ts +0 -230
- package/dist/src/table/index.js +0 -386
- package/dist/src/table/td.d.ts +0 -91
- package/dist/src/table/td.js +0 -270
- package/dist/src/table/tr.d.ts +0 -31
- package/dist/src/table/tr.js +0 -56
- package/dist/src/table/trBase.d.ts +0 -52
- package/dist/src/table/trBase.js +0 -153
- package/dist/src/tagPair/ext.d.ts +0 -39
- package/dist/src/tagPair/ext.js +0 -134
- package/dist/src/tagPair/include.d.ts +0 -39
- package/dist/src/tagPair/include.js +0 -70
- package/dist/src/tagPair/index.d.ts +0 -30
- package/dist/src/tagPair/index.js +0 -76
- package/dist/src/transclude.d.ts +0 -166
- package/dist/src/transclude.js +0 -694
- package/dist/util/constants.js +0 -113
- package/dist/util/debug.js +0 -83
- package/dist/util/diff.js +0 -72
- package/dist/util/lint.js +0 -30
- package/dist/util/string.js +0 -51
- package/errors/README +0 -1
- package/printed/README +0 -1
package/dist/parser/converter.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseConverter = void 0;
|
|
4
|
-
const constants_1 = require("../util/constants");
|
|
5
|
-
const Parser = require("../index");
|
|
6
|
-
const converter_1 = require("../src/converter");
|
|
7
|
-
/**
|
|
8
|
-
* 解析语言变体转换
|
|
9
|
-
* @param text
|
|
10
|
-
* @param config
|
|
11
|
-
* @param accum
|
|
12
|
-
*/
|
|
13
|
-
const parseConverter = (text, config = Parser.getConfig(), accum = []) => {
|
|
14
|
-
const regex1 = /-\{/gu, regex2 = /-\{|\}-/gu, stack = [];
|
|
15
|
-
let regex = regex1, mt = regex.exec(text);
|
|
16
|
-
while (mt) {
|
|
17
|
-
const { 0: syntax, index } = mt;
|
|
18
|
-
if (syntax === '}-') {
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
20
|
-
/;(?=(?:[^;]*?=>)?\s*foo\s*:|(?:\s|\0\d+c\x7F)*$)/u;
|
|
21
|
-
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'), variants = `(?:${config.variants.join('|')})`, rules = temp.split(new RegExp(`;(?=(?:[^;]*?=>)?\\s*${variants}\\s*:|(?:\\s|\0\\d+c\x7F)*$)`, 'u'))
|
|
22
|
-
.map(rule => rule.replace(/\x01/gu, ';'));
|
|
23
|
-
new converter_1.ConverterToken(flags, rules, config, accum);
|
|
24
|
-
text = `${text.slice(0, top.index)}\0${length}v\x7F${text.slice(index + 2)}`;
|
|
25
|
-
if (stack.length === 0) {
|
|
26
|
-
regex = regex1;
|
|
27
|
-
}
|
|
28
|
-
regex.lastIndex = top.index + 3 + String(length).length;
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
stack.push(mt);
|
|
32
|
-
regex = regex2;
|
|
33
|
-
regex.lastIndex = index + 2;
|
|
34
|
-
}
|
|
35
|
-
mt = regex.exec(text);
|
|
36
|
-
}
|
|
37
|
-
return text;
|
|
38
|
-
};
|
|
39
|
-
exports.parseConverter = parseConverter;
|
|
40
|
-
constants_1.parsers['parseConverter'] = __filename;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseExternalLinks = void 0;
|
|
4
|
-
const string_1 = require("../util/string");
|
|
5
|
-
const constants_1 = require("../util/constants");
|
|
6
|
-
const Parser = require("../index");
|
|
7
|
-
const extLink_1 = require("../src/extLink");
|
|
8
|
-
/**
|
|
9
|
-
* 解析外部链接
|
|
10
|
-
* @param wikitext
|
|
11
|
-
* @param config
|
|
12
|
-
* @param accum
|
|
13
|
-
*/
|
|
14
|
-
const parseExternalLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
16
|
-
/\[((?:\[[\da-f:.]+\]|[^[\]\t\n\p{Zs}])[^[\]\t\n\p{Zs}]*(?=[[\]\t\p{Zs}]|\0\d))(\p{Zs}*(?=\P{Zs}))([^\]\n]*)\]/giu;
|
|
17
|
-
const regex = new RegExp(`\\[((?:(?:${config.protocol}|//)${string_1.extUrlCharFirst}|\0\\d+m\x7F)${string_1.extUrlChar}(?=[[\\]<>"\\t\\p{Zs}]|\0\\d))`
|
|
18
|
-
+ '(\\p{Zs}*(?=\\P{Zs}))([^\\]\x01-\x08\x0A-\x1F\uFFFD]*)\\]', 'giu');
|
|
19
|
-
return wikitext.replace(regex, (_, url, space, text) => {
|
|
20
|
-
const { length } = accum, mt = /&[lg]t;/u.exec(url);
|
|
21
|
-
if (mt) {
|
|
22
|
-
url = url.slice(0, mt.index);
|
|
23
|
-
space = '';
|
|
24
|
-
text = `${url.slice(mt.index)}${space}${text}`;
|
|
25
|
-
}
|
|
26
|
-
new extLink_1.ExtLinkToken(url, space, text, config, accum);
|
|
27
|
-
return `\0${length}w\x7F`;
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
exports.parseExternalLinks = parseExternalLinks;
|
|
31
|
-
constants_1.parsers['parseExternalLinks'] = __filename;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseHrAndDoubleUnderscore = void 0;
|
|
4
|
-
const constants_1 = require("../util/constants");
|
|
5
|
-
const Parser = require("../index");
|
|
6
|
-
const hr_1 = require("../src/nowiki/hr");
|
|
7
|
-
const doubleUnderscore_1 = require("../src/nowiki/doubleUnderscore");
|
|
8
|
-
const heading_1 = require("../src/heading");
|
|
9
|
-
/**
|
|
10
|
-
* 解析`<hr>`和状态开关
|
|
11
|
-
* @param {Token} root 根节点
|
|
12
|
-
* @param config
|
|
13
|
-
* @param accum
|
|
14
|
-
*/
|
|
15
|
-
const parseHrAndDoubleUnderscore = ({ firstChild: { data }, type, name }, config = Parser.getConfig(), accum = []) => {
|
|
16
|
-
const { doubleUnderscore } = config, insensitive = new Set(doubleUnderscore[0]), sensitive = new Set(doubleUnderscore[1]);
|
|
17
|
-
if (type !== 'root' && (type !== 'ext-inner' || name !== 'poem')) {
|
|
18
|
-
data = `\0${data}`;
|
|
19
|
-
}
|
|
20
|
-
data = data.replace(/^((?:\0\d+c\x7F)*)(-{4,})/gmu, (_, lead, m) => {
|
|
21
|
-
new hr_1.HrToken(m, config, accum);
|
|
22
|
-
return `${lead}\0${accum.length - 1}r\x7F`;
|
|
23
|
-
}).replace(new RegExp(`__(${doubleUnderscore.flat().join('|')})__`, 'giu'), (m, p1) => {
|
|
24
|
-
const caseSensitive = sensitive.has(p1);
|
|
25
|
-
if (caseSensitive || insensitive.has(p1.toLowerCase())) {
|
|
26
|
-
new doubleUnderscore_1.DoubleUnderscoreToken(p1, caseSensitive, config, accum);
|
|
27
|
-
return `\0${accum.length - 1}u\x7F`;
|
|
28
|
-
}
|
|
29
|
-
return m;
|
|
30
|
-
}).replace(/^((?:\0\d+c\x7F)*)(={1,6})(.+)\2((?:[^\S\n]|\0\d+c\x7F)*)$/gmu, (_, lead, equals, heading, trail) => {
|
|
31
|
-
const text = `${lead}\0${accum.length}h\x7F`;
|
|
32
|
-
new heading_1.HeadingToken(equals.length, [heading, trail], config, accum);
|
|
33
|
-
return text;
|
|
34
|
-
});
|
|
35
|
-
return type === 'root' || type === 'ext-inner' && name === 'poem' ? data : data.slice(1);
|
|
36
|
-
};
|
|
37
|
-
exports.parseHrAndDoubleUnderscore = parseHrAndDoubleUnderscore;
|
|
38
|
-
constants_1.parsers['parseHrAndDoubleUnderscore'] = __filename;
|
package/dist/parser/html.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseHtml = void 0;
|
|
4
|
-
const constants_1 = require("../util/constants");
|
|
5
|
-
const Parser = require("../index");
|
|
6
|
-
const attributes_1 = require("../src/attributes");
|
|
7
|
-
const html_1 = require("../src/html");
|
|
8
|
-
/**
|
|
9
|
-
* 解析HTML标签
|
|
10
|
-
* @param wikitext
|
|
11
|
-
* @param config
|
|
12
|
-
* @param accum
|
|
13
|
-
*/
|
|
14
|
-
const parseHtml = (wikitext, config = Parser.getConfig(), accum = []) => {
|
|
15
|
-
const regex = /^(\/?)([a-z][^\s/>]*)((?:\s|\/(?!>))[^>]*?)?(\/?>)([^<]*)$/iu, elements = new Set(config.html.flat()), bits = wikitext.split('<');
|
|
16
|
-
let text = bits.shift();
|
|
17
|
-
for (const x of bits) {
|
|
18
|
-
const mt = regex.exec(x), t = mt?.[2], name = t?.toLowerCase();
|
|
19
|
-
if (!mt || !elements.has(name)) {
|
|
20
|
-
text += `<${x}`;
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
const [, slash, , params = '', brace, rest] = mt, attr = new attributes_1.AttributesToken(params, 'html-attrs', name, config, accum), itemprop = attr.getAttr('itemprop');
|
|
24
|
-
if (name === 'meta' && (itemprop === undefined || attr.getAttr('content') === undefined)
|
|
25
|
-
|| name === 'link' && (itemprop === undefined || attr.getAttr('href') === undefined)) {
|
|
26
|
-
text += `<${x}`;
|
|
27
|
-
accum.pop();
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
text += `\0${accum.length}x\x7F${rest}`;
|
|
31
|
-
new html_1.HtmlToken(t, attr, slash === '/', brace === '/>', config, accum);
|
|
32
|
-
}
|
|
33
|
-
return text;
|
|
34
|
-
};
|
|
35
|
-
exports.parseHtml = parseHtml;
|
|
36
|
-
constants_1.parsers['parseHtml'] = __filename;
|
package/dist/parser/links.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseLinks = void 0;
|
|
4
|
-
const constants_1 = require("../util/constants");
|
|
5
|
-
const Parser = require("../index");
|
|
6
|
-
const index_1 = require("../src/link/index");
|
|
7
|
-
const file_1 = require("../src/link/file");
|
|
8
|
-
const category_1 = require("../src/link/category");
|
|
9
|
-
/**
|
|
10
|
-
* 解析内部链接
|
|
11
|
-
* @param wikitext
|
|
12
|
-
* @param config
|
|
13
|
-
* @param accum
|
|
14
|
-
*/
|
|
15
|
-
const parseLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
|
|
16
|
-
const { parseQuotes } = require('./quotes');
|
|
17
|
-
const regex = /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(?:(\||\0\d+!\x7F)(.*?[^\]]))?\]\](.*)$/su, regexImg = /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(\||\0\d+!\x7F)(.*)$/su, regexExt = new RegExp(`^\\s*(?:${config.protocol}|//)`, 'iu'), bits = wikitext.split('[[');
|
|
18
|
-
let s = bits.shift();
|
|
19
|
-
for (let i = 0; i < bits.length; i++) {
|
|
20
|
-
let mightBeImg = false, link, delimiter, text, after;
|
|
21
|
-
const x = bits[i], m = regex.exec(x);
|
|
22
|
-
if (m) {
|
|
23
|
-
[, link, delimiter, text, after] = m;
|
|
24
|
-
if (after.startsWith(']') && text?.includes('[')) {
|
|
25
|
-
text += ']';
|
|
26
|
-
after = after.slice(1);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
const m2 = regexImg.exec(x);
|
|
31
|
-
if (m2) {
|
|
32
|
-
mightBeImg = true;
|
|
33
|
-
[, link, delimiter, text] = m2;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
if (link === undefined || regexExt.test(link) || /\0\d+[exhbru]\x7F/u.test(link)) {
|
|
37
|
-
s += `[[${x}`;
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
const force = link.trim().startsWith(':');
|
|
41
|
-
if (force && mightBeImg) {
|
|
42
|
-
s += `[[${x}`;
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
const title = Parser.normalizeTitle(link, 0, false, config, true, true, true), { ns, interwiki, valid, } = title;
|
|
46
|
-
if (!valid) {
|
|
47
|
-
s += `[[${x}`;
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
else if (mightBeImg) {
|
|
51
|
-
if (interwiki || ns !== 6) {
|
|
52
|
-
s += `[[${x}`;
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
let found = false;
|
|
56
|
-
for (i++; i < bits.length; i++) {
|
|
57
|
-
const next = bits[i], p = next.split(']]');
|
|
58
|
-
if (p.length > 2) {
|
|
59
|
-
found = true;
|
|
60
|
-
text += `[[${p[0]}]]${p[1]}`;
|
|
61
|
-
after = p.slice(2).join(']]');
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
else if (p.length === 2) {
|
|
65
|
-
text += `[[${p[0]}]]${p[1]}`;
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
text += `[[${next}`;
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
text = (0, exports.parseLinks)(text, config, accum);
|
|
73
|
-
if (!found) {
|
|
74
|
-
s += `[[${link}${delimiter}${text}`;
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
text &&= parseQuotes(text, config, accum);
|
|
79
|
-
s += `\0${accum.length}l\x7F${after}`;
|
|
80
|
-
let SomeLinkToken = index_1.LinkToken;
|
|
81
|
-
if (!force) {
|
|
82
|
-
if (!interwiki && ns === 6) {
|
|
83
|
-
SomeLinkToken = file_1.FileToken;
|
|
84
|
-
}
|
|
85
|
-
else if (!interwiki && ns === 14) {
|
|
86
|
-
SomeLinkToken = category_1.CategoryToken;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
new SomeLinkToken(link, text, config, accum, delimiter);
|
|
90
|
-
}
|
|
91
|
-
return s;
|
|
92
|
-
};
|
|
93
|
-
exports.parseLinks = parseLinks;
|
|
94
|
-
constants_1.parsers['parseLinks'] = __filename;
|
package/dist/parser/list.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseList = void 0;
|
|
4
|
-
const constants_1 = require("../util/constants");
|
|
5
|
-
const Parser = require("../index");
|
|
6
|
-
const list_1 = require("../src/nowiki/list");
|
|
7
|
-
const dd_1 = require("../src/nowiki/dd");
|
|
8
|
-
/**
|
|
9
|
-
* 解析列表
|
|
10
|
-
* @param wikitext
|
|
11
|
-
* @param config
|
|
12
|
-
* @param accum
|
|
13
|
-
*/
|
|
14
|
-
const parseList = (wikitext, config = Parser.getConfig(), accum = []) => {
|
|
15
|
-
const mt = /^((?:\0\d+c\x7F)*)([;:*#]+)/u.exec(wikitext);
|
|
16
|
-
if (!mt) {
|
|
17
|
-
return wikitext;
|
|
18
|
-
}
|
|
19
|
-
const [total, comment, prefix] = mt;
|
|
20
|
-
let text = `${comment}\0${accum.length}d\x7F${wikitext.slice(total.length)}`, dt = prefix.split(';').length - 1;
|
|
21
|
-
new list_1.ListToken(prefix, config, accum);
|
|
22
|
-
if (!dt) {
|
|
23
|
-
return text;
|
|
24
|
-
}
|
|
25
|
-
let regex = /:+|-\{/gu, ex = regex.exec(text), lc = 0;
|
|
26
|
-
/**
|
|
27
|
-
* 创建`DdToken`
|
|
28
|
-
* @param syntax `:`
|
|
29
|
-
* @param index 起点
|
|
30
|
-
*/
|
|
31
|
-
const dd = (syntax, index) => {
|
|
32
|
-
new dd_1.DdToken(syntax, config, accum);
|
|
33
|
-
return `${text.slice(0, index)}\0${accum.length - 1}d\x7F${text.slice(index + syntax.length)}`;
|
|
34
|
-
};
|
|
35
|
-
while (ex && dt) {
|
|
36
|
-
const { 0: syntax, index } = ex;
|
|
37
|
-
if (syntax.startsWith(':')) {
|
|
38
|
-
if (syntax.length >= dt) {
|
|
39
|
-
return dd(syntax.slice(0, dt), index);
|
|
40
|
-
}
|
|
41
|
-
dt -= syntax.length;
|
|
42
|
-
regex.lastIndex = index + 4 + String(accum.length).length;
|
|
43
|
-
text = dd(syntax, index);
|
|
44
|
-
}
|
|
45
|
-
else if (syntax === '-{') {
|
|
46
|
-
if (!lc) {
|
|
47
|
-
const { lastIndex } = regex;
|
|
48
|
-
regex = /-\{|\}-/gu;
|
|
49
|
-
regex.lastIndex = lastIndex;
|
|
50
|
-
}
|
|
51
|
-
lc++;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
lc--;
|
|
55
|
-
if (!lc) {
|
|
56
|
-
const { lastIndex } = regex;
|
|
57
|
-
regex = /:+|-\{/gu;
|
|
58
|
-
regex.lastIndex = lastIndex;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
ex = regex.exec(text);
|
|
62
|
-
}
|
|
63
|
-
return text;
|
|
64
|
-
};
|
|
65
|
-
exports.parseList = parseList;
|
|
66
|
-
constants_1.parsers['parseList'] = __filename;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseMagicLinks = void 0;
|
|
4
|
-
const string_1 = require("../util/string");
|
|
5
|
-
const constants_1 = require("../util/constants");
|
|
6
|
-
const Parser = require("../index");
|
|
7
|
-
const magicLink_1 = require("../src/magicLink");
|
|
8
|
-
/**
|
|
9
|
-
* 解析自由外链
|
|
10
|
-
* @param wikitext
|
|
11
|
-
* @param config
|
|
12
|
-
* @param accum
|
|
13
|
-
*/
|
|
14
|
-
const parseMagicLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
16
|
-
/(^|[^\p{L}\d_])((?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])(?:[^[\]<>"\0\t\n\p{Zs}]|\0\d+c\x7F)*)/giu;
|
|
17
|
-
const regex = new RegExp(`(^|[^\\p{L}\\d_])(?:${config.protocol})(${string_1.extUrlCharFirst}${string_1.extUrlChar})`, 'giu');
|
|
18
|
-
return wikitext.replace(regex, (m, lead, p1) => {
|
|
19
|
-
let trail = '', url = lead ? m.slice(1) : m;
|
|
20
|
-
const m2 = /&(?:lt|gt|nbsp|#x0*(?:3[ce]|a0)|#0*(?:6[02]|160));/iu.exec(url);
|
|
21
|
-
if (m2) {
|
|
22
|
-
trail = url.slice(m2.index);
|
|
23
|
-
url = url.slice(0, m2.index);
|
|
24
|
-
}
|
|
25
|
-
const sep = new RegExp(`[,;.:!?${url.includes('(') ? '' : ')'}]+$`, 'u'), sepChars = sep.exec(url);
|
|
26
|
-
if (sepChars) {
|
|
27
|
-
let correction = 0;
|
|
28
|
-
if (sepChars[0].startsWith(';') && /&(?:[a-z]+|#x[\da-f]+|#\d+)$/iu.test(url.slice(0, sepChars.index))) {
|
|
29
|
-
correction = 1;
|
|
30
|
-
}
|
|
31
|
-
trail = `${url.slice(sepChars.index + correction)}${trail}`;
|
|
32
|
-
url = url.slice(0, sepChars.index + correction);
|
|
33
|
-
}
|
|
34
|
-
if (trail.length >= p1.length) {
|
|
35
|
-
return m;
|
|
36
|
-
}
|
|
37
|
-
new magicLink_1.MagicLinkToken(url, false, config, accum);
|
|
38
|
-
return `${lead}\0${accum.length - 1}w\x7F${trail}`;
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
exports.parseMagicLinks = parseMagicLinks;
|
|
42
|
-
constants_1.parsers['parseMagicLinks'] = __filename;
|
package/dist/parser/quotes.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseQuotes = void 0;
|
|
4
|
-
const constants_1 = require("../util/constants");
|
|
5
|
-
const Parser = require("../index");
|
|
6
|
-
const quote_1 = require("../src/nowiki/quote");
|
|
7
|
-
/**
|
|
8
|
-
* 解析单引号
|
|
9
|
-
* @param wikitext
|
|
10
|
-
* @param config
|
|
11
|
-
* @param accum
|
|
12
|
-
*/
|
|
13
|
-
const parseQuotes = (wikitext, config = Parser.getConfig(), accum = []) => {
|
|
14
|
-
const arr = wikitext.split(/('{2,})/u), { length } = arr;
|
|
15
|
-
if (length === 1) {
|
|
16
|
-
return wikitext;
|
|
17
|
-
}
|
|
18
|
-
let nBold = 0, nItalic = 0, firstSingle, firstMulti, firstSpace;
|
|
19
|
-
for (let i = 1; i < length; i += 2) {
|
|
20
|
-
const { length: len } = arr[i];
|
|
21
|
-
switch (len) {
|
|
22
|
-
case 2:
|
|
23
|
-
nItalic++;
|
|
24
|
-
break;
|
|
25
|
-
case 4:
|
|
26
|
-
arr[i - 1] += `'`;
|
|
27
|
-
arr[i] = `'''`;
|
|
28
|
-
// fall through
|
|
29
|
-
case 3:
|
|
30
|
-
nBold++;
|
|
31
|
-
if (firstSingle !== undefined) {
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
else if (arr[i - 1].endsWith(' ')) {
|
|
35
|
-
if (firstMulti === undefined && firstSpace === undefined) {
|
|
36
|
-
firstSpace = i;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
else if (arr[i - 1].slice(-2, -1) === ' ') {
|
|
40
|
-
firstSingle = i;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
firstMulti ??= i;
|
|
44
|
-
}
|
|
45
|
-
break;
|
|
46
|
-
default:
|
|
47
|
-
arr[i - 1] += `'`.repeat(len - 5);
|
|
48
|
-
arr[i] = `'''''`;
|
|
49
|
-
nItalic++;
|
|
50
|
-
nBold++;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (nItalic % 2 === 1 && nBold % 2 === 1) {
|
|
54
|
-
const i = firstSingle ?? firstMulti ?? firstSpace;
|
|
55
|
-
if (i !== undefined) {
|
|
56
|
-
arr[i] = `''`;
|
|
57
|
-
arr[i - 1] += `'`;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
for (let i = 1; i < length; i += 2) {
|
|
61
|
-
new quote_1.QuoteToken(arr[i], config, accum);
|
|
62
|
-
arr[i] = `\0${accum.length - 1}q\x7F`;
|
|
63
|
-
}
|
|
64
|
-
return arr.join('');
|
|
65
|
-
};
|
|
66
|
-
exports.parseQuotes = parseQuotes;
|
|
67
|
-
constants_1.parsers['parseQuotes'] = __filename;
|
package/dist/parser/selector.js
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseSelector = void 0;
|
|
4
|
-
const constants_1 = require("../util/constants");
|
|
5
|
-
const string_1 = require("../util/string");
|
|
6
|
-
const Parser = require("../index");
|
|
7
|
-
const simplePseudos = new Set([
|
|
8
|
-
'root',
|
|
9
|
-
'first-child',
|
|
10
|
-
'first-of-type',
|
|
11
|
-
'last-child',
|
|
12
|
-
'last-of-type',
|
|
13
|
-
'only-child',
|
|
14
|
-
'only-of-type',
|
|
15
|
-
'empty',
|
|
16
|
-
'parent',
|
|
17
|
-
'header',
|
|
18
|
-
'hidden',
|
|
19
|
-
'visible',
|
|
20
|
-
'only-whitespace',
|
|
21
|
-
'any-link',
|
|
22
|
-
'local-link',
|
|
23
|
-
'invalid',
|
|
24
|
-
'required',
|
|
25
|
-
'optional',
|
|
26
|
-
]);
|
|
27
|
-
const complexPseudos = [
|
|
28
|
-
'is',
|
|
29
|
-
'not',
|
|
30
|
-
'nth-child',
|
|
31
|
-
'nth-of-type',
|
|
32
|
-
'nth-last-child',
|
|
33
|
-
'nth-last-of-type',
|
|
34
|
-
'contains',
|
|
35
|
-
'has',
|
|
36
|
-
'lang',
|
|
37
|
-
'regex',
|
|
38
|
-
];
|
|
39
|
-
const specialChars = [
|
|
40
|
-
['[', '['],
|
|
41
|
-
[']', ']'],
|
|
42
|
-
['(', '('],
|
|
43
|
-
[')', ')'],
|
|
44
|
-
['"', '"'],
|
|
45
|
-
[`'`, '''],
|
|
46
|
-
[':', ':'],
|
|
47
|
-
['\\', '\'],
|
|
48
|
-
['&', '&'],
|
|
49
|
-
];
|
|
50
|
-
const pseudoRegex = new RegExp(`:(${complexPseudos.join('|')})$`, 'u'), regularRegex = /[[(,>+~]|\s+/u, attributeRegex = /^\s*(\w+)\s*(?:([~|^$*!]?=)\s*("[^"]*"|'[^']*'|[^\s[\]]+)(?:\s+(i))?\s*)?\]/u, functionRegex = /^(\s*"[^"]*"\s*|\s*'[^']*'\s*|[^()]*)\)/u, grouping = new Set([',', '>', '+', '~']), combinator = new Set(['>', '+', '~', '']);
|
|
51
|
-
/**
|
|
52
|
-
* 清理转义符号
|
|
53
|
-
* @param selector
|
|
54
|
-
*/
|
|
55
|
-
const sanitize = (selector) => {
|
|
56
|
-
for (const [c, escaped] of specialChars) {
|
|
57
|
-
selector = selector.replace(new RegExp((0, string_1.escapeRegExp)(`\\${c}`), 'gu'), escaped);
|
|
58
|
-
}
|
|
59
|
-
return selector;
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* 还原转义符号
|
|
63
|
-
* @param selector
|
|
64
|
-
*/
|
|
65
|
-
const desanitize = (selector) => {
|
|
66
|
-
for (const [c, escaped] of specialChars) {
|
|
67
|
-
selector = selector.replace(new RegExp(escaped, 'gu'), c);
|
|
68
|
-
}
|
|
69
|
-
return selector.trim();
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* 去除首尾的引号
|
|
73
|
-
* @param val 属性值或伪选择器函数的参数
|
|
74
|
-
*/
|
|
75
|
-
const deQuote = (val) => /^(["']).*\1$/u.test(val) ? val.slice(1, -1) : val.trim();
|
|
76
|
-
/**
|
|
77
|
-
* 解析选择器
|
|
78
|
-
* @param selector
|
|
79
|
-
* @throws `SyntaxError` 非法的选择器
|
|
80
|
-
*/
|
|
81
|
-
const parseSelector = (selector) => {
|
|
82
|
-
selector = selector.trim();
|
|
83
|
-
const stack = [[[]]];
|
|
84
|
-
let sanitized = sanitize(selector), regex = regularRegex, mt = regex.exec(sanitized), [condition] = stack, [step] = condition;
|
|
85
|
-
/**
|
|
86
|
-
* 解析简单伪选择器
|
|
87
|
-
* @param index 伪选择器的终点位置
|
|
88
|
-
* @throws `SyntaxError` 非法的选择器
|
|
89
|
-
*/
|
|
90
|
-
const pushSimple = (index) => {
|
|
91
|
-
const str = sanitized.slice(0, index), pieces = str.trim().split(':'),
|
|
92
|
-
// eslint-disable-next-line unicorn/explicit-length-check
|
|
93
|
-
i = pieces.slice(1).findIndex(pseudo => simplePseudos.has(pseudo)) + 1 || pieces.length;
|
|
94
|
-
if (pieces.slice(i).some(pseudo => !simplePseudos.has(pseudo))) {
|
|
95
|
-
throw new SyntaxError(`非法的选择器!\n${str}\n可能需要将':'转义为'\\:'。`);
|
|
96
|
-
}
|
|
97
|
-
step.push(desanitize(pieces.slice(0, i).join(':')), ...pieces.slice(i).map(piece => `:${piece}`));
|
|
98
|
-
};
|
|
99
|
-
while (mt) {
|
|
100
|
-
let { 0: syntax, index } = mt;
|
|
101
|
-
if (syntax.trim() === '') {
|
|
102
|
-
index += syntax.length;
|
|
103
|
-
const char = sanitized[index];
|
|
104
|
-
syntax = grouping.has(char) ? char : '';
|
|
105
|
-
}
|
|
106
|
-
if (syntax === ',') { // 情形1:并列
|
|
107
|
-
pushSimple(index);
|
|
108
|
-
condition = [[]];
|
|
109
|
-
[step] = condition;
|
|
110
|
-
stack.push(condition);
|
|
111
|
-
}
|
|
112
|
-
else if (combinator.has(syntax)) { // 情形2:关系
|
|
113
|
-
pushSimple(index);
|
|
114
|
-
if (!step.some(Boolean)) {
|
|
115
|
-
throw new SyntaxError(`非法的选择器!\n${selector}\n可能需要通用选择器'*'。`);
|
|
116
|
-
}
|
|
117
|
-
step.relation = syntax;
|
|
118
|
-
step = [];
|
|
119
|
-
condition.push(step);
|
|
120
|
-
}
|
|
121
|
-
else if (syntax === '[') { // 情形3:属性开启
|
|
122
|
-
pushSimple(index);
|
|
123
|
-
regex = attributeRegex;
|
|
124
|
-
}
|
|
125
|
-
else if (syntax.endsWith(']')) { // 情形4:属性闭合
|
|
126
|
-
mt[3] &&= desanitize(deQuote(mt[3]));
|
|
127
|
-
step.push(mt.slice(1));
|
|
128
|
-
regex = regularRegex;
|
|
129
|
-
}
|
|
130
|
-
else if (syntax === '(') { // 情形5:伪选择器开启
|
|
131
|
-
const pseudoExec = pseudoRegex.exec(sanitized.slice(0, index));
|
|
132
|
-
if (!pseudoExec) {
|
|
133
|
-
throw new SyntaxError(`非法的选择器!\n${desanitize(sanitized)}\n请检查伪选择器是否存在。`);
|
|
134
|
-
}
|
|
135
|
-
pushSimple(pseudoExec.index);
|
|
136
|
-
step.push(pseudoExec[1]); // 临时存放复杂伪选择器
|
|
137
|
-
regex = functionRegex;
|
|
138
|
-
}
|
|
139
|
-
else { // 情形6:伪选择器闭合
|
|
140
|
-
mt.push(step.pop());
|
|
141
|
-
mt[1] &&= deQuote(mt[1]);
|
|
142
|
-
step.push(mt.slice(1));
|
|
143
|
-
regex = regularRegex;
|
|
144
|
-
}
|
|
145
|
-
sanitized = sanitized.slice(index + syntax.length);
|
|
146
|
-
if (grouping.has(syntax)) {
|
|
147
|
-
sanitized = sanitized.trim();
|
|
148
|
-
}
|
|
149
|
-
mt = regex.exec(sanitized);
|
|
150
|
-
}
|
|
151
|
-
if (regex === regularRegex) {
|
|
152
|
-
pushSimple(Infinity);
|
|
153
|
-
const pseudos = new Set(stack.flat(2).filter((e) => typeof e === 'string' && e.startsWith(':')));
|
|
154
|
-
if (pseudos.size > 0) {
|
|
155
|
-
Parser.warn('检测到伪选择器,请确认是否需要将":"转义成"\\:"。', pseudos);
|
|
156
|
-
}
|
|
157
|
-
return stack;
|
|
158
|
-
}
|
|
159
|
-
throw new SyntaxError(`非法的选择器!\n${selector}\n检测到未闭合的'${regex === attributeRegex ? '[' : '('}'`);
|
|
160
|
-
};
|
|
161
|
-
exports.parseSelector = parseSelector;
|
|
162
|
-
constants_1.parsers['parseSelector'] = __filename;
|