wikiparser-node 1.29.0 → 1.29.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/bundle-es8.min.js +24 -24
- package/bundle/bundle-lsp.min.js +19 -19
- package/bundle/bundle.min.js +22 -22
- package/dist/addon/transclude.js +19 -2
- package/dist/bin/config.js +1 -1
- package/dist/lib/document.js +16 -12
- package/dist/lib/lsp.js +81 -79
- package/dist/lib/text.js +7 -14
- package/dist/mixin/elementLike.d.ts +1 -1
- package/dist/parser/commentAndExt.js +1 -1
- package/dist/src/atom.d.ts +1 -1
- package/dist/src/atom.js +0 -2
- package/dist/src/attribute.js +4 -2
- package/dist/src/attributes.d.ts +1 -0
- package/dist/src/attributes.js +8 -1
- package/dist/src/converter.js +1 -2
- package/dist/src/converterFlags.js +2 -1
- package/dist/src/converterRule.d.ts +8 -8
- package/dist/src/converterRule.js +34 -9
- package/dist/src/hidden.js +2 -1
- package/dist/src/imageParameter.d.ts +6 -1
- package/dist/src/imageParameter.js +308 -252
- package/dist/src/index.js +10 -8
- package/dist/src/link/base.js +2 -2
- package/dist/src/nowiki/index.js +35 -33
- package/dist/src/table/index.js +3 -2
- package/dist/src/tag/html.js +1 -1
- package/dist/src/tag/tvar.js +2 -1
- package/dist/src/transclude.d.ts +4 -2
- package/dist/src/transclude.js +8 -7
- package/dist/util/html.js +2 -4
- package/extensions/dist/base.js +1 -1
- package/package.json +2 -2
package/dist/addon/transclude.js
CHANGED
|
@@ -12,18 +12,32 @@ const index_2 = require("../src/index");
|
|
|
12
12
|
const transclude_1 = require("../src/transclude");
|
|
13
13
|
const parameter_1 = require("../src/parameter");
|
|
14
14
|
const atom_1 = require("../src/atom");
|
|
15
|
+
/**
|
|
16
|
+
* 调整最后一个子节点的换行符
|
|
17
|
+
* @param token 魔术字或模板节点
|
|
18
|
+
*/
|
|
19
|
+
const format = (token) => {
|
|
20
|
+
const { lastChild, type } = token, isParameter = lastChild.type === 'parameter';
|
|
21
|
+
if (!(type === 'template' ? isParameter && lastChild.anon : lastChild.type === 'magic-word-name')
|
|
22
|
+
&& !lastChild.toString().endsWith('\n')) {
|
|
23
|
+
(isParameter ? lastChild.lastChild : lastChild).insertAt('\n');
|
|
24
|
+
}
|
|
25
|
+
};
|
|
15
26
|
transclude_1.TranscludeToken.prototype.newAnonArg =
|
|
16
27
|
/** @implements */
|
|
17
|
-
function (val) {
|
|
28
|
+
function (val, newline) {
|
|
18
29
|
const { childNodes } = index_1.default.parseWithRef(val, this), token = debug_1.Shadow.run(
|
|
19
30
|
// @ts-expect-error abstract class
|
|
20
31
|
() => new parameter_1.ParameterToken(undefined, undefined, this.getAttribute('config')));
|
|
21
32
|
token.lastChild.concat(childNodes); // eslint-disable-line unicorn/prefer-spread
|
|
33
|
+
if (newline) {
|
|
34
|
+
format(this);
|
|
35
|
+
}
|
|
22
36
|
return this.insertAt(token);
|
|
23
37
|
};
|
|
24
38
|
transclude_1.TranscludeToken.prototype.setValue =
|
|
25
39
|
/** @implements */
|
|
26
|
-
function (key, value) {
|
|
40
|
+
function (key, value, newline) {
|
|
27
41
|
/* istanbul ignore if */
|
|
28
42
|
if (!this.isTemplate()) {
|
|
29
43
|
throw new Error('TranscludeToken.setValue method is only for templates!');
|
|
@@ -38,6 +52,9 @@ transclude_1.TranscludeToken.prototype.setValue =
|
|
|
38
52
|
() => new parameter_1.ParameterToken(undefined, undefined, this.getAttribute('config')));
|
|
39
53
|
token.firstChild.safeAppend(k.childNodes);
|
|
40
54
|
token.lastChild.concat(v.childNodes); // eslint-disable-line unicorn/prefer-spread
|
|
55
|
+
if (newline) {
|
|
56
|
+
format(this);
|
|
57
|
+
}
|
|
41
58
|
this.insertAt(token);
|
|
42
59
|
};
|
|
43
60
|
transclude_1.TranscludeToken.prototype.replaceTemplate =
|
package/dist/bin/config.js
CHANGED
package/dist/lib/document.js
CHANGED
|
@@ -9,12 +9,14 @@ const common_1 = require("@bhsd/common");
|
|
|
9
9
|
/* NOT FOR BROWSER */
|
|
10
10
|
const constants_1 = require("../util/constants");
|
|
11
11
|
exports.texvcjs = (() => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
NPM: { // eslint-disable-line no-unused-labels
|
|
13
|
+
try {
|
|
14
|
+
return require('mathoid-texvcjs');
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
/* istanbul ignore next */
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
18
20
|
}
|
|
19
21
|
})();
|
|
20
22
|
exports.jsonTags = ['templatedata', 'mapframe', 'maplink'];
|
|
@@ -72,12 +74,14 @@ exports.htmlData = (() => {
|
|
|
72
74
|
}
|
|
73
75
|
})();
|
|
74
76
|
exports.stylelint = (async () => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
NPM: { // eslint-disable-line no-unused-labels
|
|
78
|
+
try {
|
|
79
|
+
return (await import('stylelint')).default;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
/* istanbul ignore next */
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
81
85
|
}
|
|
82
86
|
})();
|
|
83
87
|
/** embedded document */
|
package/dist/lib/lsp.js
CHANGED
|
@@ -21,10 +21,6 @@ const stylelint_util_1 = require("@bhsd/stylelint-util");
|
|
|
21
21
|
const search_1 = __importDefault(require("../util/search"));
|
|
22
22
|
const constants_1 = require("../util/constants");
|
|
23
23
|
const document_1 = require("./document");
|
|
24
|
-
/** @see https://www.npmjs.com/package/stylelint-config-recommended */
|
|
25
|
-
const cssRules = { 'block-no-empty': null }, sources = { 'invalid-css': 'css', 'invalid-math': 'texvc' }, jsonSelector = document_1.jsonTags.map(s => `ext#${s}`).join(), scores = new Map();
|
|
26
|
-
let colors;
|
|
27
|
-
/* NOT FOR BROWSER ONLY END */
|
|
28
24
|
exports.tasks = new WeakMap();
|
|
29
25
|
const refTags = new Set(['ref']), referencesTags = new Set(['ref', 'references']), nameAttrs = new Set(['name', 'follow']), groupAttrs = new Set(['group']), renameTypes = new Set([
|
|
30
26
|
'arg-name',
|
|
@@ -232,6 +228,9 @@ const getFixAll = (root, rule) => {
|
|
|
232
228
|
];
|
|
233
229
|
};
|
|
234
230
|
/* NOT FOR BROWSER ONLY */
|
|
231
|
+
/** @see https://www.npmjs.com/package/stylelint-config-recommended */
|
|
232
|
+
const cssRules = { 'block-no-empty': null }, sources = { 'invalid-css': 'css', 'invalid-math': 'texvc' }, jsonSelector = document_1.jsonTags.map(s => `ext#${s}`).join(), scores = new Map();
|
|
233
|
+
let colors;
|
|
235
234
|
/**
|
|
236
235
|
* Correct the position of an error.
|
|
237
236
|
* @param height
|
|
@@ -250,21 +249,20 @@ const adjustPos = (height, width, line, column) => {
|
|
|
250
249
|
}
|
|
251
250
|
return [line, column];
|
|
252
251
|
};
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
const getStylelintPos = (rect, bottom, lineOrCode, columnOrOffset) => {
|
|
252
|
+
function getStylelintPos(rect, bottom, lineOrCode, columnOrOffset) {
|
|
253
|
+
if (Array.isArray(columnOrOffset)) {
|
|
254
|
+
return {
|
|
255
|
+
start: getStylelintPos(rect, bottom, lineOrCode, columnOrOffset[0]),
|
|
256
|
+
end: getStylelintPos(rect, bottom, lineOrCode, columnOrOffset[1]),
|
|
257
|
+
};
|
|
258
|
+
}
|
|
261
259
|
const { top, left, height, width } = rect, start = bottom - height - 1;
|
|
262
260
|
if (typeof lineOrCode === 'number') {
|
|
263
261
|
return (0, lint_1.getEndPos)(top, left, ...adjustPos(height, width, lineOrCode - start, columnOrOffset));
|
|
264
262
|
}
|
|
265
263
|
const lines = lineOrCode.slice(0, columnOrOffset).split(/\r?\n/u);
|
|
266
264
|
return getStylelintPos(rect, bottom, lines.length, lines.at(-1).length);
|
|
267
|
-
}
|
|
265
|
+
}
|
|
268
266
|
/**
|
|
269
267
|
* Convert LilyPond errors to VSCode diagnostics.
|
|
270
268
|
* @param root root token
|
|
@@ -519,21 +517,23 @@ class LanguageService {
|
|
|
519
517
|
this.config ??= index_1.default.getConfig();
|
|
520
518
|
const { nsid, ext, html, parserFunction: [insensitive, sensitive, ...other], doubleUnderscore, protocol, img, } = this.config, tags = new Set([ext, html].flat(2));
|
|
521
519
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
522
|
-
/(
|
|
520
|
+
/(?:<(\/?\w*)|(\{{2,4}|\[\[)\s*([^|{}<>[\]\s][^|{}<>[\]#]*)?|(_(?:_(?:(?!__|_{2})[\p{L}\p{N}_])*)?)|(_(?:_(?:(?!__|_{2})[\p{L}\p{N}_])*)?)|(?<!\[)\[([a-z:/]*)|\[\[\s*(?:file|image)\s*:[^[\]{}<>]+\|([^[\]{}<>|=]*)|<(\w+)(?:\s(?:[^<>{}|=\s]+(?:\s*=\s*(?:[^\s"']\S*|(["']).*?\9))?(?=\s))*)?\s(\w*))$/iu;
|
|
523
521
|
const re = new RegExp('(?:' // eslint-disable-line prefer-template
|
|
524
|
-
+ String.raw `<(\/?\w*)` // tag
|
|
522
|
+
+ String.raw `<(\/?\w*)` // tag ($1)
|
|
525
523
|
+ '|'
|
|
526
|
-
+ String.raw `(\{{2,4}|\[\[)\s*([^|{}<>[\]\s][^|{}<>[\]#]*)?` // braces and brackets
|
|
524
|
+
+ String.raw `(\{{2,4}|\[\[)\s*([^|{}<>[\]\s][^|{}<>[\]#]*)?` // braces and brackets ($2, $3)
|
|
527
525
|
+ '|'
|
|
528
|
-
+ String.raw `(
|
|
526
|
+
+ String.raw `(_(?:_(?:(?!__|_{2})[\p{L}\p{N}_])*)?)` // behavior switch ($4)
|
|
529
527
|
+ '|'
|
|
530
|
-
+ String.raw `(
|
|
528
|
+
+ String.raw `(_(?:_(?:(?!__|_{2})[\p{L}\p{N}_])*)?)` // Japanese behavior switch ($5)
|
|
531
529
|
+ '|'
|
|
532
|
-
+ String.raw
|
|
530
|
+
+ String.raw `(?<!\[)\[([a-z:/]*)` // protocol ($6)
|
|
533
531
|
+ '|'
|
|
534
|
-
//
|
|
535
|
-
+
|
|
536
|
-
|
|
532
|
+
+ String.raw `\[\[\s*(?:${Object.entries(nsid).filter(([, v]) => v === 6).map(([k]) => k).join('|')})\s*:[^[\]{}<>]+\|([^[\]{}<>|=]*)` // image parameter ($7)
|
|
533
|
+
+ '|'
|
|
534
|
+
// attribute key ($8, $10)
|
|
535
|
+
+ String.raw `<(\w+)(?:\s(?:[^<>{}|=\s]+(?:\s*=\s*(?:[^\s"']\S*|(["']).*?\9))?(?=\s))*)?\s(\w*)`
|
|
536
|
+
+ ')$', 'iu'), allSwitches = doubleUnderscore.slice(0, 2).flat();
|
|
537
537
|
this.#completionConfig = [
|
|
538
538
|
{
|
|
539
539
|
re,
|
|
@@ -545,9 +545,8 @@ class LanguageService {
|
|
|
545
545
|
Array.isArray(sensitive) ? /* istanbul ignore next */ sensitive : Object.keys(sensitive),
|
|
546
546
|
other,
|
|
547
547
|
].flat(2),
|
|
548
|
-
switches:
|
|
549
|
-
|
|
550
|
-
.map(w => `__${w}__`),
|
|
548
|
+
switches: allSwitches.filter(cm_util_1.isUnderscore).map(w => `__${w}__`),
|
|
549
|
+
jaSwitches: allSwitches.filter(w => !(0, cm_util_1.isUnderscore)(w)),
|
|
551
550
|
protocols: protocol.split('|'),
|
|
552
551
|
params: Object.keys(img)
|
|
553
552
|
.filter(k => k.endsWith('$1') || !k.includes('$1'))
|
|
@@ -566,17 +565,20 @@ class LanguageService {
|
|
|
566
565
|
* @param position position / 位置
|
|
567
566
|
*/
|
|
568
567
|
async provideCompletionItems(text, position) {
|
|
569
|
-
const { re, allTags, functions, switches, protocols, params, tags, ext } = this.#prepareCompletionConfig(), { line, character } = position, curLine = text.split(/\r?\n/u, line + 1)[line], mt = re.exec(curLine?.slice(0, character) ?? ''), [, , iAlias = {}, sAlias = {}] = this.config.doubleUnderscore;
|
|
568
|
+
const { re, allTags, functions, switches, jaSwitches, protocols, params, tags, ext, } = this.#prepareCompletionConfig(), { line, character } = position, curLine = text.split(/\r?\n/u, line + 1)[line], mt = re.exec(curLine?.slice(0, character) ?? ''), [, , iAlias = {}, sAlias = {}] = this.config.doubleUnderscore;
|
|
570
569
|
if (mt?.[1] !== undefined) { // tag
|
|
571
570
|
const closing = mt[1].startsWith('/');
|
|
572
571
|
return getCompletion(allTags, 'Class', mt[1].slice(closing ? 1 : 0), position, closing && !curLine?.slice(character).trim().startsWith('>') ? '>' : '');
|
|
573
572
|
}
|
|
574
|
-
else if (mt?.[4]) { // behavior switch
|
|
575
|
-
|
|
573
|
+
else if (mt?.[4] || mt?.[5] && jaSwitches.length > 0) { // behavior switch
|
|
574
|
+
const isJa = mt[5] !== undefined;
|
|
575
|
+
return getCompletion(isJa ? jaSwitches : switches, 'Constant', mt[isJa ? 5 : 4], position, '', name => {
|
|
576
576
|
if (!this.data) {
|
|
577
577
|
return undefined;
|
|
578
578
|
}
|
|
579
|
-
|
|
579
|
+
else if (!isJa) {
|
|
580
|
+
name = name.slice(2, -2);
|
|
581
|
+
}
|
|
580
582
|
if (name in iAlias) {
|
|
581
583
|
name = iAlias[name];
|
|
582
584
|
}
|
|
@@ -586,8 +588,8 @@ class LanguageService {
|
|
|
586
588
|
return this.#getBehaviorSwitch(name.toLowerCase());
|
|
587
589
|
});
|
|
588
590
|
}
|
|
589
|
-
else if (mt?.[
|
|
590
|
-
return getCompletion(protocols, 'Reference', mt[
|
|
591
|
+
else if (mt?.[6] !== undefined) { // protocol
|
|
592
|
+
return getCompletion(protocols, 'Reference', mt[6], position);
|
|
591
593
|
}
|
|
592
594
|
const root = await this.#queue(text);
|
|
593
595
|
let cur;
|
|
@@ -640,12 +642,12 @@ class LanguageService {
|
|
|
640
642
|
];
|
|
641
643
|
}
|
|
642
644
|
let type, parentNode;
|
|
643
|
-
if (mt?.[
|
|
645
|
+
if (mt?.[8] === undefined) {
|
|
644
646
|
cur = root.elementFromPoint(character, line);
|
|
645
647
|
({ type, parentNode } = cur);
|
|
646
648
|
}
|
|
647
|
-
if (mt?.[
|
|
648
|
-
const index = root.indexFromPos(line, character), match = mt?.[
|
|
649
|
+
if (mt?.[7] !== undefined || type === 'image-parameter') { // image parameter
|
|
650
|
+
const index = root.indexFromPos(line, character), match = mt?.[7]?.trimStart()
|
|
649
651
|
?? this.#text.slice(cur.getAbsoluteIndex(), index).trimStart(), equal = this.#text[index] === '=';
|
|
650
652
|
return [
|
|
651
653
|
...getCompletion(params, 'Property', match, position)
|
|
@@ -655,8 +657,8 @@ class LanguageService {
|
|
|
655
657
|
.map(width => width.text()), 'Unit', match, position),
|
|
656
658
|
];
|
|
657
659
|
}
|
|
658
|
-
else if (mt?.[
|
|
659
|
-
const tag = mt?.[
|
|
660
|
+
else if (mt?.[8] !== undefined || type === 'attr-key') { // attribute key
|
|
661
|
+
const tag = mt?.[8]?.toLowerCase() ?? parentNode.tag, key = mt?.[10]
|
|
660
662
|
?? cur.toString().slice(0, character - root.posFromIndex(cur.getAbsoluteIndex()).left);
|
|
661
663
|
if (!tags.has(tag)) {
|
|
662
664
|
return undefined;
|
|
@@ -790,48 +792,47 @@ class LanguageService {
|
|
|
790
792
|
/* eslint-disable @stylistic/operator-linebreak */
|
|
791
793
|
cssDiagnostics = await document_1.stylelint ?
|
|
792
794
|
await (async () => {
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
795
|
+
NPM: { // eslint-disable-line no-unused-labels
|
|
796
|
+
const tokens = this.findStyleTokens();
|
|
797
|
+
if (tokens.length === 0) {
|
|
798
|
+
return [];
|
|
799
|
+
}
|
|
800
|
+
const code = tokens.map(({ type, tag, lastChild }, i) => `${type === 'ext-attr' ? 'div' : tag}#${i}{\n${(0, common_1.sanitizeInlineStyle)(lastChild.toString())}\n}`).join('\n'), cssErrors = await (0, stylelint_util_1.styleLint)((await document_1.stylelint), code, cssRules);
|
|
801
|
+
if (cssErrors.length === 0) {
|
|
802
|
+
return [];
|
|
803
|
+
}
|
|
804
|
+
const rects = tokens.map(({ lastChild }) => lastChild.getBoundingClientRect());
|
|
805
|
+
let acc = 0;
|
|
806
|
+
const bottoms = rects.map(({ height }) => {
|
|
807
|
+
acc += height + 2;
|
|
808
|
+
return acc;
|
|
809
|
+
});
|
|
810
|
+
return cssErrors.map(({ rule, text: msg, severity, line, column, endLine = line, endColumn = column, fix, }) => {
|
|
811
|
+
const i = (0, search_1.default)(bottoms, line, (bottom, needle) => bottom - needle);
|
|
812
|
+
return {
|
|
813
|
+
range: {
|
|
814
|
+
start: getStylelintPos(rects[i], bottoms[i], line, column - 1),
|
|
815
|
+
end: getStylelintPos(rects[i], bottoms[i], endLine, endColumn - 1),
|
|
816
|
+
},
|
|
817
|
+
severity: severity === 'error' ? 1 : 2,
|
|
818
|
+
source: 'Stylelint',
|
|
819
|
+
code: rule,
|
|
820
|
+
message: msg.slice(0, msg.lastIndexOf('(') - 1),
|
|
821
|
+
...fix
|
|
822
|
+
? {
|
|
823
|
+
data: [
|
|
824
|
+
{
|
|
825
|
+
range: getStylelintPos(rects[i], bottoms[i], code, fix.range),
|
|
826
|
+
newText: fix.text,
|
|
827
|
+
title: `Fix: ${rule}`,
|
|
828
|
+
fix: true,
|
|
825
829
|
},
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
: {},
|
|
833
|
-
};
|
|
834
|
-
});
|
|
830
|
+
],
|
|
831
|
+
}
|
|
832
|
+
: {},
|
|
833
|
+
};
|
|
834
|
+
});
|
|
835
|
+
}
|
|
835
836
|
})() :
|
|
836
837
|
[], jsonDiagnostics = document_1.jsonLSP ?
|
|
837
838
|
await Promise.all(root.querySelectorAll(jsonSelector).map(async ({ name, lastChild, selfClosing }) => {
|
|
@@ -1032,7 +1033,7 @@ class LanguageService {
|
|
|
1032
1033
|
else if (type === 'link-target' && (parentNode.is('link')
|
|
1033
1034
|
|| parentNode.is('redirect-target')
|
|
1034
1035
|
|| parentNode.is('category'))) {
|
|
1035
|
-
if (
|
|
1036
|
+
if (/^(?:\.\.)?\//u.test(target)) {
|
|
1036
1037
|
return false;
|
|
1037
1038
|
}
|
|
1038
1039
|
target = parentNode.link.getUrl(articlePath);
|
|
@@ -1095,7 +1096,8 @@ class LanguageService {
|
|
|
1095
1096
|
* @param position position / 位置
|
|
1096
1097
|
*/
|
|
1097
1098
|
async provideReferences(text, position) {
|
|
1098
|
-
const root = await this.#queue(text), { offsetNode, offset } = caretPositionFromWord(root, this.#text, position), element = offsetNode.type === 'text' ? offsetNode.parentNode : offsetNode, node = offset === 0
|
|
1099
|
+
const root = await this.#queue(text), { offsetNode, offset } = caretPositionFromWord(root, this.#text, position), element = offsetNode.type === 'text' ? offsetNode.parentNode : offsetNode, node = offset === 0
|
|
1100
|
+
&& (element.is('ext-attr-dirty') || element.is('html-attr-dirty'))
|
|
1099
1101
|
? element.parentNode.parentNode
|
|
1100
1102
|
: element, { type } = node, refName = getRefName(node), refGroup = getRefGroup(node);
|
|
1101
1103
|
if (!refName && !refGroup && !referenceTypes.has(type)) {
|
package/dist/lib/text.js
CHANGED
|
@@ -52,12 +52,12 @@ const constants_1 = require("../util/constants");
|
|
|
52
52
|
const readOnly_1 = require("../mixin/readOnly");
|
|
53
53
|
const cached_1 = require("../mixin/cached");
|
|
54
54
|
/* NOT FOR BROWSER END */
|
|
55
|
-
const sp = /* #__PURE__ */ (() => String.raw `[${string_1.zs}\t]*`)(), anySp = /* #__PURE__ */ (() => String.raw `[^\S\n]*`)(), source = /* #__PURE__ */ (() => String.raw `<${anySp}(?:/${anySp})?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*?\])|((?:^|\])[^[]*?)\]
|
|
55
|
+
const sp = /* #__PURE__ */ (() => String.raw `[${string_1.zs}\t]*`)(), anySp = /* #__PURE__ */ (() => String.raw `[^\S\n]*`)(), source = /* #__PURE__ */ (() => String.raw `<${anySp}(?:/${anySp})?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*?\])|((?:^|\])[^[]*?)\]+`)();
|
|
56
56
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
57
|
-
|
|
58
|
-
const errorSyntax = /* #__PURE__ */ (() => new RegExp(String.raw `${source}|https?[:/]
|
|
57
|
+
/https?[:/]\/+|(?:rfc|pmid)(?=[-::]?\s*\d)|isbn(?=[-::]?\s*(?:\d(?:\s*|-)){6})/giu;
|
|
58
|
+
const errorSyntax = /* #__PURE__ */ (() => new RegExp(String.raw `${source}|https?[:/]/+|(?:rfc|pmid)(?=[-::]?${sp}\d)|isbn(?=[-::]?${sp}(?:\d(?:${sp}|-)){6})`, 'giu'))();
|
|
59
59
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
60
|
-
|
|
60
|
+
/<[^\S\n]*(?:\/[^\S\n]*)?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*?\])|((?:^|\])[^[]*?)\]+|https?[:/]\/+/giu;
|
|
61
61
|
const errorSyntaxUrl = /* #__PURE__ */ new RegExp(source, 'giu'), noLinkTypes = new Set(['attr-value', 'ext-link-text', 'link-text']), regexes = {
|
|
62
62
|
'[': /[[\]]/u,
|
|
63
63
|
'{': /[{}]/u,
|
|
@@ -201,7 +201,7 @@ let AstText = (() => {
|
|
|
201
201
|
if (!parentNode) {
|
|
202
202
|
throw new Error('An isolated text node cannot be linted!');
|
|
203
203
|
}
|
|
204
|
-
const { type,
|
|
204
|
+
const { type, parentNode: grandparent } = parentNode;
|
|
205
205
|
if (type === 'attr-value') {
|
|
206
206
|
const { name: grandName, tag } = grandparent;
|
|
207
207
|
if (tag === 'ref' && (grandName === 'name' || grandName === 'follow')
|
|
@@ -210,13 +210,7 @@ let AstText = (() => {
|
|
|
210
210
|
return [];
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
|
-
errorRegex ??= type
|
|
214
|
-
|| type === 'ext-link-url'
|
|
215
|
-
|| type === 'ext-link-text'
|
|
216
|
-
|| type === 'image-parameter' && name === 'link'
|
|
217
|
-
|| type === 'attr-value'
|
|
218
|
-
? errorSyntaxUrl
|
|
219
|
-
: errorSyntax;
|
|
213
|
+
errorRegex ??= parentNode.isPlain() && !noLinkTypes.has(type) ? errorSyntax : errorSyntaxUrl;
|
|
220
214
|
if (data.search(errorRegex) === -1) {
|
|
221
215
|
return [];
|
|
222
216
|
}
|
|
@@ -248,8 +242,7 @@ let AstText = (() => {
|
|
|
248
242
|
if (char === '<' && !tags.has(tag.toLowerCase())
|
|
249
243
|
|| lbrack && type === 'ext-link-text' && (/&(?:rbrack|#93|#x5[Dd];);/u.test(data.slice(index + 1))
|
|
250
244
|
|| nextSibling?.is('ext') && nextName === 'nowiki'
|
|
251
|
-
&& nextSibling.innerText?.includes(']'))
|
|
252
|
-
|| magicLink && (!parentNode.isPlain() || noLinkTypes.has(type))) {
|
|
245
|
+
&& nextSibling.innerText?.includes(']'))) {
|
|
253
246
|
continue;
|
|
254
247
|
}
|
|
255
248
|
else if (rbrack && (index || length > 1)) {
|
|
@@ -73,7 +73,7 @@ const parseCommentAndExt = (wikitext, config, accum, includeOnly) => {
|
|
|
73
73
|
wikitext = wikitext.replace(/<nowiki>[\s\S]*?<\/nowiki>/giu, m => {
|
|
74
74
|
stack.push(m);
|
|
75
75
|
return `\0${stack.length - 1}\x7F`;
|
|
76
|
-
}).replace(/<translate( nowrap)?>([\s\S]
|
|
76
|
+
}).replace(/<translate( nowrap)?>([\s\S]*?)<\/translate>/gu, (_, p1, p2) => {
|
|
77
77
|
const l = accum.length;
|
|
78
78
|
// @ts-expect-error abstract class
|
|
79
79
|
new translate_1.TranslateToken(p1, p2 && (0, string_1.restore)(p2, stack), newConfig, accum);
|
package/dist/src/atom.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Token } from './index';
|
|
2
2
|
import type { Config } from '../base';
|
|
3
|
-
declare const atomTypes: readonly ["arg-name", "attr-key", "attr-value", "ext-attr-dirty", "html-attr-dirty", "table-attr-dirty", "converter-flag", "converter-rule-variant", "
|
|
3
|
+
declare const atomTypes: readonly ["arg-name", "attr-key", "attr-value", "ext-attr-dirty", "html-attr-dirty", "table-attr-dirty", "converter-flag", "converter-rule-variant", "invoke-function", "invoke-module", "template-name", "link-target"];
|
|
4
4
|
declare type AtomTypes = typeof atomTypes[number];
|
|
5
5
|
/**
|
|
6
6
|
* plain Token that will not be parsed further
|
package/dist/src/atom.js
CHANGED
package/dist/src/attribute.js
CHANGED
|
@@ -360,8 +360,10 @@ let AttributeToken = (() => {
|
|
|
360
360
|
}
|
|
361
361
|
escape() {
|
|
362
362
|
LSP: { // eslint-disable-line no-unused-labels
|
|
363
|
-
this
|
|
364
|
-
|
|
363
|
+
if (this.type !== 'ext-attr') {
|
|
364
|
+
this.#equal = '{{=}}';
|
|
365
|
+
this.lastChild.escape();
|
|
366
|
+
}
|
|
365
367
|
}
|
|
366
368
|
}
|
|
367
369
|
/* PRINT ONLY */
|
package/dist/src/attributes.d.ts
CHANGED
package/dist/src/attributes.js
CHANGED
|
@@ -312,6 +312,13 @@ let AttributesToken = (() => {
|
|
|
312
312
|
return errors;
|
|
313
313
|
}
|
|
314
314
|
}
|
|
315
|
+
escape() {
|
|
316
|
+
LSP: { // eslint-disable-line no-unused-labels
|
|
317
|
+
if (this.type !== 'ext-attrs') {
|
|
318
|
+
super.escape();
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
315
322
|
/* PRINT ONLY */
|
|
316
323
|
/** @private */
|
|
317
324
|
getAttribute(key) {
|
|
@@ -378,7 +385,7 @@ let AttributesToken = (() => {
|
|
|
378
385
|
else {
|
|
379
386
|
token.close();
|
|
380
387
|
}
|
|
381
|
-
if (this.closest('parameter')) {
|
|
388
|
+
if (this.closest('parameter,ext')?.is('parameter')) {
|
|
382
389
|
token.escape();
|
|
383
390
|
}
|
|
384
391
|
super.insertAt(token, i);
|
package/dist/src/converter.js
CHANGED
|
@@ -101,8 +101,7 @@ let ConverterToken = (() => {
|
|
|
101
101
|
const [firstRule] = rules, hasColon = firstRule.includes(':'),
|
|
102
102
|
// @ts-expect-error abstract class
|
|
103
103
|
firstRuleToken = new converterRule_1.ConverterRuleToken(firstRule, hasColon, config, accum);
|
|
104
|
-
if (hasColon
|
|
105
|
-
|| !hasColon && rules.length === 2 && !(0, string_1.removeComment)(rules[1]).trim()) {
|
|
104
|
+
if (hasColon ? firstRuleToken.length === 1 : rules.length === 2 && !(0, string_1.removeComment)(rules[1]).trim()) {
|
|
106
105
|
this.insertAt(
|
|
107
106
|
// @ts-expect-error abstract class
|
|
108
107
|
new converterRule_1.ConverterRuleToken(rules.join(';'), false, config, accum));
|
|
@@ -41,6 +41,7 @@ exports.ConverterFlagsToken = void 0;
|
|
|
41
41
|
const lint_1 = require("../util/lint");
|
|
42
42
|
const rect_1 = require("../lib/rect");
|
|
43
43
|
const gapped_1 = require("../mixin/gapped");
|
|
44
|
+
const noEscape_1 = require("../mixin/noEscape");
|
|
44
45
|
const index_1 = __importDefault(require("../index"));
|
|
45
46
|
const index_2 = require("./index");
|
|
46
47
|
const atom_1 = require("./atom");
|
|
@@ -57,7 +58,7 @@ const definedFlags = new Set(['A', 'T', 'R', 'D', '-', 'H', 'N']);
|
|
|
57
58
|
* @classdesc `{childNodes: AtomToken[]}`
|
|
58
59
|
*/
|
|
59
60
|
let ConverterFlagsToken = (() => {
|
|
60
|
-
let _classDecorators = [(0, gapped_1.gapped)()];
|
|
61
|
+
let _classDecorators = [(0, gapped_1.gapped)(), noEscape_1.noEscape];
|
|
61
62
|
let _classDescriptor;
|
|
62
63
|
let _classExtraInitializers = [];
|
|
63
64
|
let _classThis;
|
|
@@ -7,18 +7,18 @@ import type { ConverterToken, ConverterFlagsToken } from '../internal';
|
|
|
7
7
|
* language conversion rule
|
|
8
8
|
*
|
|
9
9
|
* 转换规则
|
|
10
|
-
* @classdesc `{childNodes: AtomToken
|
|
10
|
+
* @classdesc `{childNodes: [Token?, AtomToken?, Token]}`
|
|
11
11
|
*/
|
|
12
12
|
export declare abstract class ConverterRuleToken extends Token {
|
|
13
|
-
readonly childNodes: readonly [
|
|
14
|
-
abstract get firstChild():
|
|
15
|
-
abstract get lastChild():
|
|
13
|
+
readonly childNodes: readonly [Token] | readonly [AtomToken, Token] | readonly [Token, AtomToken, Token];
|
|
14
|
+
abstract get firstChild(): Token;
|
|
15
|
+
abstract get lastChild(): Token;
|
|
16
16
|
abstract get parentNode(): ConverterToken | undefined;
|
|
17
17
|
abstract get previousSibling(): ConverterFlagsToken | this | undefined;
|
|
18
18
|
abstract get nextSibling(): this | undefined;
|
|
19
|
-
abstract get children(): [
|
|
20
|
-
abstract get firstElementChild():
|
|
21
|
-
abstract get lastElementChild():
|
|
19
|
+
abstract get children(): [Token] | [AtomToken, Token] | [Token, AtomToken, Token];
|
|
20
|
+
abstract get firstElementChild(): Token;
|
|
21
|
+
abstract get lastElementChild(): Token;
|
|
22
22
|
abstract get parentElement(): ConverterToken | undefined;
|
|
23
23
|
abstract get previousElementSibling(): ConverterFlagsToken | this | undefined;
|
|
24
24
|
abstract get nextElementSibling(): this | undefined;
|
|
@@ -44,7 +44,7 @@ export declare abstract class ConverterRuleToken extends Token {
|
|
|
44
44
|
* @override
|
|
45
45
|
* @param i position of the child node / 移除位置
|
|
46
46
|
*/
|
|
47
|
-
removeAt(i: number):
|
|
47
|
+
removeAt(i: number): Token;
|
|
48
48
|
insertAt(): never;
|
|
49
49
|
/**
|
|
50
50
|
* Prevent language conversion
|