wikiparser-node 1.28.0 → 1.29.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 +0 -2
- package/bundle/bundle-es8.min.js +25 -25
- package/bundle/bundle-lsp.min.js +30 -30
- package/bundle/bundle.min.js +24 -24
- package/config/default.json +15 -16
- package/config/jawiki.json +15 -16
- package/data/ext/ThirdPartyNotices.txt +33 -0
- package/data/ext/mapframe.json +489 -2
- package/dist/addon/magicWords.js +132 -0
- package/dist/addon/table.js +4 -4
- package/dist/addon/token.js +37 -126
- package/dist/addon/transclude.js +24 -30
- package/dist/base.d.mts +4 -2
- package/dist/base.d.ts +4 -2
- package/dist/base.js +2 -0
- package/dist/base.mjs +3 -1
- package/dist/bin/config.js +11 -11
- package/dist/index.d.ts +2 -1
- package/dist/index.js +27 -5
- package/dist/lib/document.d.ts +23 -7
- package/dist/lib/document.js +7 -27
- package/dist/lib/element.js +1 -1
- package/dist/lib/lintConfig.js +4 -0
- package/dist/lib/lsp.d.ts +1 -12
- package/dist/lib/lsp.js +45 -79
- package/dist/lib/node.js +25 -25
- package/dist/lib/range.js +2 -2
- package/dist/lib/title.d.ts +3 -1
- package/dist/lib/title.js +54 -33
- package/dist/mixin/elementLike.js +14 -9
- package/dist/parser/commentAndExt.js +34 -27
- package/dist/parser/hrAndDoubleUnderscore.js +9 -8
- package/dist/parser/links.js +4 -3
- package/dist/parser/redirect.js +1 -1
- package/dist/parser/selector.js +7 -9
- package/dist/src/arg.js +6 -9
- package/dist/src/attribute.js +37 -8
- package/dist/src/attributes.js +1 -1
- package/dist/src/converter.js +6 -3
- package/dist/src/converterRule.js +4 -6
- package/dist/src/extLink.js +3 -4
- package/dist/src/heading.js +1 -2
- package/dist/src/imageParameter.d.ts +4 -1
- package/dist/src/imageParameter.js +79 -26
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.js +21 -29
- package/dist/src/link/base.js +6 -8
- package/dist/src/link/file.js +10 -14
- package/dist/src/link/galleryImage.js +1 -1
- package/dist/src/link/redirectTarget.js +1 -1
- package/dist/src/magicLink.js +13 -3
- package/dist/src/multiLine/gallery.js +2 -2
- package/dist/src/multiLine/imagemap.js +3 -4
- package/dist/src/multiLine/paramTag.js +2 -2
- package/dist/src/nowiki/doubleUnderscore.d.ts +2 -1
- package/dist/src/nowiki/doubleUnderscore.js +9 -5
- package/dist/src/nowiki/index.js +58 -4
- package/dist/src/onlyinclude.js +2 -1
- package/dist/src/parameter.js +4 -6
- package/dist/src/redirect.js +2 -2
- package/dist/src/table/base.js +1 -2
- package/dist/src/table/index.js +3 -6
- package/dist/src/table/td.d.ts +2 -3
- package/dist/src/table/td.js +6 -6
- package/dist/src/table/trBase.js +1 -1
- package/dist/src/tag/html.js +3 -4
- package/dist/src/tag/tvar.js +1 -2
- package/dist/src/tagPair/ext.js +12 -5
- package/dist/src/tagPair/include.js +2 -2
- package/dist/src/tagPair/translate.js +2 -2
- package/dist/src/transclude.js +5 -5
- package/dist/util/constants.js +4 -1
- package/dist/util/debug.js +1 -1
- package/dist/util/html.js +13 -10
- package/dist/util/search.js +16 -0
- package/dist/util/sharable.js +27 -3
- package/dist/util/sharable.mjs +28 -4
- package/extensions/dist/base.js +1 -1
- package/i18n/en.json +4 -0
- package/i18n/zh-hans.json +4 -0
- package/i18n/zh-hant.json +4 -0
- package/package.json +9 -7
- package/data/ext/maplink.json +0 -4
package/dist/lib/document.d.ts
CHANGED
|
@@ -3,14 +3,30 @@ import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
|
3
3
|
import type { JSONDocument } from 'vscode-json-languageservice';
|
|
4
4
|
import type { Stylesheet } from 'vscode-css-languageservice';
|
|
5
5
|
import type { Token } from '../internal';
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
export interface TexvcLocation {
|
|
7
|
+
offset: number;
|
|
8
|
+
line: number;
|
|
9
|
+
column: number;
|
|
8
10
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
declare interface Texvcjs {
|
|
12
|
+
check(input: string, options?: {
|
|
13
|
+
usemhchem?: boolean;
|
|
14
|
+
}): {
|
|
15
|
+
status: '+';
|
|
16
|
+
} | {
|
|
17
|
+
status: 'C';
|
|
18
|
+
} | {
|
|
19
|
+
status: 'F' | 'S';
|
|
20
|
+
error: {
|
|
21
|
+
message: string;
|
|
22
|
+
location: {
|
|
23
|
+
start: TexvcLocation;
|
|
24
|
+
end: TexvcLocation;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export declare const texvcjs: Texvcjs | undefined;
|
|
14
30
|
export declare const jsonTags: string[];
|
|
15
31
|
export declare const jsonLSP: import("vscode-json-languageservice").LanguageService | undefined;
|
|
16
32
|
export declare const cssLSP: import("vscode-css-languageservice").LanguageService | undefined;
|
package/dist/lib/document.js
CHANGED
|
@@ -3,40 +3,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.EmbeddedCSSDocument = exports.EmbeddedJSONDocument = exports.stylelint = exports.htmlData = exports.cssLSP = exports.jsonLSP = exports.jsonTags = exports.
|
|
6
|
+
exports.EmbeddedCSSDocument = exports.EmbeddedJSONDocument = exports.stylelint = exports.htmlData = exports.cssLSP = exports.jsonLSP = exports.jsonTags = exports.texvcjs = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const common_1 = require("@bhsd/common");
|
|
9
9
|
/* NOT FOR BROWSER */
|
|
10
10
|
const constants_1 = require("../util/constants");
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Load MathJax
|
|
14
|
-
* @param id MathJax module ID
|
|
15
|
-
*/
|
|
16
|
-
const loadMathJax = (id = 'mathjax') => {
|
|
11
|
+
exports.texvcjs = (() => {
|
|
17
12
|
try {
|
|
18
|
-
|
|
19
|
-
MathJax ??= jax.init({
|
|
20
|
-
loader: {
|
|
21
|
-
load: ['input/tex', '[tex]/mhchem'],
|
|
22
|
-
},
|
|
23
|
-
tex: {
|
|
24
|
-
packages: { '[+]': ['mhchem'] },
|
|
25
|
-
/** @ignore */
|
|
26
|
-
formatError(_, error) {
|
|
27
|
-
throw error;
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
startup: { typeset: false },
|
|
31
|
-
});
|
|
32
|
-
return MathJax;
|
|
13
|
+
return require('mathoid-texvcjs');
|
|
33
14
|
}
|
|
34
15
|
catch {
|
|
35
16
|
/* istanbul ignore next */
|
|
36
17
|
return undefined;
|
|
37
18
|
}
|
|
38
|
-
};
|
|
39
|
-
exports.loadMathJax = loadMathJax;
|
|
19
|
+
})();
|
|
40
20
|
exports.jsonTags = ['templatedata', 'mapframe', 'maplink'];
|
|
41
21
|
exports.jsonLSP = (() => {
|
|
42
22
|
try {
|
|
@@ -46,12 +26,12 @@ exports.jsonLSP = (() => {
|
|
|
46
26
|
async schemaRequestService(uri) {
|
|
47
27
|
return (await fetch(uri)).text();
|
|
48
28
|
},
|
|
49
|
-
});
|
|
29
|
+
}), dir = path_1.default.join('..', '..', 'data', 'ext');
|
|
50
30
|
lsp.configure({
|
|
51
31
|
schemas: exports.jsonTags.map((tag) => {
|
|
52
|
-
const uri = path_1.default.join(
|
|
32
|
+
const uri = path_1.default.join(dir, tag);
|
|
53
33
|
try {
|
|
54
|
-
const schema = require(uri);
|
|
34
|
+
const schema = require(tag === 'maplink' ? path_1.default.join(dir, 'mapframe') : uri);
|
|
55
35
|
return {
|
|
56
36
|
uri,
|
|
57
37
|
fileMatch: [tag],
|
package/dist/lib/element.js
CHANGED
|
@@ -348,7 +348,7 @@ let AstElement = (() => {
|
|
|
348
348
|
child.setAttribute('aIndex', cur);
|
|
349
349
|
const childErrors = child.lint(cur, re);
|
|
350
350
|
if (childErrors.length > 0) {
|
|
351
|
-
|
|
351
|
+
Array.prototype.push.apply(errors, childErrors);
|
|
352
352
|
}
|
|
353
353
|
cur += child.toString().length + this.getGaps(i);
|
|
354
354
|
}
|
package/dist/lib/lintConfig.js
CHANGED
|
@@ -55,6 +55,7 @@ const defaultLintRuleConfig = {
|
|
|
55
55
|
// extension: 2,
|
|
56
56
|
// image: 2,
|
|
57
57
|
parameter: 1,
|
|
58
|
+
// thumb: 2,
|
|
58
59
|
},
|
|
59
60
|
],
|
|
60
61
|
'invalid-imagemap': [
|
|
@@ -72,6 +73,7 @@ const defaultLintRuleConfig = {
|
|
|
72
73
|
},
|
|
73
74
|
],
|
|
74
75
|
'invalid-isbn': 2,
|
|
76
|
+
'invalid-url': 1,
|
|
75
77
|
'lonely-apos': [
|
|
76
78
|
1,
|
|
77
79
|
{
|
|
@@ -99,6 +101,7 @@ const defaultLintRuleConfig = {
|
|
|
99
101
|
2,
|
|
100
102
|
{
|
|
101
103
|
// file: 2,
|
|
104
|
+
// ref: 2,
|
|
102
105
|
},
|
|
103
106
|
],
|
|
104
107
|
'no-arg': 1,
|
|
@@ -218,6 +221,7 @@ const defaultLintRuleConfig = {
|
|
|
218
221
|
warn: 1,
|
|
219
222
|
},
|
|
220
223
|
],
|
|
224
|
+
'invalid-math': 2,
|
|
221
225
|
};
|
|
222
226
|
Object.freeze(defaultLintRuleConfig);
|
|
223
227
|
const defaultLintConfig = {
|
package/dist/lib/lsp.d.ts
CHANGED
|
@@ -1,28 +1,17 @@
|
|
|
1
1
|
import Parser from '../index';
|
|
2
2
|
import type { Range, Position, ColorInformation, ColorPresentation, FoldingRange, DocumentLink, Location, WorkspaceEdit, Diagnostic as DiagnosticBase, TextEdit, Hover, SignatureHelp, InlayHint, CodeAction, DocumentSymbol } from 'vscode-languageserver-types';
|
|
3
3
|
import type { Config, LanguageService as LanguageServiceBase, CompletionItem, SignatureData } from '../base';
|
|
4
|
-
import type {
|
|
4
|
+
import type { AttributeToken } from '../internal';
|
|
5
5
|
export interface QuickFixData extends TextEdit {
|
|
6
6
|
title: string;
|
|
7
7
|
fix: boolean;
|
|
8
8
|
}
|
|
9
9
|
export declare const tasks: WeakMap<object, Parser.LanguageService>;
|
|
10
|
-
/**
|
|
11
|
-
* Check if a token is a plain attribute.
|
|
12
|
-
* @param token
|
|
13
|
-
* @param token.type
|
|
14
|
-
* @param token.parentNode
|
|
15
|
-
* @param token.length
|
|
16
|
-
* @param token.firstChild
|
|
17
|
-
* @param style whether it is a style attribute
|
|
18
|
-
*/
|
|
19
|
-
export declare const isAttr: ({ type, parentNode, length, firstChild }: Token, style?: boolean) => boolean | undefined;
|
|
20
10
|
/** VSCode-style language service */
|
|
21
11
|
export declare class LanguageService implements LanguageServiceBase {
|
|
22
12
|
#private;
|
|
23
13
|
/** @since v1.17.1 */
|
|
24
14
|
include: boolean;
|
|
25
|
-
lilypond: string;
|
|
26
15
|
/** @param uri 任务标识 */
|
|
27
16
|
constructor(uri: object);
|
|
28
17
|
/** @implements */
|
package/dist/lib/lsp.js
CHANGED
|
@@ -3,16 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.LanguageService = exports.
|
|
6
|
+
exports.LanguageService = exports.tasks = void 0;
|
|
7
7
|
const common_1 = require("@bhsd/common");
|
|
8
|
+
const cm_util_1 = require("@bhsd/cm-util");
|
|
8
9
|
const base_1 = require("../base");
|
|
9
10
|
const sharable_1 = require("../util/sharable");
|
|
10
11
|
const lint_1 = require("../util/lint");
|
|
11
12
|
const string_1 = require("../util/string");
|
|
12
13
|
const index_1 = __importDefault(require("../index"));
|
|
13
|
-
/* NOT FOR BROWSER */
|
|
14
|
-
const constants_1 = require("../util/constants");
|
|
15
|
-
/* NOT FOR BROWSER END */
|
|
16
14
|
/* NOT FOR BROWSER ONLY */
|
|
17
15
|
const fs_1 = __importDefault(require("fs"));
|
|
18
16
|
const path_1 = __importDefault(require("path"));
|
|
@@ -20,9 +18,11 @@ const util_1 = __importDefault(require("util"));
|
|
|
20
18
|
const child_process_1 = require("child_process");
|
|
21
19
|
const crypto_1 = require("crypto");
|
|
22
20
|
const stylelint_util_1 = require("@bhsd/stylelint-util");
|
|
21
|
+
const search_1 = __importDefault(require("../util/search"));
|
|
22
|
+
const constants_1 = require("../util/constants");
|
|
23
23
|
const document_1 = require("./document");
|
|
24
24
|
/** @see https://www.npmjs.com/package/stylelint-config-recommended */
|
|
25
|
-
const cssRules = { 'block-no-empty': null },
|
|
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
26
|
let colors;
|
|
27
27
|
/* NOT FOR BROWSER ONLY END */
|
|
28
28
|
exports.tasks = new WeakMap();
|
|
@@ -56,7 +56,6 @@ const isAttr = ({ type, parentNode, length, firstChild }, style) => type === 'at
|
|
|
56
56
|
&& (!style
|
|
57
57
|
|| parentNode.name === 'style'
|
|
58
58
|
&& Boolean(document_1.cssLSP));
|
|
59
|
-
exports.isAttr = isAttr;
|
|
60
59
|
/**
|
|
61
60
|
* Check if a token is an HTML attribute.
|
|
62
61
|
* @param token
|
|
@@ -314,10 +313,11 @@ class LanguageService {
|
|
|
314
313
|
config;
|
|
315
314
|
/** @private */
|
|
316
315
|
data;
|
|
316
|
+
/* NOT FOR BROWSER ONLY */
|
|
317
|
+
/** @private */
|
|
317
318
|
lilypond;
|
|
318
319
|
#lilypondData;
|
|
319
320
|
#mathData;
|
|
320
|
-
#mathSet;
|
|
321
321
|
/* NOT FOR BROWSER ONLY END */
|
|
322
322
|
/** @param uri 任务标识 */
|
|
323
323
|
constructor(uri) {
|
|
@@ -326,7 +326,6 @@ class LanguageService {
|
|
|
326
326
|
const dataDir = path_1.default.join('..', '..', 'data'), extDir = path_1.default.join(dataDir, 'ext');
|
|
327
327
|
this.#lilypondData = require(path_1.default.join(extDir, 'score'));
|
|
328
328
|
this.#mathData = require(path_1.default.join(extDir, 'math'));
|
|
329
|
-
this.#mathSet = new Set(this.#mathData);
|
|
330
329
|
/* NOT FOR BROWSER ONLY END */
|
|
331
330
|
Object.defineProperties(this, {
|
|
332
331
|
config: { enumerable: false },
|
|
@@ -454,8 +453,7 @@ class LanguageService {
|
|
|
454
453
|
})();
|
|
455
454
|
const re = await colors;
|
|
456
455
|
/* NOT FOR BROWSER ONLY END */
|
|
457
|
-
return root.querySelectorAll('attr-value,parameter-value,arg-default').reverse()
|
|
458
|
-
.flatMap(token => {
|
|
456
|
+
return root.querySelectorAll('attr-value,parameter-value,arg-default').reverse().flatMap(token => {
|
|
459
457
|
const { type, childNodes,
|
|
460
458
|
/* NOT FOR BROWSER ONLY */
|
|
461
459
|
parentNode, } = token;
|
|
@@ -463,7 +461,7 @@ class LanguageService {
|
|
|
463
461
|
return [];
|
|
464
462
|
/* NOT FOR BROWSER ONLY */
|
|
465
463
|
}
|
|
466
|
-
else if (
|
|
464
|
+
else if (isAttr(token, true)) {
|
|
467
465
|
const textDoc = new document_1.EmbeddedCSSDocument(root, token);
|
|
468
466
|
return document_1.cssLSP.findDocumentColors(textDoc, textDoc.styleSheet);
|
|
469
467
|
/* NOT FOR BROWSER ONLY END */
|
|
@@ -471,8 +469,7 @@ class LanguageService {
|
|
|
471
469
|
/* NOT FOR BROWSER ONLY */
|
|
472
470
|
const isStyle = re && type === 'attr-value' && parentNode.name === 'style';
|
|
473
471
|
/* NOT FOR BROWSER ONLY END */
|
|
474
|
-
return childNodes.filter((child) => child.type === 'text').reverse()
|
|
475
|
-
.flatMap(child => {
|
|
472
|
+
return childNodes.filter((child) => child.type === 'text').reverse().flatMap(child => {
|
|
476
473
|
const { data } = child, parts = (0, common_1.splitColors)(data, hsl).filter(([, , , isColor]) => isColor);
|
|
477
474
|
/* NOT FOR BROWSER ONLY */
|
|
478
475
|
if (isStyle) {
|
|
@@ -548,7 +545,9 @@ class LanguageService {
|
|
|
548
545
|
Array.isArray(sensitive) ? /* istanbul ignore next */ sensitive : Object.keys(sensitive),
|
|
549
546
|
other,
|
|
550
547
|
].flat(2),
|
|
551
|
-
switches: doubleUnderscore.slice(0, 2).flat()
|
|
548
|
+
switches: doubleUnderscore.slice(0, 2).flat()
|
|
549
|
+
.filter(cm_util_1.isUnderscore)
|
|
550
|
+
.map(w => `__${w}__`),
|
|
552
551
|
protocols: protocol.split('|'),
|
|
553
552
|
params: Object.keys(img)
|
|
554
553
|
.filter(k => k.endsWith('$1') || !k.includes('$1'))
|
|
@@ -700,7 +699,7 @@ class LanguageService {
|
|
|
700
699
|
: undefined;
|
|
701
700
|
/* NOT FOR BROWSER ONLY */
|
|
702
701
|
}
|
|
703
|
-
else if (
|
|
702
|
+
else if (isAttr(cur, true)) {
|
|
704
703
|
const textDoc = new document_1.EmbeddedCSSDocument(root, cur);
|
|
705
704
|
return document_1.cssLSP.doComplete(textDoc, position, textDoc.styleSheet).items.map((item) => ({
|
|
706
705
|
...item,
|
|
@@ -735,7 +734,7 @@ class LanguageService {
|
|
|
735
734
|
];
|
|
736
735
|
}
|
|
737
736
|
}
|
|
738
|
-
else if (type === 'ext-inner' && mathTags.
|
|
737
|
+
else if (type === 'ext-inner' && constants_1.mathTags.has(cur.name)) {
|
|
739
738
|
const word = /(?<!\\)\\[a-z]+$/iu.exec(curLine.slice(0, character))?.[0];
|
|
740
739
|
if (word) {
|
|
741
740
|
const data = this.#mathData;
|
|
@@ -745,7 +744,7 @@ class LanguageService {
|
|
|
745
744
|
}
|
|
746
745
|
/* NOT FOR BROWSER ONLY END */
|
|
747
746
|
}
|
|
748
|
-
else if (
|
|
747
|
+
else if (isAttr(cur) && isHtmlAttr(parentNode)) {
|
|
749
748
|
const data = (0, lint_1.provideValues)(parentNode.tag, parentNode.name);
|
|
750
749
|
if (data.length === 0) {
|
|
751
750
|
return undefined;
|
|
@@ -777,8 +776,7 @@ class LanguageService {
|
|
|
777
776
|
severity: severity === 'error' ? 1 : 2,
|
|
778
777
|
source:
|
|
779
778
|
/* eslint-disable @stylistic/operator-linebreak */
|
|
780
|
-
rule
|
|
781
|
-
'css' :
|
|
779
|
+
sources[rule] ??
|
|
782
780
|
'WikiLint',
|
|
783
781
|
code: code ??
|
|
784
782
|
/* eslint-enable @stylistic/operator-linebreak */
|
|
@@ -807,7 +805,7 @@ class LanguageService {
|
|
|
807
805
|
return acc;
|
|
808
806
|
});
|
|
809
807
|
return cssErrors.map(({ rule, text: msg, severity, line, column, endLine = line, endColumn = column, fix, }) => {
|
|
810
|
-
const i =
|
|
808
|
+
const i = (0, search_1.default)(bottoms, line, (bottom, needle) => bottom - needle);
|
|
811
809
|
return {
|
|
812
810
|
range: {
|
|
813
811
|
start: getStylelintPos(rects[i], bottoms[i], line, column - 1),
|
|
@@ -895,42 +893,6 @@ class LanguageService {
|
|
|
895
893
|
}));
|
|
896
894
|
}
|
|
897
895
|
}
|
|
898
|
-
const MathJax = await (0, document_1.loadMathJax)(this.mathjax), data = this.#mathSet, mathDiagnostics = root.querySelectorAll(mathSelector)
|
|
899
|
-
.map(token => {
|
|
900
|
-
const { selfClosing, innerText, lastChild, name } = token;
|
|
901
|
-
if (selfClosing) {
|
|
902
|
-
return [];
|
|
903
|
-
}
|
|
904
|
-
const hasCe = name === 'math' && token.hasAttr('chem'), mathErrors = [...innerText.matchAll(/(?<!\\)\\[a-z]+/giu)]
|
|
905
|
-
.filter(([macro]) => !(hasCe && macro === String.raw `\ce` || data.has(macro)))
|
|
906
|
-
.map(({ 0: macro, index }) => {
|
|
907
|
-
const aIndex = lastChild.getAbsoluteIndex() + index;
|
|
908
|
-
return {
|
|
909
|
-
range: createRange(root, aIndex, aIndex + macro.length),
|
|
910
|
-
severity: 2,
|
|
911
|
-
source: 'MathJax',
|
|
912
|
-
code: 'UnknownMacro',
|
|
913
|
-
message: `Unknown macro "${macro}"`,
|
|
914
|
-
};
|
|
915
|
-
});
|
|
916
|
-
if (MathJax) {
|
|
917
|
-
try {
|
|
918
|
-
MathJax.tex2mml(name === 'math' ? innerText : String.raw `\ce{${innerText}}`);
|
|
919
|
-
}
|
|
920
|
-
catch (e) {
|
|
921
|
-
if (e && typeof e === 'object' && 'id' in e && 'message' in e) {
|
|
922
|
-
mathErrors.push({
|
|
923
|
-
range: createNodeRange(lastChild),
|
|
924
|
-
severity: 2,
|
|
925
|
-
source: 'MathJax',
|
|
926
|
-
code: e.id,
|
|
927
|
-
message: e.message,
|
|
928
|
-
});
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
return mathErrors;
|
|
933
|
-
});
|
|
934
896
|
/* NOT FOR BROWSER ONLY END */
|
|
935
897
|
return [
|
|
936
898
|
diagnostics,
|
|
@@ -938,7 +900,6 @@ class LanguageService {
|
|
|
938
900
|
jsonDiagnostics,
|
|
939
901
|
/* NOT FOR BROWSER ONLY */
|
|
940
902
|
lilypondDiagnostics,
|
|
941
|
-
mathDiagnostics,
|
|
942
903
|
].flat(2);
|
|
943
904
|
}
|
|
944
905
|
/**
|
|
@@ -1016,7 +977,7 @@ class LanguageService {
|
|
|
1016
977
|
if (!selfClosing) {
|
|
1017
978
|
const foldingRanges = document_1.jsonLSP.getFoldingRanges(new document_1.EmbeddedJSONDocument(root, lastChild));
|
|
1018
979
|
if (foldingRanges.length > 0) {
|
|
1019
|
-
|
|
980
|
+
Array.prototype.push.apply(ranges, foldingRanges);
|
|
1020
981
|
}
|
|
1021
982
|
}
|
|
1022
983
|
}
|
|
@@ -1034,7 +995,7 @@ class LanguageService {
|
|
|
1034
995
|
this.config ??= index_1.default.getConfig();
|
|
1035
996
|
const { articlePath, protocol } = this.config, absolute = articlePath?.includes('//'), protocolRegex = getLinkRegex(protocol);
|
|
1036
997
|
return (await this.#queue(text))
|
|
1037
|
-
.querySelectorAll(`magic-link,ext-link-url,free-ext-link,attr-value
|
|
998
|
+
.querySelectorAll(`magic-link,ext-link-url,free-ext-link,attr-value${absolute ? ',link-target,template-name,invoke-module,magic-word#filepath,magic-word#widget' : ''},image-parameter#link,image-parameter#manualthumb`)
|
|
1038
999
|
.reverse()
|
|
1039
1000
|
.map((token) => {
|
|
1040
1001
|
let name;
|
|
@@ -1042,11 +1003,16 @@ class LanguageService {
|
|
|
1042
1003
|
({ name } = token);
|
|
1043
1004
|
token = token.childNodes[1].lastChild; // eslint-disable-line no-param-reassign
|
|
1044
1005
|
}
|
|
1006
|
+
else if (token.is('image-parameter')) {
|
|
1007
|
+
({ name } = token);
|
|
1008
|
+
}
|
|
1045
1009
|
const { type, parentNode, firstChild, lastChild, childNodes, length } = token, { tag } = parentNode;
|
|
1046
1010
|
name ??= parentNode.name;
|
|
1047
1011
|
if (!(type !== 'attr-value'
|
|
1012
|
+
|| name === 'cite' && ['blockquote', 'del', 'ins', 'q'].includes(tag)
|
|
1048
1013
|
|| name === 'src' && ['templatestyles', 'img'].includes(tag)
|
|
1049
|
-
|| name === '
|
|
1014
|
+
|| name === 'templatename' && tag === 'rss'
|
|
1015
|
+
|| name === 'file' && tag === 'phonos')
|
|
1050
1016
|
|| !isPlain(token)) {
|
|
1051
1017
|
return false;
|
|
1052
1018
|
}
|
|
@@ -1071,29 +1037,29 @@ class LanguageService {
|
|
|
1071
1037
|
}
|
|
1072
1038
|
target = parentNode.link.getUrl(articlePath);
|
|
1073
1039
|
}
|
|
1074
|
-
else if (type === 'template-name') {
|
|
1040
|
+
else if (type === 'link-target' || type === 'template-name') {
|
|
1075
1041
|
target = parentNode.getAttribute('title').getUrl(articlePath);
|
|
1076
1042
|
}
|
|
1077
|
-
else if (['
|
|
1078
|
-
|| type === 'attr-value' && name === 'src' && tag === 'templatestyles'
|
|
1079
|
-
|
|
1043
|
+
else if (['invoke-module', 'parameter-value'].includes(type)
|
|
1044
|
+
|| type === 'attr-value' && (name === 'src' && tag === 'templatestyles'
|
|
1045
|
+
|| name === 'templatename' && tag === 'rss'
|
|
1046
|
+
|| name === 'file' && tag === 'phonos')
|
|
1047
|
+
|| type === 'image-parameter' && (name === 'manualthumb' || !protocolRegex.test(target))) {
|
|
1080
1048
|
if (!absolute || target.startsWith('/')) {
|
|
1081
1049
|
return false;
|
|
1082
1050
|
}
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
// no default
|
|
1051
|
+
else if (type === 'image-parameter' && name === 'manualthumb'
|
|
1052
|
+
|| type === 'parameter-value' && name === 'filepath'
|
|
1053
|
+
|| type === 'attr-value' && tag === 'phonos') {
|
|
1054
|
+
target = `File:${target}`;
|
|
1055
|
+
}
|
|
1056
|
+
else if (type === 'parameter-value') {
|
|
1057
|
+
target = `Widget:${target}`;
|
|
1058
|
+
}
|
|
1059
|
+
else if (type === 'invoke-module') {
|
|
1060
|
+
target = `Module:${target}`;
|
|
1094
1061
|
}
|
|
1095
|
-
const title = index_1.default
|
|
1096
|
-
.normalizeTitle(target, ns, false, this.config, { temporary: true });
|
|
1062
|
+
const title = index_1.default.normalizeTitle(target, type === 'attr-value' ? 10 : 0, false, this.config, { temporary: true });
|
|
1097
1063
|
if (!title.valid) {
|
|
1098
1064
|
return false;
|
|
1099
1065
|
}
|
|
@@ -1272,7 +1238,7 @@ class LanguageService {
|
|
|
1272
1238
|
}
|
|
1273
1239
|
/* NOT FOR BROWSER ONLY */
|
|
1274
1240
|
}
|
|
1275
|
-
else if (
|
|
1241
|
+
else if (isAttr(offsetNode, true)) {
|
|
1276
1242
|
const textDoc = new document_1.EmbeddedCSSDocument(root, offsetNode);
|
|
1277
1243
|
return document_1.cssLSP.doHover(textDoc, position, textDoc.styleSheet) ?? undefined;
|
|
1278
1244
|
}
|
|
@@ -1395,7 +1361,7 @@ class LanguageService {
|
|
|
1395
1361
|
}
|
|
1396
1362
|
/** @private */
|
|
1397
1363
|
findStyleTokens() {
|
|
1398
|
-
return this.#done.querySelectorAll(cssSelector).filter(({ lastChild }) =>
|
|
1364
|
+
return this.#done.querySelectorAll(cssSelector).filter(({ lastChild }) => isAttr(lastChild));
|
|
1399
1365
|
}
|
|
1400
1366
|
/**
|
|
1401
1367
|
* Provide refactoring actions
|
package/dist/lib/node.js
CHANGED
|
@@ -39,6 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
40
|
exports.AstNode = void 0;
|
|
41
41
|
/* eslint-disable @typescript-eslint/no-base-to-string */
|
|
42
|
+
const search_1 = __importDefault(require("../util/search"));
|
|
42
43
|
const lint_1 = require("../util/lint");
|
|
43
44
|
const debug_1 = require("../util/debug");
|
|
44
45
|
const cached_1 = require("../mixin/cached");
|
|
@@ -291,7 +292,7 @@ let AstNode = (() => {
|
|
|
291
292
|
const { length } = String(this);
|
|
292
293
|
index += index < 0 ? length : 0;
|
|
293
294
|
if (index >= 0 && index <= length) {
|
|
294
|
-
const lines = this.getLines(), top =
|
|
295
|
+
const lines = this.getLines(), top = (0, search_1.default)(lines, index, ([, , end], needle) => end - needle);
|
|
295
296
|
return { top, left: index - lines[top][1] };
|
|
296
297
|
}
|
|
297
298
|
return undefined;
|
|
@@ -315,30 +316,28 @@ let AstNode = (() => {
|
|
|
315
316
|
* @param j rank of the child node / 子节点序号
|
|
316
317
|
*/
|
|
317
318
|
getRelativeIndex(j) {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
: 0;
|
|
324
|
-
}
|
|
325
|
-
/* NOT FOR BROWSER */
|
|
326
|
-
this.verifyChild(j, 1);
|
|
327
|
-
/* NOT FOR BROWSER END */
|
|
328
|
-
return (0, lint_1.cache)(this.#rIndex[j], () => {
|
|
329
|
-
const { childNodes } = this, n = j + (j < 0 ? childNodes.length : 0);
|
|
330
|
-
let acc = this.getAttribute('padding');
|
|
331
|
-
for (let i = 0; i < n; i++) {
|
|
332
|
-
if (index_1.default.viewOnly) {
|
|
333
|
-
this.#rIndex[i] = [debug_1.Shadow.rev, acc];
|
|
334
|
-
}
|
|
335
|
-
acc += childNodes[i].toString().length + this.getGaps(i);
|
|
336
|
-
}
|
|
337
|
-
return acc;
|
|
338
|
-
}, value => {
|
|
339
|
-
this.#rIndex[j] = value;
|
|
340
|
-
});
|
|
319
|
+
if (j === undefined) {
|
|
320
|
+
const { parentNode } = this;
|
|
321
|
+
return parentNode
|
|
322
|
+
? parentNode.getRelativeIndex(parentNode.childNodes.indexOf(this))
|
|
323
|
+
: 0;
|
|
341
324
|
}
|
|
325
|
+
/* NOT FOR BROWSER */
|
|
326
|
+
this.verifyChild(j, 1);
|
|
327
|
+
/* NOT FOR BROWSER END */
|
|
328
|
+
return (0, lint_1.cache)(this.#rIndex[j], () => {
|
|
329
|
+
const { childNodes } = this, n = j + (j < 0 ? childNodes.length : 0);
|
|
330
|
+
let acc = this.getAttribute('padding');
|
|
331
|
+
for (let i = 0; i < n; i++) {
|
|
332
|
+
if (index_1.default.viewOnly) {
|
|
333
|
+
this.#rIndex[i] = [debug_1.Shadow.rev, acc];
|
|
334
|
+
}
|
|
335
|
+
acc += childNodes[i].toString().length + this.getGaps(i);
|
|
336
|
+
}
|
|
337
|
+
return acc;
|
|
338
|
+
}, value => {
|
|
339
|
+
this.#rIndex[j] = value;
|
|
340
|
+
});
|
|
342
341
|
}
|
|
343
342
|
/**
|
|
344
343
|
* Get the absolute character index of the current node
|
|
@@ -346,7 +345,8 @@ let AstNode = (() => {
|
|
|
346
345
|
* 获取当前节点的绝对位置
|
|
347
346
|
*/
|
|
348
347
|
getAbsoluteIndex() {
|
|
349
|
-
|
|
348
|
+
// 也用于Prism-Wiki
|
|
349
|
+
return (0, lint_1.cache)(// eslint-disable-line no-unused-labels
|
|
350
350
|
this.#aIndex, () => {
|
|
351
351
|
const { parentNode } = this;
|
|
352
352
|
return parentNode ? parentNode.getAbsoluteIndex() + this.getRelativeIndex() : 0;
|
package/dist/lib/range.js
CHANGED
|
@@ -618,7 +618,7 @@ let AstRange = (() => {
|
|
|
618
618
|
* @param elements nodes to be inserted / 插入节点
|
|
619
619
|
*/
|
|
620
620
|
append(...elements) {
|
|
621
|
-
this
|
|
621
|
+
this.#after(elements);
|
|
622
622
|
const { endContainer } = this;
|
|
623
623
|
if (endContainer.type === 'text') {
|
|
624
624
|
this.#endContainer = endContainer.parentNode;
|
|
@@ -633,7 +633,7 @@ let AstRange = (() => {
|
|
|
633
633
|
* @param elements nodes to be inserted / 插入节点
|
|
634
634
|
*/
|
|
635
635
|
prepend(...elements) {
|
|
636
|
-
|
|
636
|
+
AstRange.prototype.before.apply(this, elements);
|
|
637
637
|
const { startContainer } = this;
|
|
638
638
|
if (startContainer.type === 'text') {
|
|
639
639
|
this.#startContainer = startContainer.parentNode;
|
package/dist/lib/title.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export interface TitleOptions {
|
|
|
4
4
|
decode?: boolean | undefined;
|
|
5
5
|
selfLink?: boolean | undefined;
|
|
6
6
|
halfParsed?: boolean | undefined;
|
|
7
|
+
page?: string | undefined;
|
|
7
8
|
}
|
|
8
9
|
/**
|
|
9
10
|
* title object of a MediaWiki page
|
|
@@ -53,8 +54,9 @@ export declare class Title {
|
|
|
53
54
|
* @param opt.temporary 是否是临时标题
|
|
54
55
|
* @param opt.decode 是否需要解码
|
|
55
56
|
* @param opt.selfLink 是否允许selfLink
|
|
57
|
+
* @param opt.page 当前页面标题
|
|
56
58
|
*/
|
|
57
|
-
constructor(title: string, defaultNs: number, config: Config, { temporary, decode, selfLink }?: TitleOptions);
|
|
59
|
+
constructor(title: string, defaultNs: number, config: Config, { temporary, decode, selfLink, page }?: TitleOptions);
|
|
58
60
|
/**
|
|
59
61
|
* Check if the title is a redirect
|
|
60
62
|
*
|