wikiparser-node 1.40.0 → 1.42.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 +55 -7
- package/bundle/bundle-es8.min.js +27 -27
- package/bundle/bundle-lsp.min.js +29 -29
- package/bundle/bundle.min.js +19 -19
- package/config/.schema.json +5 -0
- package/config/default.json +1 -1
- package/config/enwiki.json +3 -2
- package/config/jawiki.json +6 -5
- package/config/llwiki.json +2 -1
- package/config/minimum.json +1 -1
- package/config/moegirl.json +2 -1
- package/config/zhwiki.json +3 -2
- package/dist/addon/attribute.js +1 -1
- package/dist/addon/transclude.js +1 -3
- package/dist/base.d.mts +5 -3
- package/dist/base.d.ts +5 -3
- package/dist/bin/config.js +11 -10
- package/dist/index.js +1 -2
- package/dist/lib/element.d.ts +3 -8
- package/dist/lib/element.js +2 -26
- package/dist/lib/lintConfig.js +30 -23
- 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/text.js +4 -6
- 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/extension.js +139 -8
- package/dist/render/html.js +72 -3
- package/dist/render/magicWords.js +6 -3
- package/dist/src/attribute.d.ts +2 -2
- package/dist/src/attribute.js +18 -14
- package/dist/src/attributes.d.ts +3 -3
- package/dist/src/attributes.js +35 -19
- package/dist/src/extLink.js +5 -4
- package/dist/src/heading.js +11 -3
- package/dist/src/index.js +3 -4
- package/dist/src/link/base.js +2 -4
- package/dist/src/link/file.js +5 -5
- package/dist/src/link/galleryImage.js +1 -3
- package/dist/src/magicLink.js +6 -5
- 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/parameter.js +5 -2
- package/dist/src/table/td.d.ts +2 -2
- package/dist/src/table/td.js +1 -1
- 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/util/debug.js +5 -7
- package/dist/util/html.js +3 -11
- package/dist/util/sharable.js +2 -0
- package/dist/util/sharable.mjs +3 -1
- package/extensions/dist/base.js +1 -1
- package/extensions/dist/env.js +34 -0
- package/package.json +19 -20
package/config/jawiki.json
CHANGED
|
@@ -899,7 +899,7 @@
|
|
|
899
899
|
"EXPECTED_UNCONNECTED_PAGE": "EXPECTEDUNCONNECTEDPAGE"
|
|
900
900
|
}
|
|
901
901
|
],
|
|
902
|
-
"protocol": "bitcoin:|ftp://|ftps://|geo:|git://|gopher://|http://|https://|irc://|ircs://|magnet:|mailto:|matrix:|mms://|news:|nntp://|redis://|sftp://|sip:|sips:|sms:|ssh://|svn://|tel:|telnet://|urn:|wikipedia://|worldwind://|xmpp
|
|
902
|
+
"protocol": "bitcoin:|ftp://|ftps://|geo:|git://|gopher://|http://|https://|irc://|ircs://|magnet:|mailto:|matrix:|mms://|news:|nntp://|redis://|sftp://|sip:|sips:|sms:|ssh://|svn://|tel:|telnet://|urn:|wikipedia://|worldwind://|xmpp:|commonsfinder://",
|
|
903
903
|
"interwiki": [],
|
|
904
904
|
"img": {
|
|
905
905
|
"代替文=$1": "alt",
|
|
@@ -915,12 +915,14 @@
|
|
|
915
915
|
"中央": "center",
|
|
916
916
|
"center": "center",
|
|
917
917
|
"centre": "center",
|
|
918
|
+
"class=$1": "class",
|
|
918
919
|
"フレーム": "framed",
|
|
919
920
|
"frame": "framed",
|
|
920
921
|
"framed": "framed",
|
|
921
922
|
"enframed": "framed",
|
|
922
923
|
"フレームなし": "frameless",
|
|
923
924
|
"frameless": "frameless",
|
|
925
|
+
"lang=$1": "lang",
|
|
924
926
|
"左": "left",
|
|
925
927
|
"left": "left",
|
|
926
928
|
"リンク=$1": "link",
|
|
@@ -959,9 +961,7 @@
|
|
|
959
961
|
"upright=$1": "upright",
|
|
960
962
|
"upright $1": "upright",
|
|
961
963
|
"$1ピクセル": "width",
|
|
962
|
-
"$1px": "width"
|
|
963
|
-
"class=$1": "class",
|
|
964
|
-
"lang=$1": "lang"
|
|
964
|
+
"$1px": "width"
|
|
965
965
|
},
|
|
966
966
|
"redirection": [
|
|
967
967
|
"#転送",
|
|
@@ -971,5 +971,6 @@
|
|
|
971
971
|
"#redirect"
|
|
972
972
|
],
|
|
973
973
|
"variants": [],
|
|
974
|
-
"articlePath": "/wiki/$1"
|
|
974
|
+
"articlePath": "/wiki/$1",
|
|
975
|
+
"server": "//ja.wikipedia.org"
|
|
975
976
|
}
|
package/config/llwiki.json
CHANGED
package/config/minimum.json
CHANGED
|
@@ -125,7 +125,7 @@
|
|
|
125
125
|
{},
|
|
126
126
|
{}
|
|
127
127
|
],
|
|
128
|
-
"protocol": "bitcoin:|ftp://|ftps://|geo:|git://|gopher://|http://|https://|irc://|ircs://|magnet:|mailto:|matrix:|mms://|news:|nntp://|redis://|sftp://|sip:|sips:|sms:|ssh://|svn://|tel:|telnet://|urn:|wikipedia://|worldwind://|xmpp
|
|
128
|
+
"protocol": "bitcoin:|ftp://|ftps://|geo:|git://|gopher://|http://|https://|irc://|ircs://|magnet:|mailto:|matrix:|mms://|news:|nntp://|redis://|sftp://|sip:|sips:|sms:|ssh://|svn://|tel:|telnet://|urn:|wikipedia://|worldwind://|xmpp:|commonsfinder://",
|
|
129
129
|
"interwiki": [],
|
|
130
130
|
"img": {},
|
|
131
131
|
"redirection": [
|
package/config/moegirl.json
CHANGED
package/config/zhwiki.json
CHANGED
|
@@ -961,7 +961,7 @@
|
|
|
961
961
|
"EXPECTED_UNCONNECTED_PAGE": "EXPECTEDUNCONNECTEDPAGE"
|
|
962
962
|
}
|
|
963
963
|
],
|
|
964
|
-
"protocol": "bitcoin:|ftp://|ftps://|geo:|git://|gopher://|http://|https://|irc://|ircs://|magnet:|mailto:|matrix:|mms://|news:|nntp://|redis://|sftp://|sip:|sips:|sms:|ssh://|svn://|tel:|telnet://|urn:|wikipedia://|worldwind://|xmpp
|
|
964
|
+
"protocol": "bitcoin:|ftp://|ftps://|geo:|git://|gopher://|http://|https://|irc://|ircs://|magnet:|mailto:|matrix:|mms://|news:|nntp://|redis://|sftp://|sip:|sips:|sms:|ssh://|svn://|tel:|telnet://|urn:|wikipedia://|worldwind://|xmpp:|commonsfinder://",
|
|
965
965
|
"interwiki": [],
|
|
966
966
|
"img": {
|
|
967
967
|
"alt=$1": "alt",
|
|
@@ -1060,5 +1060,6 @@
|
|
|
1060
1060
|
"zh-sg",
|
|
1061
1061
|
"zh-tw"
|
|
1062
1062
|
],
|
|
1063
|
-
"articlePath": "/wiki/$1"
|
|
1063
|
+
"articlePath": "/wiki/$1",
|
|
1064
|
+
"server": "//zh.wikipedia.org"
|
|
1064
1065
|
}
|
package/dist/addon/attribute.js
CHANGED
|
@@ -163,7 +163,7 @@ attributes_1.AttributesToken.prototype.toggleAttr =
|
|
|
163
163
|
key = (0, string_1.trimLc)(key);
|
|
164
164
|
const attr = this.getAttrToken(key);
|
|
165
165
|
/* c8 ignore next 3 */
|
|
166
|
-
if (attr && attr.getValue() !==
|
|
166
|
+
if (attr && attr.getValue() !== '') {
|
|
167
167
|
throw new RangeError(`${key} attribute is not Boolean!`);
|
|
168
168
|
}
|
|
169
169
|
if (attr) {
|
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
|
}
|
package/dist/base.d.mts
CHANGED
|
@@ -9,13 +9,14 @@ export interface Config {
|
|
|
9
9
|
readonly parserFunction: [Record<string, string>, Record<string, string>, string[], string[]];
|
|
10
10
|
readonly doubleUnderscore: [string[], string[], Record<string, string>, Record<string, string>];
|
|
11
11
|
readonly protocol: string;
|
|
12
|
-
readonly interwiki: string[];
|
|
13
12
|
readonly img: Record<string, string>;
|
|
14
13
|
readonly redirection: string[];
|
|
15
14
|
readonly variants: string[];
|
|
16
15
|
articlePath?: string;
|
|
17
16
|
readonly conversionTable?: [string, string][];
|
|
18
17
|
readonly redirects?: [string, string][];
|
|
18
|
+
readonly interwiki: string[];
|
|
19
|
+
server?: string;
|
|
19
20
|
}
|
|
20
21
|
export type ConfigData = Omit<Config, 'excludes'>;
|
|
21
22
|
export type TokenTypes = 'root' | 'plain' | 'redirect' | 'redirect-syntax' | 'redirect-target' | 'translate' | 'translate-attr' | 'translate-inner' | 'tvar' | 'tvar-name' | 'onlyinclude' | 'noinclude' | 'include' | 'comment' | 'ext' | 'ext-attrs' | 'ext-attr-dirty' | 'ext-attr' | 'attr-key' | 'attr-value' | 'ext-inner' | 'arg' | 'arg-name' | 'arg-default' | 'hidden' | 'magic-word' | 'magic-word-name' | 'invoke-function' | 'invoke-module' | 'template' | 'template-name' | 'parameter' | 'parameter-key' | 'parameter-value' | 'heading' | 'heading-title' | 'heading-trail' | 'html' | 'html-attrs' | 'html-attr-dirty' | 'html-attr' | 'table' | 'tr' | 'td' | 'table-syntax' | 'table-attrs' | 'table-attr-dirty' | 'table-attr' | 'table-inter' | 'td-inner' | 'hr' | 'double-underscore' | 'link' | 'link-target' | 'link-text' | 'category' | 'file' | 'gallery-image' | 'imagemap-image' | 'image-parameter' | 'quote' | 'ext-link' | 'ext-link-text' | 'ext-link-url' | 'free-ext-link' | 'magic-link' | 'list' | 'dd' | 'converter' | 'converter-flags' | 'converter-flag' | 'converter-rule' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'param-line' | 'imagemap-link' | 'list-range';
|
|
@@ -298,8 +299,9 @@ export interface LanguageService {
|
|
|
298
299
|
[Symbol.dispose](): void;
|
|
299
300
|
}
|
|
300
301
|
export type SeverityLevel = 0 | 1 | 2 | false | 'off' | 'warning' | 'error';
|
|
301
|
-
export type
|
|
302
|
-
export type
|
|
302
|
+
export type FullLintConfigValue = [SeverityLevel, Record<string, SeverityLevel>?];
|
|
303
|
+
export type LintConfigValue = SeverityLevel | FullLintConfigValue | Record<string, SeverityLevel>;
|
|
304
|
+
export type LintRuleConfig<T = LintConfigValue> = Partial<Record<LintError.Rule, T>>;
|
|
303
305
|
export interface FullLintConfig {
|
|
304
306
|
rules: LintRuleConfig;
|
|
305
307
|
configurationComment?: string;
|
package/dist/base.d.ts
CHANGED
|
@@ -9,13 +9,14 @@ export interface Config {
|
|
|
9
9
|
readonly parserFunction: [Record<string, string>, Record<string, string>, string[], string[]];
|
|
10
10
|
readonly doubleUnderscore: [string[], string[], Record<string, string>, Record<string, string>];
|
|
11
11
|
readonly protocol: string;
|
|
12
|
-
readonly interwiki: string[];
|
|
13
12
|
readonly img: Record<string, string>;
|
|
14
13
|
readonly redirection: string[];
|
|
15
14
|
readonly variants: string[];
|
|
16
15
|
articlePath?: string;
|
|
17
16
|
readonly conversionTable?: [string, string][];
|
|
18
17
|
readonly redirects?: [string, string][];
|
|
18
|
+
readonly interwiki: string[];
|
|
19
|
+
server?: string;
|
|
19
20
|
}
|
|
20
21
|
export type ConfigData = Omit<Config, 'excludes'>;
|
|
21
22
|
export type TokenTypes = 'root' | 'plain' | 'redirect' | 'redirect-syntax' | 'redirect-target' | 'translate' | 'translate-attr' | 'translate-inner' | 'tvar' | 'tvar-name' | 'onlyinclude' | 'noinclude' | 'include' | 'comment' | 'ext' | 'ext-attrs' | 'ext-attr-dirty' | 'ext-attr' | 'attr-key' | 'attr-value' | 'ext-inner' | 'arg' | 'arg-name' | 'arg-default' | 'hidden' | 'magic-word' | 'magic-word-name' | 'invoke-function' | 'invoke-module' | 'template' | 'template-name' | 'parameter' | 'parameter-key' | 'parameter-value' | 'heading' | 'heading-title' | 'heading-trail' | 'html' | 'html-attrs' | 'html-attr-dirty' | 'html-attr' | 'table' | 'tr' | 'td' | 'table-syntax' | 'table-attrs' | 'table-attr-dirty' | 'table-attr' | 'table-inter' | 'td-inner' | 'hr' | 'double-underscore' | 'link' | 'link-target' | 'link-text' | 'category' | 'file' | 'gallery-image' | 'imagemap-image' | 'image-parameter' | 'quote' | 'ext-link' | 'ext-link-text' | 'ext-link-url' | 'free-ext-link' | 'magic-link' | 'list' | 'dd' | 'converter' | 'converter-flags' | 'converter-flag' | 'converter-rule' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'param-line' | 'imagemap-link' | 'list-range';
|
|
@@ -298,8 +299,9 @@ export interface LanguageService {
|
|
|
298
299
|
[Symbol.dispose](): void;
|
|
299
300
|
}
|
|
300
301
|
export type SeverityLevel = 0 | 1 | 2 | false | 'off' | 'warning' | 'error';
|
|
301
|
-
export type
|
|
302
|
-
export type
|
|
302
|
+
export type FullLintConfigValue = [SeverityLevel, Record<string, SeverityLevel>?];
|
|
303
|
+
export type LintConfigValue = SeverityLevel | FullLintConfigValue | Record<string, SeverityLevel>;
|
|
304
|
+
export type LintRuleConfig<T = LintConfigValue> = Partial<Record<LintError.Rule, T>>;
|
|
303
305
|
export interface FullLintConfig {
|
|
304
306
|
rules: LintRuleConfig;
|
|
305
307
|
configurationComment?: string;
|
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.42.0";
|
|
44
44
|
/**
|
|
45
45
|
* Get the parser configuration for a Wikimedia Foundation project.
|
|
46
46
|
* @param site site nickname
|
|
@@ -78,13 +78,7 @@ exports.default = async (site, url, user, force, internal) => {
|
|
|
78
78
|
'User-Agent': `${pkg}/${version} (https://www.npmjs.com/package/${pkg}; ${user}) Node.js/${process.version}`,
|
|
79
79
|
},
|
|
80
80
|
}
|
|
81
|
-
: undefined, m = await (await fetch(`${url}/load.php?modules=ext.CodeMirror.data|ext.CodeMirror`, headers)).text(),
|
|
82
|
-
action: 'query',
|
|
83
|
-
meta: 'siteinfo',
|
|
84
|
-
siprop: 'general|magicwords|functionhooks|namespaces|namespacealiases',
|
|
85
|
-
format: 'json',
|
|
86
|
-
formatversion: '2',
|
|
87
|
-
}, { general: { articlepath, variants, langconversion }, magicwords, namespaces, namespacealiases, functionhooks, } = (await (await fetch(`${url}/api.php?${new URLSearchParams(params).toString()}`, headers)).json()).query, tempFile = path_1.default.join(__dirname, 'mw.js');
|
|
81
|
+
: undefined, m = await (await fetch(`${url}/load.php?modules=ext.CodeMirror.data|ext.CodeMirror`, headers)).text(), tempFile = path_1.default.join(__dirname, 'mw.js');
|
|
88
82
|
fs_1.default.writeFileSync(tempFile, m);
|
|
89
83
|
const { stdout, stderr } = (0, child_process_1.spawnSync)(process.execPath, [
|
|
90
84
|
'-r',
|
|
@@ -108,13 +102,19 @@ exports.default = async (site, url, user, force, internal) => {
|
|
|
108
102
|
catch {
|
|
109
103
|
throw new RangeError('Extension:CodeMirror is not installed!');
|
|
110
104
|
}
|
|
111
|
-
const
|
|
105
|
+
const params = {
|
|
106
|
+
action: 'query',
|
|
107
|
+
meta: 'siteinfo',
|
|
108
|
+
siprop: `general|magicwords|namespaces|namespacealiases${mwConfig.functionHooks ? '' : '|functionhooks'}`,
|
|
109
|
+
format: 'json',
|
|
110
|
+
formatversion: '2',
|
|
111
|
+
}, { general: { articlepath, server, variants, langconversion }, magicwords, namespaces, namespacealiases, functionhooks, } = (await (await fetch(`${url}/api.php?${new URLSearchParams(params).toString()}`, headers)).json()).query, ns = Object.entries(namespaces).filter(([id]) => filterGadget(id))
|
|
112
112
|
.flatMap(([id, { name, canonical = '' }]) => [
|
|
113
113
|
[id, name],
|
|
114
114
|
...name === canonical ? [] : [[id, canonical]],
|
|
115
115
|
]), config = {
|
|
116
116
|
...(0, cm_util_1.getParserConfig)(require(path_1.default.join(dir, 'minimum.json')), mwConfig),
|
|
117
|
-
|
|
117
|
+
...!(mwConfig.imageKeywords && mwConfig.redirection) && (0, cm_util_1.getKeywords)(magicwords),
|
|
118
118
|
variants: langconversion ? (0, cm_util_1.getVariants)(variants) : [],
|
|
119
119
|
namespaces: Object.fromEntries(ns),
|
|
120
120
|
nsid: Object.fromEntries([
|
|
@@ -122,6 +122,7 @@ exports.default = async (site, url, user, force, internal) => {
|
|
|
122
122
|
...namespacealiases.filter(({ id }) => filterGadget(id)).map(({ id, alias }) => [alias.toLowerCase(), id]),
|
|
123
123
|
]),
|
|
124
124
|
articlePath: articlepath,
|
|
125
|
+
server,
|
|
125
126
|
}, { doubleUnderscore, parserFunction, variable } = config;
|
|
126
127
|
doubleUnderscore[0] = [];
|
|
127
128
|
doubleUnderscore[1] = [];
|
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/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/lintConfig.js
CHANGED
|
@@ -15,8 +15,8 @@ const dict = new Map([
|
|
|
15
15
|
['error', 'error'],
|
|
16
16
|
]);
|
|
17
17
|
const defaultLintRuleConfig = {
|
|
18
|
-
'arg-in-ext': 1,
|
|
19
|
-
'blank-alt': 1,
|
|
18
|
+
'arg-in-ext': [1],
|
|
19
|
+
'blank-alt': [1],
|
|
20
20
|
'bold-header': [
|
|
21
21
|
1,
|
|
22
22
|
{
|
|
@@ -50,7 +50,7 @@ const defaultLintRuleConfig = {
|
|
|
50
50
|
// value: 2,
|
|
51
51
|
},
|
|
52
52
|
],
|
|
53
|
-
'insecure-style': 2,
|
|
53
|
+
'insecure-style': [2],
|
|
54
54
|
'invalid-gallery': [
|
|
55
55
|
2,
|
|
56
56
|
{
|
|
@@ -75,14 +75,14 @@ const defaultLintRuleConfig = {
|
|
|
75
75
|
// name: 2,
|
|
76
76
|
},
|
|
77
77
|
],
|
|
78
|
-
'invalid-isbn': 2,
|
|
78
|
+
'invalid-isbn': [2],
|
|
79
79
|
'invalid-json': [
|
|
80
80
|
2,
|
|
81
81
|
{
|
|
82
82
|
duplicate: 1,
|
|
83
83
|
},
|
|
84
84
|
],
|
|
85
|
-
'invalid-url': 1,
|
|
85
|
+
'invalid-url': [1],
|
|
86
86
|
'lonely-apos': [
|
|
87
87
|
1,
|
|
88
88
|
{
|
|
@@ -113,7 +113,7 @@ const defaultLintRuleConfig = {
|
|
|
113
113
|
// ref: 2,
|
|
114
114
|
},
|
|
115
115
|
],
|
|
116
|
-
'no-arg': 1,
|
|
116
|
+
'no-arg': [1],
|
|
117
117
|
'no-duplicate': [
|
|
118
118
|
2,
|
|
119
119
|
{
|
|
@@ -147,8 +147,8 @@ const defaultLintRuleConfig = {
|
|
|
147
147
|
// references: 2,
|
|
148
148
|
},
|
|
149
149
|
],
|
|
150
|
-
'obsolete-attr': 1,
|
|
151
|
-
'obsolete-tag': 1,
|
|
150
|
+
'obsolete-attr': [1],
|
|
151
|
+
'obsolete-tag': [1],
|
|
152
152
|
'parsing-order': [
|
|
153
153
|
2,
|
|
154
154
|
{
|
|
@@ -185,7 +185,7 @@ const defaultLintRuleConfig = {
|
|
|
185
185
|
// redirect: 2,
|
|
186
186
|
},
|
|
187
187
|
],
|
|
188
|
-
'table-layout': 1,
|
|
188
|
+
'table-layout': [1],
|
|
189
189
|
'tag-like': [
|
|
190
190
|
2,
|
|
191
191
|
{
|
|
@@ -193,17 +193,17 @@ const defaultLintRuleConfig = {
|
|
|
193
193
|
invalid: 1,
|
|
194
194
|
},
|
|
195
195
|
],
|
|
196
|
-
'unbalanced-header': 2,
|
|
196
|
+
'unbalanced-header': [2],
|
|
197
197
|
'unclosed-comment': [
|
|
198
198
|
1,
|
|
199
199
|
{
|
|
200
200
|
// include: 1,
|
|
201
201
|
},
|
|
202
202
|
],
|
|
203
|
-
'unclosed-quote': 1,
|
|
204
|
-
'unclosed-table': 2,
|
|
205
|
-
unescaped: 2,
|
|
206
|
-
'unknown-page': 1,
|
|
203
|
+
'unclosed-quote': [1],
|
|
204
|
+
'unclosed-table': [2],
|
|
205
|
+
unescaped: [2],
|
|
206
|
+
'unknown-page': [1],
|
|
207
207
|
'unmatched-tag': [
|
|
208
208
|
1,
|
|
209
209
|
{
|
|
@@ -250,7 +250,7 @@ const defaultLintRuleConfig = {
|
|
|
250
250
|
warn: 1,
|
|
251
251
|
},
|
|
252
252
|
],
|
|
253
|
-
'invalid-math': 2,
|
|
253
|
+
'invalid-math': [2],
|
|
254
254
|
};
|
|
255
255
|
const defaultLintConfig = {
|
|
256
256
|
configurationComment: 'lint',
|
|
@@ -267,8 +267,9 @@ const validateSeverity = (severity) => dict.has(severity);
|
|
|
267
267
|
* 验证设置值是否符合规范
|
|
268
268
|
* @param value 设置值
|
|
269
269
|
*/
|
|
270
|
-
const validateConfigValue = (value) => validateSeverity(value)
|
|
271
|
-
|
|
270
|
+
const validateConfigValue = (value) => validateSeverity(value) || (Array.isArray(value)
|
|
271
|
+
? validateSeverity(value[0]) && (value.length === 1 || typeof value[1] === 'object')
|
|
272
|
+
: typeof value === 'object');
|
|
272
273
|
/**
|
|
273
274
|
* 设置语法检查规则
|
|
274
275
|
* @param obj 语法检查设置对象
|
|
@@ -285,7 +286,16 @@ const set = (obj, key, value) => {
|
|
|
285
286
|
return false;
|
|
286
287
|
}
|
|
287
288
|
if (validateConfigValue(value)) {
|
|
288
|
-
|
|
289
|
+
if (Array.isArray(value)) {
|
|
290
|
+
obj[key] = value;
|
|
291
|
+
}
|
|
292
|
+
else if (typeof value === 'object') {
|
|
293
|
+
const [base, options = {}] = defaultLintRuleConfig[key];
|
|
294
|
+
obj[key] = [base, { ...clone(options), ...value }];
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
obj[key] = [value];
|
|
298
|
+
}
|
|
289
299
|
return true;
|
|
290
300
|
}
|
|
291
301
|
/* c8 ignore next */
|
|
@@ -308,11 +318,8 @@ class LintRuleConfiguration {
|
|
|
308
318
|
}
|
|
309
319
|
/** @implements */
|
|
310
320
|
getSeverity(rule, key) {
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
return dict.get(value);
|
|
314
|
-
}
|
|
315
|
-
return key ? dict.get(value[1]?.[key]) ?? dict.get(value[0]) : dict.get(value[0]);
|
|
321
|
+
const [base, options] = this[rule], severity = dict.get(base);
|
|
322
|
+
return key ? dict.get(options?.[key]) ?? severity : severity;
|
|
316
323
|
}
|
|
317
324
|
}
|
|
318
325
|
/** 语法检查设置 */
|
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
|
*
|