wikiparser-node 1.41.0 → 1.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -18
- package/bundle/bundle-es8.min.js +27 -27
- package/bundle/bundle-lsp.min.js +28 -28
- package/bundle/bundle.min.js +19 -19
- package/dist/addon/attribute.js +5 -7
- package/dist/addon/link.js +3 -2
- package/dist/addon/transclude.js +17 -29
- package/dist/bin/config.js +1 -1
- package/dist/extensions/typings.d.ts +1 -1
- package/dist/index.js +1 -2
- package/dist/lib/document.js +5 -5
- package/dist/lib/element.d.ts +3 -8
- package/dist/lib/element.js +2 -26
- package/dist/lib/lsp.d.ts +2 -0
- package/dist/lib/lsp.js +8 -20
- package/dist/lib/node.d.ts +2 -0
- package/dist/lib/node.js +0 -7
- package/dist/lib/range.d.ts +0 -7
- package/dist/lib/range.js +5 -14
- package/dist/lib/ranges.js +2 -2
- package/dist/lib/text.js +3 -5
- package/dist/map.d.ts +66 -0
- package/dist/map.js +2 -0
- package/dist/mixin/attributesParent.d.ts +4 -3
- package/dist/mixin/elementLike.d.ts +13 -0
- package/dist/mixin/elementLike.js +66 -53
- package/dist/parser/selector.js +3 -3
- package/dist/render/expand.js +4 -2
- package/dist/render/extension.js +139 -8
- package/dist/render/html.js +72 -3
- package/dist/render/magicWords.js +24 -131
- package/dist/src/arg.js +1 -2
- package/dist/src/atom.js +1 -1
- package/dist/src/attribute.d.ts +2 -2
- package/dist/src/attribute.js +17 -13
- package/dist/src/attributes.d.ts +3 -3
- package/dist/src/attributes.js +30 -14
- package/dist/src/converterRule.js +3 -5
- package/dist/src/extLink.js +5 -4
- package/dist/src/heading.js +12 -5
- package/dist/src/imageParameter.js +1 -2
- package/dist/src/index.js +4 -5
- package/dist/src/link/base.js +3 -5
- package/dist/src/link/file.js +7 -8
- package/dist/src/link/galleryImage.js +1 -3
- package/dist/src/magicLink.js +7 -7
- package/dist/src/multiLine/gallery.js +2 -3
- package/dist/src/nowiki/doubleUnderscore.d.ts +1 -0
- package/dist/src/nowiki/doubleUnderscore.js +4 -1
- package/dist/src/nowiki/quote.js +1 -3
- package/dist/src/onlyinclude.js +1 -2
- package/dist/src/parameter.js +6 -4
- package/dist/src/table/index.js +1 -2
- package/dist/src/table/td.d.ts +2 -2
- package/dist/src/table/td.js +5 -7
- package/dist/src/tag/html.js +29 -12
- package/dist/src/tagPair/ext.js +4 -1
- package/dist/src/tagPair/translate.d.ts +1 -1
- package/dist/src/tagPair/translate.js +1 -1
- package/dist/src/transclude.js +4 -2
- package/dist/util/debug.js +5 -7
- package/dist/util/html.js +3 -11
- package/extensions/dist/base.js +1 -1
- package/package.json +57 -21
package/dist/addon/transclude.js
CHANGED
|
@@ -18,9 +18,7 @@ const atom_1 = require("../src/atom");
|
|
|
18
18
|
*/
|
|
19
19
|
const format = (token) => {
|
|
20
20
|
const { lastChild, type } = token, isParameter = lastChild.is('parameter');
|
|
21
|
-
if (!(type === 'template'
|
|
22
|
-
? isParameter && lastChild.anon
|
|
23
|
-
: lastChild.is('magic-word-name'))
|
|
21
|
+
if (!(type === 'template' ? isParameter && lastChild.anon : lastChild.is('magic-word-name'))
|
|
24
22
|
&& !lastChild.toString().endsWith('\n')) {
|
|
25
23
|
(isParameter ? lastChild.lastChild : lastChild).insertAt('\n');
|
|
26
24
|
}
|
|
@@ -28,10 +26,10 @@ const format = (token) => {
|
|
|
28
26
|
transclude_1.TranscludeToken.prototype.newAnonArg =
|
|
29
27
|
/** @implements */
|
|
30
28
|
function (val, newline) {
|
|
31
|
-
const
|
|
29
|
+
const token = debug_1.Shadow.run(
|
|
32
30
|
// @ts-expect-error abstract class
|
|
33
31
|
() => new parameter_1.ParameterToken(undefined, undefined, this.getAttribute('config')));
|
|
34
|
-
token.lastChild.concat(childNodes); // eslint-disable-line unicorn/prefer-spread
|
|
32
|
+
token.lastChild.concat(index_1.default.parseWithRef(val, this).childNodes); // eslint-disable-line unicorn/prefer-spread
|
|
35
33
|
if (newline) {
|
|
36
34
|
format(this);
|
|
37
35
|
}
|
|
@@ -49,11 +47,12 @@ transclude_1.TranscludeToken.prototype.setValue =
|
|
|
49
47
|
arg.setValue(value);
|
|
50
48
|
return;
|
|
51
49
|
}
|
|
52
|
-
const
|
|
50
|
+
const token = debug_1.Shadow.run(
|
|
53
51
|
// @ts-expect-error abstract class
|
|
54
52
|
() => new parameter_1.ParameterToken(undefined, undefined, this.getAttribute('config')));
|
|
55
|
-
token.firstChild.safeAppend(
|
|
56
|
-
|
|
53
|
+
token.firstChild.safeAppend(index_1.default.parseWithRef(key, this).childNodes);
|
|
54
|
+
// eslint-disable-next-line unicorn/prefer-spread
|
|
55
|
+
token.lastChild.concat(index_1.default.parseWithRef(value, this).childNodes);
|
|
57
56
|
if (newline) {
|
|
58
57
|
format(this);
|
|
59
58
|
}
|
|
@@ -67,41 +66,30 @@ transclude_1.TranscludeToken.prototype.replaceTemplate =
|
|
|
67
66
|
if (type === 'magic-word') {
|
|
68
67
|
throw new Error('TranscludeToken.replaceTemplate method is only for templates!');
|
|
69
68
|
}
|
|
70
|
-
|
|
71
|
-
firstChild.safeReplaceChildren(childNodes);
|
|
69
|
+
firstChild.safeReplaceChildren(index_1.default.parseWithRef(title, this, 2).childNodes);
|
|
72
70
|
};
|
|
73
71
|
transclude_1.TranscludeToken.prototype.replaceModule =
|
|
74
72
|
/** @implements */
|
|
75
73
|
function (title) {
|
|
76
|
-
const { type, name,
|
|
74
|
+
const { type, name, childNodes: [, mod] } = this;
|
|
77
75
|
/* c8 ignore next 3 */
|
|
78
76
|
if (type !== 'magic-word' || name !== 'invoke') {
|
|
79
77
|
throw new Error('TranscludeToken.replaceModule method is only for modules!');
|
|
80
78
|
}
|
|
81
|
-
|
|
82
|
-
index_2.Token.prototype.insertAt.call(this, debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'invoke-module', this.getAttribute('config'), [], { 'Stage-1': ':', '!ExtToken': '' })));
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
const { childNodes } = index_1.default.parseWithRef(title, this, 2);
|
|
86
|
-
mod.safeReplaceChildren(childNodes);
|
|
79
|
+
mod.safeReplaceChildren(index_1.default.parseWithRef(title, this, 2).childNodes);
|
|
87
80
|
};
|
|
88
81
|
transclude_1.TranscludeToken.prototype.replaceFunction =
|
|
89
82
|
/** @implements */
|
|
90
83
|
function (func) {
|
|
91
|
-
const { type, name, length
|
|
84
|
+
const { type, name, length } = this;
|
|
92
85
|
/* c8 ignore next 6 */
|
|
93
86
|
if (type !== 'magic-word' || name !== 'invoke') {
|
|
94
87
|
throw new Error('TranscludeToken.replaceModule method is only for modules!');
|
|
95
88
|
}
|
|
96
|
-
if (length
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
if (length === 2) {
|
|
100
|
-
index_2.Token.prototype.insertAt.call(this, debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'invoke-function', this.getAttribute('config'), [], { 'Stage-1': ':', '!ExtToken': '' })));
|
|
101
|
-
return;
|
|
89
|
+
else if (length === 2) {
|
|
90
|
+
index_2.Token.prototype.insertAt.call(this, debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'invoke-function', this.getAttribute('config'), [], { 'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '' })));
|
|
102
91
|
}
|
|
103
|
-
|
|
104
|
-
fun.safeReplaceChildren(childNodes);
|
|
92
|
+
this.childNodes[2].safeReplaceChildren(index_1.default.parseWithRef(func, this, 2).childNodes);
|
|
105
93
|
};
|
|
106
94
|
transclude_1.TranscludeToken.prototype.fixDuplication =
|
|
107
95
|
/** @implements */
|
|
@@ -170,11 +158,11 @@ transclude_1.TranscludeToken.prototype.fixDuplication =
|
|
|
170
158
|
}
|
|
171
159
|
}
|
|
172
160
|
if (remaining > 1) {
|
|
173
|
-
index_1.default.error(`${this.type === 'template'
|
|
161
|
+
index_1.default.error(`${JSON.stringify(this.type === 'template'
|
|
174
162
|
? this.name
|
|
175
|
-
: this.normalizeTitle(`Module:${this.childNodes[1].text()}`, 828, { temporary: true, page: '' }).title} still has ${remaining} duplicated ${key} parameters:\n${[...this.getArgs(key)].map(arg => {
|
|
163
|
+
: this.normalizeTitle(`Module:${this.childNodes[1].text()}`, 828, { temporary: true, page: '' }).title)} still has ${remaining} duplicated ${JSON.stringify(key)} parameters:\n${[...this.getArgs(key)].map(arg => {
|
|
176
164
|
const { top, left } = arg.getBoundingClientRect();
|
|
177
|
-
return `Line ${
|
|
165
|
+
return `Line ${top} Column ${left}`;
|
|
178
166
|
}).join('\n')}`);
|
|
179
167
|
duplicatedKeys.push(key);
|
|
180
168
|
}
|
package/dist/bin/config.js
CHANGED
|
@@ -40,7 +40,7 @@ const filterGadget = (id) => {
|
|
|
40
40
|
const n = Number(id);
|
|
41
41
|
return n < 2300 || n > 2303; // Gadget, Gadget talk, Gadget definition, Gadget definition talk
|
|
42
42
|
};
|
|
43
|
-
const pkg = "wikiparser-node", version = "1.
|
|
43
|
+
const pkg = "wikiparser-node", version = "1.43.0";
|
|
44
44
|
/**
|
|
45
45
|
* Get the parser configuration for a Wikimedia Foundation project.
|
|
46
46
|
* @param site site nickname
|
|
@@ -78,7 +78,7 @@ declare global {
|
|
|
78
78
|
dones: Set<string>,
|
|
79
79
|
key: string,
|
|
80
80
|
) => void;
|
|
81
|
-
type HideOptGroup = (optgroup
|
|
81
|
+
type HideOptGroup = (optgroup?: HTMLOptGroupElement) => void;
|
|
82
82
|
type AddOption = (
|
|
83
83
|
optgroup: HTMLOptGroupElement | undefined,
|
|
84
84
|
select: HTMLSelectElement,
|
package/dist/index.js
CHANGED
|
@@ -378,8 +378,7 @@ const Parser = {
|
|
|
378
378
|
[name] = entry;
|
|
379
379
|
}
|
|
380
380
|
const { firstChild, length } = debug_1.Shadow.internal(() => this.parse(`{{${name}:${args.join('|')}}}`, false, 2), this);
|
|
381
|
-
result = length === 1 && firstChild.is('magic-word')
|
|
382
|
-
&& constants_1.functionHooks.get(lcName)(firstChild);
|
|
381
|
+
result = length === 1 && firstChild.is('magic-word') && constants_1.functionHooks.get(lcName)(firstChild);
|
|
383
382
|
}
|
|
384
383
|
else {
|
|
385
384
|
const { expandMagicWord } = require('./render/magicWords');
|
package/dist/lib/document.js
CHANGED
|
@@ -9,19 +9,19 @@ const common_1 = require("@bhsd/common");
|
|
|
9
9
|
const constants_1 = require("../util/constants");
|
|
10
10
|
/* NOT FOR BROWSER */
|
|
11
11
|
const constants_2 = require("../util/constants");
|
|
12
|
-
let
|
|
12
|
+
let texvcjs;
|
|
13
13
|
const loadTexvcjs = () => {
|
|
14
14
|
NPM: {
|
|
15
|
-
if (
|
|
15
|
+
if (texvcjs === undefined) {
|
|
16
16
|
try {
|
|
17
|
-
|
|
17
|
+
texvcjs = require('mathoid-texvcjs');
|
|
18
18
|
}
|
|
19
19
|
catch /* c8 ignore start */ {
|
|
20
|
-
|
|
20
|
+
texvcjs = null;
|
|
21
21
|
}
|
|
22
22
|
/* c8 ignore stop */
|
|
23
23
|
}
|
|
24
|
-
return
|
|
24
|
+
return texvcjs;
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
exports.loadTexvcjs = loadTexvcjs;
|
package/dist/lib/element.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { AstNode } from './node';
|
|
|
2
2
|
import type { TokenTypes, LintError, AST } from '../base';
|
|
3
3
|
import type { ElementLike } from '../mixin/elementLike';
|
|
4
4
|
import type { AstNodes, AstText, Token, FileToken, LinkToken, RedirectTargetToken, ExtLinkToken, MagicLinkToken, ImageParameterToken, TranscludeToken } from '../internal';
|
|
5
|
+
import type { TokenTypeMap, SelectedTokenTypes } from '../map';
|
|
5
6
|
declare type LinkTokens = LinkToken | RedirectTargetToken | ExtLinkToken | MagicLinkToken | ImageParameterToken;
|
|
6
7
|
export interface CaretPosition {
|
|
7
8
|
readonly offsetNode: AstNodes;
|
|
@@ -54,13 +55,6 @@ export declare abstract class AstElement extends AstNode {
|
|
|
54
55
|
* @throws `RangeError` 不能插入祖先或子节点
|
|
55
56
|
*/
|
|
56
57
|
insertAt<T extends AstNodes>(node: T, i?: number): T;
|
|
57
|
-
/**
|
|
58
|
-
* Get the closest ancestor node that matches the selector
|
|
59
|
-
*
|
|
60
|
-
* 最近的符合选择器的祖先节点
|
|
61
|
-
* @param selector selector / 选择器
|
|
62
|
-
*/
|
|
63
|
-
closest<T = Token>(selector: string): T | undefined;
|
|
64
58
|
/**
|
|
65
59
|
* Insert a batch of child nodes at the end
|
|
66
60
|
*
|
|
@@ -120,7 +114,8 @@ export declare abstract class AstElement extends AstNode {
|
|
|
120
114
|
* 检查是否符合选择器
|
|
121
115
|
* @param selector selector / 选择器
|
|
122
116
|
*/
|
|
123
|
-
matches<
|
|
117
|
+
matches<K extends SelectedTokenTypes>(selector: K): this is TokenTypeMap[K];
|
|
118
|
+
matches<T extends Token>(selector: string): this is T;
|
|
124
119
|
/**
|
|
125
120
|
* Insert a batch of child nodes at the start
|
|
126
121
|
*
|
package/dist/lib/element.js
CHANGED
|
@@ -40,13 +40,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
40
40
|
exports.AstElement = void 0;
|
|
41
41
|
const string_1 = require("../util/string");
|
|
42
42
|
const debug_1 = require("../util/debug");
|
|
43
|
-
const selector_1 = require("../util/selector");
|
|
44
43
|
const node_1 = require("./node");
|
|
45
44
|
const elementLike_1 = require("../mixin/elementLike");
|
|
46
45
|
/* NOT FOR BROWSER */
|
|
47
46
|
const fs_1 = __importDefault(require("fs"));
|
|
48
47
|
const path_1 = __importDefault(require("path"));
|
|
49
48
|
const constants_1 = require("../util/constants");
|
|
49
|
+
const selector_1 = require("../util/selector");
|
|
50
50
|
const readOnly_1 = require("../mixin/readOnly");
|
|
51
51
|
/**
|
|
52
52
|
* HTMLElement-like
|
|
@@ -113,8 +113,7 @@ let AstElement = (() => {
|
|
|
113
113
|
}
|
|
114
114
|
/** all internal, external and free external links / 所有内链、外链和自由外链 */
|
|
115
115
|
get links() {
|
|
116
|
-
return this.querySelectorAll('link,redirect-target,ext-link,free-ext-link,magic-link,image-parameter#link').filter(({ parentNode }) => !parentNode?.is('image-parameter')
|
|
117
|
-
|| parentNode.name !== 'link');
|
|
116
|
+
return this.querySelectorAll('link,redirect-target,ext-link,free-ext-link,magic-link,image-parameter#link').filter(({ parentNode }) => !parentNode?.is('image-parameter') || parentNode.name !== 'link');
|
|
118
117
|
}
|
|
119
118
|
/** all templates and modules / 所有模板和模块 */
|
|
120
119
|
get embeds() {
|
|
@@ -165,23 +164,6 @@ let AstElement = (() => {
|
|
|
165
164
|
(0, debug_1.setChildNodes)(this, i, 0, [node]);
|
|
166
165
|
return node;
|
|
167
166
|
}
|
|
168
|
-
/**
|
|
169
|
-
* Get the closest ancestor node that matches the selector
|
|
170
|
-
*
|
|
171
|
-
* 最近的符合选择器的祖先节点
|
|
172
|
-
* @param selector selector / 选择器
|
|
173
|
-
*/
|
|
174
|
-
closest(selector) {
|
|
175
|
-
const condition = (0, selector_1.getCondition)(selector, this);
|
|
176
|
-
let { parentNode } = this;
|
|
177
|
-
while (parentNode) {
|
|
178
|
-
if (condition(parentNode)) {
|
|
179
|
-
return parentNode;
|
|
180
|
-
}
|
|
181
|
-
({ parentNode } = parentNode);
|
|
182
|
-
}
|
|
183
|
-
return undefined;
|
|
184
|
-
}
|
|
185
167
|
/** @private */
|
|
186
168
|
isInside(type) {
|
|
187
169
|
return this.closest(`${type},ext`)?.type === type;
|
|
@@ -404,12 +386,6 @@ let AstElement = (() => {
|
|
|
404
386
|
}
|
|
405
387
|
this.setAttribute('childNodes', childNodes);
|
|
406
388
|
}
|
|
407
|
-
/**
|
|
408
|
-
* Check if the current element matches the selector
|
|
409
|
-
*
|
|
410
|
-
* 检查是否符合选择器
|
|
411
|
-
* @param selector selector / 选择器
|
|
412
|
-
*/
|
|
413
389
|
matches(selector) {
|
|
414
390
|
return (0, selector_1.getCondition)(selector, this)(this);
|
|
415
391
|
}
|
package/dist/lib/lsp.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Token } from '../src/index';
|
|
|
3
3
|
import type { Range, Position, ColorInformation, ColorPresentation, FoldingRange, DocumentLink, Location, WorkspaceEdit, Diagnostic as DiagnosticBase, TextEdit, Hover, SignatureHelp, InlayHint, CodeAction, DocumentSymbol } from 'vscode-languageserver-types';
|
|
4
4
|
import type { Config, LanguageService as LanguageServiceBase, CompletionItem, SignatureData } from '../base';
|
|
5
5
|
import type { AttributeToken } from '../internal';
|
|
6
|
+
import type { TokenTypeMap, SelectedTokenTypes } from '../map';
|
|
6
7
|
export interface QuickFixData extends TextEdit {
|
|
7
8
|
title: string;
|
|
8
9
|
fix: boolean;
|
|
@@ -128,6 +129,7 @@ export declare class LanguageService implements LanguageServiceBase {
|
|
|
128
129
|
* @since v1.16.3
|
|
129
130
|
*/
|
|
130
131
|
provideInlayHints(text: string): Promise<InlayHint[]>;
|
|
132
|
+
querySelectorAll<T = Token>(selector: string): T[];
|
|
131
133
|
/**
|
|
132
134
|
* Provide refactoring actions
|
|
133
135
|
*
|
package/dist/lib/lsp.js
CHANGED
|
@@ -158,15 +158,6 @@ const getRefName = (token) => getRefAttr(token, refTags, nameAttrs);
|
|
|
158
158
|
* @param token `group` attribute token
|
|
159
159
|
*/
|
|
160
160
|
const getRefGroup = (token) => getRefAttr(token, referencesTags, groupAttrs);
|
|
161
|
-
/**
|
|
162
|
-
* Get the attribute of a `<ref>` tag.
|
|
163
|
-
* @param token extension token
|
|
164
|
-
* @param target attribute name
|
|
165
|
-
*/
|
|
166
|
-
const getRefTagAttr = (token, target) => {
|
|
167
|
-
const attr = token?.getAttr(target);
|
|
168
|
-
return attr !== true && attr || false;
|
|
169
|
-
};
|
|
170
161
|
/**
|
|
171
162
|
* Get the effective name of a token.
|
|
172
163
|
* @param token
|
|
@@ -682,8 +673,7 @@ class LanguageService {
|
|
|
682
673
|
}),
|
|
683
674
|
...match.startsWith('#')
|
|
684
675
|
? []
|
|
685
|
-
: getCompletion(root.querySelectorAll('template').filter(token => token !== cur)
|
|
686
|
-
.map(token => {
|
|
676
|
+
: getCompletion(root.querySelectorAll('template').filter(token => token !== cur).map(token => {
|
|
687
677
|
const { name } = token;
|
|
688
678
|
if (colon) {
|
|
689
679
|
return name;
|
|
@@ -1173,8 +1163,7 @@ class LanguageService {
|
|
|
1173
1163
|
* @param position position / 位置
|
|
1174
1164
|
*/
|
|
1175
1165
|
async provideReferences(text, position) {
|
|
1176
|
-
const root = await this.#queue(text), { offsetNode, offset } = caretPositionFromWord(root, this.#text, position), element = offsetNode.type === 'text' ? offsetNode.parentNode : offsetNode, node = offset === 0
|
|
1177
|
-
&& (element.is('ext-attr-dirty') || element.is('html-attr-dirty'))
|
|
1166
|
+
const root = await this.#queue(text), { offsetNode, offset } = caretPositionFromWord(root, this.#text, position), element = offsetNode.type === 'text' ? offsetNode.parentNode : offsetNode, node = offset === 0 && (element.is('ext-attr-dirty') || element.is('html-attr-dirty'))
|
|
1178
1167
|
? element.parentNode.parentNode
|
|
1179
1168
|
: element, { type } = node, refName = getRefName(node), refGroup = getRefGroup(node);
|
|
1180
1169
|
if (!refName && !refGroup && !referenceTypes.has(type)) {
|
|
@@ -1201,13 +1190,13 @@ class LanguageService {
|
|
|
1201
1190
|
}
|
|
1202
1191
|
const ext = node.is('ext') && node.name === 'ref'
|
|
1203
1192
|
? node
|
|
1204
|
-
: node.closest('ext#ref'), refName =
|
|
1193
|
+
: node.closest('ext#ref'), refName = ext?.getAttr('name');
|
|
1205
1194
|
if (!refName) {
|
|
1206
1195
|
return undefined;
|
|
1207
1196
|
}
|
|
1208
|
-
const refGroup =
|
|
1209
|
-
&&
|
|
1210
|
-
&&
|
|
1197
|
+
const refGroup = ext.getAttr('group'), refs = root.querySelectorAll('ext#ref').filter(token => token.innerText
|
|
1198
|
+
&& token.getAttr('name') === refName
|
|
1199
|
+
&& token.getAttr('group') === refGroup).reverse().map(({ lastChild }) => ({
|
|
1211
1200
|
range: createNodeRange(lastChild),
|
|
1212
1201
|
}));
|
|
1213
1202
|
return refs.length === 0 ? undefined : refs;
|
|
@@ -1244,7 +1233,7 @@ class LanguageService {
|
|
|
1244
1233
|
if (!node) {
|
|
1245
1234
|
return undefined;
|
|
1246
1235
|
}
|
|
1247
|
-
const { type } = node, refName = getRefName(node), refNameGroup = refName &&
|
|
1236
|
+
const { type } = node, refName = getRefName(node), refNameGroup = refName && node.parentNode.parentNode.getAttr('group'), refGroup = getRefGroup(node), name = getName(node), refs = root.querySelectorAll(type).filter(token => {
|
|
1248
1237
|
const { type: t } = token.parentNode;
|
|
1249
1238
|
if (type === 'link-target' && t !== 'link' && t !== 'redirect-target') {
|
|
1250
1239
|
return false;
|
|
@@ -1252,7 +1241,7 @@ class LanguageService {
|
|
|
1252
1241
|
return type === 'attr-value'
|
|
1253
1242
|
? getRefGroup(token) === refGroup
|
|
1254
1243
|
|| getRefName(token) === refName
|
|
1255
|
-
&&
|
|
1244
|
+
&& token.parentNode.parentNode.getAttr('group') === refNameGroup
|
|
1256
1245
|
: getName(token) === name;
|
|
1257
1246
|
});
|
|
1258
1247
|
return refs.length === 0
|
|
@@ -1452,7 +1441,6 @@ class LanguageService {
|
|
|
1452
1441
|
}
|
|
1453
1442
|
return hints;
|
|
1454
1443
|
}
|
|
1455
|
-
/** @private */
|
|
1456
1444
|
querySelectorAll(selector) {
|
|
1457
1445
|
return this.#done.querySelectorAll(selector);
|
|
1458
1446
|
}
|
package/dist/lib/node.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AstNode as AstNodeBase, TokenTypes, LintError } from '../base';
|
|
2
2
|
import type { NodeLike } from '../mixin/nodeLike';
|
|
3
3
|
import type { AstText, Token } from '../internal';
|
|
4
|
+
import type { TokenTypeMap, SelectedTokenTypes } from '../map';
|
|
4
5
|
export type AstNodes = AstText | Token;
|
|
5
6
|
export interface Dimension {
|
|
6
7
|
readonly height: number;
|
|
@@ -136,6 +137,7 @@ export declare abstract class AstNode implements AstNodeBase {
|
|
|
136
137
|
* @param type token type / 节点类型
|
|
137
138
|
* @since v1.10.0
|
|
138
139
|
*/
|
|
140
|
+
is<K extends SelectedTokenTypes>(type: K): this is TokenTypeMap[K];
|
|
139
141
|
is<T extends Token>(type: TokenTypes): this is T;
|
|
140
142
|
/**
|
|
141
143
|
* Get the text and the start/end positions of all lines
|
package/dist/lib/node.js
CHANGED
|
@@ -371,13 +371,6 @@ let AstNode = (() => {
|
|
|
371
371
|
...this.getRootNode().posFromIndex(this.getAbsoluteIndex()),
|
|
372
372
|
};
|
|
373
373
|
}
|
|
374
|
-
/**
|
|
375
|
-
* Whether to be of a certain type
|
|
376
|
-
*
|
|
377
|
-
* 是否是某种类型的节点
|
|
378
|
-
* @param type token type / 节点类型
|
|
379
|
-
* @since v1.10.0
|
|
380
|
-
*/
|
|
381
374
|
is(type) {
|
|
382
375
|
return this.type === type;
|
|
383
376
|
}
|
package/dist/lib/range.d.ts
CHANGED
|
@@ -211,13 +211,6 @@ export declare class AstRange {
|
|
|
211
211
|
* @since v1.23.0
|
|
212
212
|
*/
|
|
213
213
|
getRootNode(): AstNodes;
|
|
214
|
-
/**
|
|
215
|
-
* Get the closest ancestor node that matches the selector
|
|
216
|
-
*
|
|
217
|
-
* 最近的符合选择器的祖先节点
|
|
218
|
-
* @param selector selector / 选择器
|
|
219
|
-
*/
|
|
220
|
-
closest<T = Token>(selector: string): T | undefined;
|
|
221
214
|
/**
|
|
222
215
|
* Insert a batch of child nodes at the end
|
|
223
216
|
*
|
package/dist/lib/range.js
CHANGED
|
@@ -146,6 +146,11 @@ let AstRange = (() => {
|
|
|
146
146
|
get childNodes() {
|
|
147
147
|
return this.extractContents();
|
|
148
148
|
}
|
|
149
|
+
/** @private */
|
|
150
|
+
get parentNode() {
|
|
151
|
+
const { commonAncestorContainer } = this;
|
|
152
|
+
return commonAncestorContainer.type === 'text' ? commonAncestorContainer.parentNode : commonAncestorContainer;
|
|
153
|
+
}
|
|
149
154
|
/**
|
|
150
155
|
* 检查起点和终点的设置是否有效
|
|
151
156
|
* @throws `RangeError` 起点和终点不是兄弟节点
|
|
@@ -601,20 +606,6 @@ let AstRange = (() => {
|
|
|
601
606
|
getRootNode() {
|
|
602
607
|
return (this.#endContainer ?? this.startContainer).getRootNode();
|
|
603
608
|
}
|
|
604
|
-
/**
|
|
605
|
-
* Get the closest ancestor node that matches the selector
|
|
606
|
-
*
|
|
607
|
-
* 最近的符合选择器的祖先节点
|
|
608
|
-
* @param selector selector / 选择器
|
|
609
|
-
*/
|
|
610
|
-
closest(selector) {
|
|
611
|
-
const { commonAncestorContainer } = this;
|
|
612
|
-
if (commonAncestorContainer.type === 'text') {
|
|
613
|
-
const { parentNode } = commonAncestorContainer;
|
|
614
|
-
return parentNode?.matches(selector) ? parentNode : parentNode?.closest(selector);
|
|
615
|
-
}
|
|
616
|
-
return commonAncestorContainer.closest(selector);
|
|
617
|
-
}
|
|
618
609
|
/**
|
|
619
610
|
* Insert a batch of child nodes at the end
|
|
620
611
|
*
|
package/dist/lib/ranges.js
CHANGED
|
@@ -47,13 +47,13 @@ class Range {
|
|
|
47
47
|
.exec(str);
|
|
48
48
|
/* c8 ignore next 3 */
|
|
49
49
|
if (!mt) {
|
|
50
|
-
throw new RangeError(`The argument
|
|
50
|
+
throw new RangeError(`The argument ${JSON.stringify(str)} should be either in the form of "an+b" as in CSS selectors or Python slices!`);
|
|
51
51
|
}
|
|
52
52
|
const [, sgnA = '+', a = 1, sgnB = '+'] = mt, b = Number(mt[4] ?? 0);
|
|
53
53
|
this.step = Number(a);
|
|
54
54
|
/* c8 ignore next 3 */
|
|
55
55
|
if (this.step === 0) {
|
|
56
|
-
throw new RangeError(`In the argument
|
|
56
|
+
throw new RangeError(`In the argument ${JSON.stringify(str)}, the coefficient of "n" must not be 0!`);
|
|
57
57
|
}
|
|
58
58
|
else if (sgnA === '+') { // `an+b` or `an-b`
|
|
59
59
|
this.start = sgnB === '+' || b === 0 ? b : this.step - 1 - (b - 1) % this.step;
|
package/dist/lib/text.js
CHANGED
|
@@ -260,8 +260,7 @@ let AstText = (() => {
|
|
|
260
260
|
// Rule & Severity
|
|
261
261
|
let startIndex = start + index, endIndex = startIndex + length, rule, severity, endLine, endCol;
|
|
262
262
|
const nextChar = rootStr[endIndex], previousChar = rootStr[startIndex - 1], leftBracket = lbrace || lbrack, lConverter = error === '{' && previousChar === '-' && variants.length > 0, rConverter = error === '}' && nextChar === '-' && variants.length > 0, brokenExtLink = lbrack && nextType === 'free-ext-link' && !data.slice(index + 1).trim()
|
|
263
|
-
|| rbrack && previousType === 'free-ext-link'
|
|
264
|
-
&& !data.slice(0, index).includes(']');
|
|
263
|
+
|| rbrack && previousType === 'free-ext-link' && index === 0;
|
|
265
264
|
if (magicLink) {
|
|
266
265
|
rule = 'lonely-http';
|
|
267
266
|
error = error.toUpperCase();
|
|
@@ -571,9 +570,8 @@ let AstText = (() => {
|
|
|
571
570
|
if (/\s$/u.test(this.data)) {
|
|
572
571
|
const spaces = [], mt = /\n[^\S\n]*$/u.exec(this.data);
|
|
573
572
|
let { nextSibling } = this, mt2 = null;
|
|
574
|
-
while (nextSibling
|
|
575
|
-
|| nextSibling.is('category')
|
|
576
|
-
|| nextSibling.type === 'text')) {
|
|
573
|
+
while (nextSibling
|
|
574
|
+
&& (nextSibling.is('comment') || nextSibling.is('category') || nextSibling.type === 'text')) {
|
|
577
575
|
if (nextSibling.type === 'text') {
|
|
578
576
|
mt2 = mt && /^[^\S\n]*(?=\n)/u.exec(nextSibling.data);
|
|
579
577
|
if (mt2 || nextSibling.data.trim()) {
|
package/dist/map.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { RedirectToken, RedirectTargetToken, OnlyincludeToken, IncludeToken, CommentToken, ExtToken, AttributesToken, AttributeToken, AtomToken, ArgToken, TranscludeToken, SyntaxToken, ParameterToken, HeadingToken, HtmlToken, TableToken, TrToken, TdToken, DoubleUnderscoreToken, HrToken, LinkToken, CategoryToken, FileToken, ImageParameterToken, QuoteToken, ExtLinkToken, MagicLinkToken, ListToken, DdToken, ConverterToken, ConverterFlagsToken, ConverterRuleToken, TranslateToken, TvarToken, HiddenToken, GalleryImageToken, ParamLineToken, ImagemapLinkToken, ListRangeToken } from './internal';
|
|
2
|
+
export interface TokenTypeMap {
|
|
3
|
+
redirect: RedirectToken;
|
|
4
|
+
'redirect-syntax': SyntaxToken;
|
|
5
|
+
'redirect-target': RedirectTargetToken;
|
|
6
|
+
translate: TranslateToken;
|
|
7
|
+
'translate-attr': SyntaxToken;
|
|
8
|
+
tvar: TvarToken;
|
|
9
|
+
'tvar-name': SyntaxToken;
|
|
10
|
+
onlyinclude: OnlyincludeToken;
|
|
11
|
+
include: IncludeToken;
|
|
12
|
+
comment: CommentToken;
|
|
13
|
+
ext: ExtToken;
|
|
14
|
+
'ext-attrs': AttributesToken;
|
|
15
|
+
'ext-attr-dirty': AtomToken;
|
|
16
|
+
'ext-attr': AttributeToken;
|
|
17
|
+
'attr-key': AtomToken;
|
|
18
|
+
arg: ArgToken;
|
|
19
|
+
'arg-name': AtomToken;
|
|
20
|
+
hidden: HiddenToken;
|
|
21
|
+
'magic-word': TranscludeToken;
|
|
22
|
+
'magic-word-name': SyntaxToken;
|
|
23
|
+
'invoke-function': AtomToken;
|
|
24
|
+
'invoke-module': AtomToken;
|
|
25
|
+
template: TranscludeToken;
|
|
26
|
+
'template-name': AtomToken;
|
|
27
|
+
parameter: ParameterToken;
|
|
28
|
+
heading: HeadingToken;
|
|
29
|
+
'heading-trail': SyntaxToken;
|
|
30
|
+
html: HtmlToken;
|
|
31
|
+
'html-attrs': AttributesToken;
|
|
32
|
+
'html-attr-dirty': AtomToken;
|
|
33
|
+
'html-attr': AttributeToken;
|
|
34
|
+
table: TableToken;
|
|
35
|
+
tr: TrToken;
|
|
36
|
+
td: TdToken;
|
|
37
|
+
'table-syntax': SyntaxToken;
|
|
38
|
+
'table-attrs': AttributesToken;
|
|
39
|
+
'table-attr-dirty': AtomToken;
|
|
40
|
+
'table-attr': AttributeToken;
|
|
41
|
+
hr: HrToken;
|
|
42
|
+
'double-underscore': DoubleUnderscoreToken;
|
|
43
|
+
link: LinkToken;
|
|
44
|
+
'link-target': AtomToken;
|
|
45
|
+
category: CategoryToken;
|
|
46
|
+
file: FileToken;
|
|
47
|
+
'gallery-image': GalleryImageToken;
|
|
48
|
+
'imagemap-image': GalleryImageToken;
|
|
49
|
+
'image-parameter': ImageParameterToken;
|
|
50
|
+
quote: QuoteToken;
|
|
51
|
+
'ext-link': ExtLinkToken;
|
|
52
|
+
'ext-link-url': MagicLinkToken;
|
|
53
|
+
'free-ext-link': MagicLinkToken;
|
|
54
|
+
'magic-link': MagicLinkToken;
|
|
55
|
+
list: ListToken;
|
|
56
|
+
dd: DdToken;
|
|
57
|
+
converter: ConverterToken;
|
|
58
|
+
'converter-flags': ConverterFlagsToken;
|
|
59
|
+
'converter-flag': AtomToken;
|
|
60
|
+
'converter-rule': ConverterRuleToken;
|
|
61
|
+
'converter-rule-variant': AtomToken;
|
|
62
|
+
'param-line': ParamLineToken;
|
|
63
|
+
'imagemap-link': ImagemapLinkToken;
|
|
64
|
+
'list-range': ListRangeToken;
|
|
65
|
+
}
|
|
66
|
+
export type SelectedTokenTypes = keyof TokenTypeMap;
|
package/dist/map.js
ADDED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export interface AttributesParentBase {
|
|
2
2
|
/** all attributes / 全部属性 */
|
|
3
|
-
attributes: Record<string, string
|
|
3
|
+
get attributes(): Record<string, string>;
|
|
4
|
+
set attributes(attrs: Record<string, string | true>);
|
|
4
5
|
/** class attribute in string / 以字符串表示的class属性 */
|
|
5
6
|
className: string;
|
|
6
7
|
/** class attribute in Set / 以Set表示的class属性 */
|
|
@@ -20,7 +21,7 @@ export interface AttributesParentBase {
|
|
|
20
21
|
* 获取指定属性
|
|
21
22
|
* @param key attribute name / 属性键
|
|
22
23
|
*/
|
|
23
|
-
getAttr(key: string): string |
|
|
24
|
+
getAttr(key: string): string | undefined;
|
|
24
25
|
/**
|
|
25
26
|
* Get all attribute names
|
|
26
27
|
*
|
|
@@ -32,7 +33,7 @@ export interface AttributesParentBase {
|
|
|
32
33
|
*
|
|
33
34
|
* 获取全部属性
|
|
34
35
|
*/
|
|
35
|
-
getAttrs(): Record<string, string
|
|
36
|
+
getAttrs(): Record<string, string>;
|
|
36
37
|
/**
|
|
37
38
|
* Set the attribute
|
|
38
39
|
*
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { AstNodes, Token, HtmlToken, ExtToken } from '../internal';
|
|
2
|
+
import type { TokenTypeMap, SelectedTokenTypes } from '../map';
|
|
2
3
|
declare type ElementConstructor = abstract new (...args: any[]) => {
|
|
4
|
+
readonly parentNode: Token | undefined;
|
|
3
5
|
readonly childNodes: readonly AstNodes[];
|
|
4
6
|
detach?: () => void;
|
|
5
7
|
};
|
|
@@ -12,12 +14,21 @@ export interface ElementLike {
|
|
|
12
14
|
readonly lastElementChild: Token | undefined;
|
|
13
15
|
/** number of child elements / 非文本子节点总数 */
|
|
14
16
|
readonly childElementCount: number;
|
|
17
|
+
/**
|
|
18
|
+
* Get the closest ancestor node that matches the selector
|
|
19
|
+
*
|
|
20
|
+
* 最近的符合选择器的祖先节点
|
|
21
|
+
* @param selector selector / 选择器
|
|
22
|
+
*/
|
|
23
|
+
closest<K extends SelectedTokenTypes>(selector: K): TokenTypeMap[K] | undefined;
|
|
24
|
+
closest<T = Token>(selector: string): T | undefined;
|
|
15
25
|
/**
|
|
16
26
|
* Get the first descendant that matches the selector
|
|
17
27
|
*
|
|
18
28
|
* 符合选择器的第一个后代节点
|
|
19
29
|
* @param selector selector / 选择器
|
|
20
30
|
*/
|
|
31
|
+
querySelector<K extends SelectedTokenTypes>(selector: K): TokenTypeMap[K] | undefined;
|
|
21
32
|
querySelector<T = Token>(selector: string): T | undefined;
|
|
22
33
|
/**
|
|
23
34
|
* Get all descendants that match the selector
|
|
@@ -25,6 +36,7 @@ export interface ElementLike {
|
|
|
25
36
|
* 符合选择器的所有后代节点
|
|
26
37
|
* @param selector selector / 选择器
|
|
27
38
|
*/
|
|
39
|
+
querySelectorAll<K extends SelectedTokenTypes>(selector: K): TokenTypeMap[K][];
|
|
28
40
|
querySelectorAll<T = Token>(selector: string): T[];
|
|
29
41
|
/**
|
|
30
42
|
* Escape `=` and `|`
|
|
@@ -39,6 +51,7 @@ export interface ElementLike {
|
|
|
39
51
|
* 类型选择器
|
|
40
52
|
* @param types token types / 节点类型
|
|
41
53
|
*/
|
|
54
|
+
getElementByTypes<K extends SelectedTokenTypes>(types: K): TokenTypeMap[K] | undefined;
|
|
42
55
|
getElementByTypes<T = Token>(types: string): T | undefined;
|
|
43
56
|
/**
|
|
44
57
|
* Get the first descendant with the id
|