wikiparser-node 1.30.0 → 1.32.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 +9 -4
- package/bundle/bundle-es8.min.js +28 -29
- package/bundle/bundle-lsp.min.js +34 -34
- package/bundle/bundle.min.js +23 -23
- package/dist/addon/attribute.js +166 -0
- package/dist/addon/link.js +92 -0
- package/dist/addon/table.js +12 -3
- package/dist/addon/token.js +5 -316
- package/dist/addon/transclude.js +11 -8
- package/dist/base.d.mts +13 -4
- package/dist/base.d.ts +13 -4
- package/dist/base.js +2 -0
- package/dist/base.mjs +2 -0
- package/dist/bin/config.js +1 -1
- package/dist/index.d.ts +34 -5
- package/dist/index.js +100 -88
- package/dist/internal.d.ts +6 -1
- package/dist/lib/document.d.ts +9 -7
- package/dist/lib/document.js +91 -66
- package/dist/lib/element.d.ts +8 -8
- package/dist/lib/element.js +52 -50
- package/dist/lib/lintConfig.js +6 -2
- package/dist/lib/lsp.js +120 -56
- package/dist/lib/node.js +21 -15
- package/dist/lib/redirectMap.js +1 -1
- package/dist/lib/text.js +17 -14
- package/dist/lib/title.d.ts +11 -0
- package/dist/lib/title.js +37 -13
- package/dist/mixin/elementLike.js +2 -3
- package/dist/mixin/syntax.js +13 -7
- package/dist/parser/commentAndExt.js +4 -4
- package/dist/parser/hrAndDoubleUnderscore.js +11 -9
- package/dist/parser/selector.js +16 -41
- package/dist/render/expand.js +216 -0
- package/dist/render/extension.js +141 -0
- package/dist/render/html.js +91 -0
- package/dist/render/magicWords.js +768 -0
- package/dist/render/syntaxhighlight.js +415 -0
- package/dist/src/arg.js +8 -1
- package/dist/src/atom.js +2 -0
- package/dist/src/attribute.d.ts +5 -0
- package/dist/src/attribute.js +59 -104
- package/dist/src/attributes.d.ts +5 -0
- package/dist/src/attributes.js +17 -51
- package/dist/src/converter.js +4 -2
- package/dist/src/converterFlags.js +8 -6
- package/dist/src/converterRule.js +19 -15
- package/dist/src/extLink.js +2 -2
- package/dist/src/heading.d.ts +1 -1
- package/dist/src/heading.js +5 -3
- package/dist/src/imageParameter.d.ts +0 -1
- package/dist/src/imageParameter.js +34 -24
- package/dist/src/index.d.ts +5 -5
- package/dist/src/index.js +37 -27
- package/dist/src/link/base.js +26 -36
- package/dist/src/link/category.d.ts +8 -1
- package/dist/src/link/category.js +104 -38
- package/dist/src/link/file.js +21 -8
- package/dist/src/link/galleryImage.js +2 -3
- package/dist/src/link/index.d.ts +1 -1
- package/dist/src/link/index.js +12 -33
- package/dist/src/multiLine/index.js +1 -1
- package/dist/src/nowiki/comment.js +1 -1
- package/dist/src/nowiki/doubleUnderscore.js +4 -2
- package/dist/src/nowiki/index.js +34 -31
- package/dist/src/nowiki/list.js +3 -1
- package/dist/src/nowiki/listBase.d.ts +2 -1
- package/dist/src/nowiki/listBase.js +22 -8
- package/dist/src/nowiki/quote.d.ts +1 -1
- package/dist/src/nowiki/quote.js +3 -3
- package/dist/src/onlyinclude.js +1 -1
- package/dist/src/paramLine.js +2 -0
- package/dist/src/parameter.js +1 -1
- package/dist/src/redirect.js +1 -1
- package/dist/src/table/base.js +5 -4
- package/dist/src/table/index.d.ts +1 -6
- package/dist/src/table/index.js +7 -16
- package/dist/src/table/td.js +12 -9
- package/dist/src/tag/html.js +2 -3
- package/dist/src/tag/index.js +8 -6
- package/dist/src/tagPair/ext.js +18 -41
- package/dist/src/tagPair/index.js +6 -4
- package/dist/src/tagPair/translate.d.ts +1 -0
- package/dist/src/tagPair/translate.js +10 -3
- package/dist/src/transclude.js +18 -21
- package/dist/util/constants.js +9 -3
- package/dist/util/debug.js +72 -5
- package/dist/util/diff.js +17 -15
- package/dist/util/html.js +14 -5
- package/dist/util/selector.js +37 -0
- package/dist/util/sharable.d.mts +4 -1
- package/dist/util/sharable.js +7 -7
- package/dist/util/sharable.mjs +7 -7
- package/dist/util/string.js +51 -20
- package/extensions/dist/base.js +2 -2
- package/extensions/editor.css +1 -1
- package/i18n/en.json +1 -0
- package/i18n/zh-hans.json +30 -29
- package/i18n/zh-hant.json +31 -30
- package/package.json +23 -16
- package/dist/addon/magicWords.js +0 -132
|
@@ -1,10 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
3
|
+
var useValue = arguments.length > 2;
|
|
4
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
5
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
6
|
+
}
|
|
7
|
+
return useValue ? value : void 0;
|
|
8
|
+
};
|
|
9
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
10
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
11
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
12
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
13
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
14
|
+
var _, done = false;
|
|
15
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
16
|
+
var context = {};
|
|
17
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
18
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
19
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
20
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
21
|
+
if (kind === "accessor") {
|
|
22
|
+
if (result === void 0) continue;
|
|
23
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
24
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
25
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
26
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
27
|
+
}
|
|
28
|
+
else if (_ = accept(result)) {
|
|
29
|
+
if (kind === "field") initializers.unshift(_);
|
|
30
|
+
else descriptor[key] = _;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
34
|
+
done = true;
|
|
35
|
+
};
|
|
2
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
37
|
exports.CategoryToken = void 0;
|
|
4
|
-
const string_1 = require("../../util/string");
|
|
5
38
|
const base_1 = require("./base");
|
|
39
|
+
/* PRINT ONLY */
|
|
40
|
+
const string_1 = require("../../util/string");
|
|
41
|
+
/* PRINT ONLY END */
|
|
6
42
|
/* NOT FOR BROWSER */
|
|
7
43
|
const constants_1 = require("../../util/constants");
|
|
44
|
+
const cached_1 = require("../../mixin/cached");
|
|
8
45
|
/* NOT FOR BROWSER END */
|
|
9
46
|
/**
|
|
10
47
|
* category
|
|
@@ -12,45 +49,74 @@ const constants_1 = require("../../util/constants");
|
|
|
12
49
|
* 分类
|
|
13
50
|
* @classdesc `{childNodes: [AtomToken, ?Token]}`
|
|
14
51
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return child && (0, string_1.decodeHtml)(child.text());
|
|
52
|
+
let CategoryToken = (() => {
|
|
53
|
+
let _classSuper = base_1.LinkBaseToken;
|
|
54
|
+
let _instanceExtraInitializers = [];
|
|
55
|
+
let _toHtmlInternal_decorators;
|
|
56
|
+
return class CategoryToken extends _classSuper {
|
|
57
|
+
static {
|
|
58
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
59
|
+
_toHtmlInternal_decorators = [(0, cached_1.cached)()];
|
|
60
|
+
__esDecorate(this, null, _toHtmlInternal_decorators, { kind: "method", name: "toHtmlInternal", static: false, private: false, access: { has: obj => "toHtmlInternal" in obj, get: obj => obj.toHtmlInternal }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
61
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
26
62
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const json = super.json(undefined, start), { sortkey } = this;
|
|
38
|
-
if (sortkey) {
|
|
39
|
-
json['sortkey'] = sortkey;
|
|
63
|
+
/* NOT FOR BROWSER END */
|
|
64
|
+
get type() {
|
|
65
|
+
return 'category';
|
|
66
|
+
}
|
|
67
|
+
/* PRINT ONLY */
|
|
68
|
+
/** sort key / 分类排序关键字 */
|
|
69
|
+
get sortkey() {
|
|
70
|
+
LSP: {
|
|
71
|
+
const { childNodes: [, child] } = this;
|
|
72
|
+
return child && (0, string_1.decodeHtml)(child.text());
|
|
40
73
|
}
|
|
41
|
-
return json;
|
|
42
74
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
75
|
+
/* PRINT ONLY END */
|
|
76
|
+
/* NOT FOR BROWSER */
|
|
77
|
+
set sortkey(text) {
|
|
78
|
+
this.setSortkey(text);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* link text
|
|
82
|
+
*
|
|
83
|
+
* 链接显示文字
|
|
84
|
+
* @since v1.32.0
|
|
85
|
+
*/
|
|
86
|
+
get innerText() {
|
|
87
|
+
return this.link.main;
|
|
88
|
+
}
|
|
89
|
+
/* NOT FOR BROWSER END */
|
|
90
|
+
/** @private */
|
|
91
|
+
json(_, start = this.getAbsoluteIndex()) {
|
|
92
|
+
LSP: {
|
|
93
|
+
const json = super.json(undefined, start), { sortkey } = this;
|
|
94
|
+
if (sortkey) {
|
|
95
|
+
json['sortkey'] = sortkey;
|
|
96
|
+
}
|
|
97
|
+
return json;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/* NOT FOR BROWSER */
|
|
101
|
+
/**
|
|
102
|
+
* Set the sort key
|
|
103
|
+
*
|
|
104
|
+
* 设置排序关键字
|
|
105
|
+
* @param text sort key / 排序关键字
|
|
106
|
+
*/
|
|
107
|
+
setSortkey(text) {
|
|
108
|
+
this.setLinkText(text);
|
|
109
|
+
}
|
|
110
|
+
/** @private */
|
|
111
|
+
toHtmlInternal() {
|
|
112
|
+
constants_1.states.get(this.getRootNode())?.categories.add(super.toHtmlInternal());
|
|
113
|
+
return '';
|
|
114
|
+
}
|
|
115
|
+
constructor() {
|
|
116
|
+
super(...arguments);
|
|
117
|
+
__runInitializers(this, _instanceExtraInitializers);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
})();
|
|
55
121
|
exports.CategoryToken = CategoryToken;
|
|
56
122
|
constants_1.classes['CategoryToken'] = __filename;
|
package/dist/src/link/file.js
CHANGED
|
@@ -39,6 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
40
|
exports.FileToken = void 0;
|
|
41
41
|
const lint_1 = require("../../util/lint");
|
|
42
|
+
const constants_1 = require("../../util/constants");
|
|
42
43
|
const rect_1 = require("../../lib/rect");
|
|
43
44
|
const index_1 = __importDefault(require("../../index"));
|
|
44
45
|
const base_1 = require("./base");
|
|
@@ -46,7 +47,6 @@ const imageParameter_1 = require("../imageParameter");
|
|
|
46
47
|
/* NOT FOR BROWSER */
|
|
47
48
|
const string_1 = require("../../util/string");
|
|
48
49
|
const debug_1 = require("../../util/debug");
|
|
49
|
-
const constants_1 = require("../../util/constants");
|
|
50
50
|
const title_1 = require("../../lib/title");
|
|
51
51
|
const cached_1 = require("../../mixin/cached");
|
|
52
52
|
const frame = new Map([
|
|
@@ -85,6 +85,13 @@ const explode = (str) => {
|
|
|
85
85
|
* @param types token types to be filtered
|
|
86
86
|
*/
|
|
87
87
|
const filterArgs = (args, types) => args.filter(({ childNodes }) => !childNodes.some(node => node.text().trim() && types.has(node.type)));
|
|
88
|
+
/* NOT FOR BROWSER */
|
|
89
|
+
/**
|
|
90
|
+
* check if a string is an integer
|
|
91
|
+
* @param n string to be checked
|
|
92
|
+
*/
|
|
93
|
+
const isInteger = (n) => Boolean(n && !/\D/u.test(n));
|
|
94
|
+
/* NOT FOR BROWSER END */
|
|
88
95
|
/**
|
|
89
96
|
* image
|
|
90
97
|
*
|
|
@@ -187,8 +194,8 @@ let FileToken = (() => {
|
|
|
187
194
|
interwiki, } = this.getAttribute('title'), { firstChild } = this;
|
|
188
195
|
let rule = 'nested-link', s = lintConfig.getSeverity(rule, 'file');
|
|
189
196
|
if (s
|
|
190
|
-
&&
|
|
191
|
-
&& this.
|
|
197
|
+
&& constants_1.extensions.has(extension)
|
|
198
|
+
&& this.isInside('ext-link-text')
|
|
192
199
|
&& this.getValue('link')?.trim() !== '') {
|
|
193
200
|
const e = (0, lint_1.generateForSelf)(this, rect, rule, 'link-in-extlink', s);
|
|
194
201
|
if (computeEditInfo || fix) {
|
|
@@ -263,7 +270,7 @@ let FileToken = (() => {
|
|
|
263
270
|
];
|
|
264
271
|
}
|
|
265
272
|
if (relevantArgs.length > 1) {
|
|
266
|
-
let severity = !isCaption || !extension ||
|
|
273
|
+
let severity = !isCaption || !extension || constants_1.extensions.has(extension);
|
|
267
274
|
if (isCaption && severity) {
|
|
268
275
|
const plainArgs = filterArgs(relevantArgs, transclusion);
|
|
269
276
|
severity = plainArgs.length > 1 && ((arg) => plainArgs.includes(arg));
|
|
@@ -480,15 +487,21 @@ let FileToken = (() => {
|
|
|
480
487
|
}
|
|
481
488
|
/** @private */
|
|
482
489
|
toHtmlInternal(opt) {
|
|
483
|
-
/** @ignore */
|
|
484
|
-
const isInteger = (n) => Boolean(n && !/\D/u.test(n));
|
|
485
490
|
const { link, width, height, type } = this, file = this.getAttribute('title'), fr = this.getFrame(), manual = fr instanceof title_1.Title, visibleCaption = manual || fr === 'thumbnail' || fr === 'framed' || type === 'gallery-image', caption = this.getArg('caption')?.toHtmlInternal({
|
|
486
491
|
...opt,
|
|
487
492
|
nowrap: true,
|
|
488
493
|
}) ?? '', titleFromCaption = visibleCaption && type !== 'gallery-image' ? '' : (0, string_1.sanitizeAlt)(caption), hasLink = manual || link !== file, title = titleFromCaption || (hasLink && typeof link !== 'string' ? link.getTitleAttr() : ''), titleAttr = title && ` title="${title}"`, alt = (0, string_1.sanitizeAlt)(this.getArg('alt')?.toHtmlInternal({
|
|
489
494
|
...opt,
|
|
490
495
|
nowrap: true,
|
|
491
|
-
})) ?? titleFromCaption, horiz = this.getHorizAlign() ?? '', vert = this.getVertAlign() ?? '', className = `${horiz ? `mw-halign-${horiz}` : vert && `mw-valign-${vert}`}${this.getValue('border') ? ' mw-image-border' : ''} ${(0, string_1.sanitizeAlt)(this.getValue('class')) ?? ''}`.trim(), classAttr = className && ` class="${className}"`,
|
|
496
|
+
})) ?? titleFromCaption, horiz = this.getHorizAlign() ?? '', vert = this.getVertAlign() ?? '', className = `${horiz ? `mw-halign-${horiz}` : vert && `mw-valign-${vert}`}${this.getValue('border') ? ' mw-image-border' : ''} ${(0, string_1.sanitizeAlt)(this.getValue('class')) ?? ''}`.trim(), classAttr = className && ` class="${className}"`, hasWidth = isInteger(width), hasHeight = isInteger(height);
|
|
497
|
+
let src;
|
|
498
|
+
try {
|
|
499
|
+
src = manual ? fr.getFileUrl() : file.getFileUrl(hasWidth && Number(width), hasHeight && Number(height));
|
|
500
|
+
}
|
|
501
|
+
catch {
|
|
502
|
+
return '';
|
|
503
|
+
}
|
|
504
|
+
const img = `<img${alt && ` alt="${alt}"`} src="${src}" decoding="async" class="mw-file-element"${hasWidth ? ` width="${width}"` : ''}${hasHeight ? ` height="${height}"` : ''}>`;
|
|
492
505
|
let href = '';
|
|
493
506
|
if (link) {
|
|
494
507
|
try {
|
|
@@ -509,7 +522,7 @@ let FileToken = (() => {
|
|
|
509
522
|
? `<a${href && ` href="${href}"`}${hasLink ? '' : ' class="mw-file-description"'}${titleAttr}${typeof link === 'string' ? ' rel="nofollow"' : ''}>${img}</a>`
|
|
510
523
|
: `<span${titleAttr}>${img}</span>`;
|
|
511
524
|
if (type !== 'gallery-image') {
|
|
512
|
-
return horiz ||
|
|
525
|
+
return horiz || visibleCaption
|
|
513
526
|
? `<figure${classAttr} typeof="mw:File${fr ? `/${manual ? 'Thumb' : frame.get(fr)}` : ''}">${a}<figcaption>${caption}</figcaption></figure>`
|
|
514
527
|
: `<span${classAttr}>${a}</span>`;
|
|
515
528
|
}
|
|
@@ -47,7 +47,6 @@ const file_1 = require("./file");
|
|
|
47
47
|
/* NOT FOR BROWSER */
|
|
48
48
|
const debug_1 = require("../../util/debug");
|
|
49
49
|
const singleLine_1 = require("../../mixin/singleLine");
|
|
50
|
-
const imageParameter_1 = require("../imageParameter");
|
|
51
50
|
/**
|
|
52
51
|
* gallery image
|
|
53
52
|
*
|
|
@@ -100,7 +99,7 @@ let GalleryImageToken = (() => {
|
|
|
100
99
|
}
|
|
101
100
|
accum.splice(length, 1);
|
|
102
101
|
}
|
|
103
|
-
super(link, token?.toString(), config, accum);
|
|
102
|
+
super(link, token?.firstChild.toString(), config, accum);
|
|
104
103
|
this.setAttribute('bracket', false);
|
|
105
104
|
this.privateType = `${type}-image`;
|
|
106
105
|
/* PRINT ONLY */
|
|
@@ -148,7 +147,7 @@ let GalleryImageToken = (() => {
|
|
|
148
147
|
insertAt(child, i) {
|
|
149
148
|
if (this.type === 'gallery-image'
|
|
150
149
|
&& child.is('image-parameter')
|
|
151
|
-
&& !
|
|
150
|
+
&& !constants_1.galleryParams.has(child.name)) {
|
|
152
151
|
child.setAttribute('name', 'invalid');
|
|
153
152
|
}
|
|
154
153
|
return super.insertAt(child, i);
|
package/dist/src/link/index.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export declare abstract class LinkToken extends LinkBaseToken {
|
|
|
36
36
|
* @param fragment URI fragment / 片段标识符
|
|
37
37
|
* @throws `RangeError` 空的片段标识符
|
|
38
38
|
*/
|
|
39
|
-
asSelfLink(fragment?: string
|
|
39
|
+
asSelfLink(fragment?: string): void;
|
|
40
40
|
/**
|
|
41
41
|
* Automatically generate the link text after the pipe
|
|
42
42
|
*
|
package/dist/src/link/index.js
CHANGED
|
@@ -10,7 +10,6 @@ const index_1 = __importDefault(require("../../index"));
|
|
|
10
10
|
const base_1 = require("./base");
|
|
11
11
|
/* NOT FOR BROWSER */
|
|
12
12
|
const constants_1 = require("../../util/constants");
|
|
13
|
-
const string_1 = require("../../util/string");
|
|
14
13
|
/* NOT FOR BROWSER END */
|
|
15
14
|
/**
|
|
16
15
|
* internal link
|
|
@@ -35,7 +34,7 @@ class LinkToken extends base_1.LinkBaseToken {
|
|
|
35
34
|
}
|
|
36
35
|
/** whether to be a self link / 是否链接到自身 */
|
|
37
36
|
get selfLink() {
|
|
38
|
-
const {
|
|
37
|
+
const { title, fragment } = this.link;
|
|
39
38
|
return !title && Boolean(fragment);
|
|
40
39
|
}
|
|
41
40
|
set selfLink(selfLink) {
|
|
@@ -48,7 +47,7 @@ class LinkToken extends base_1.LinkBaseToken {
|
|
|
48
47
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
49
48
|
LINT: {
|
|
50
49
|
const errors = super.lint(start, re), rule = 'nested-link', { lintConfig } = index_1.default, s = lintConfig.getSeverity(rule);
|
|
51
|
-
if (s && this.
|
|
50
|
+
if (s && this.isInside('ext-link-text')) {
|
|
52
51
|
const e = (0, lint_1.generateForSelf)(this, { start }, rule, 'link-in-extlink', s);
|
|
53
52
|
if (lintConfig.computeEditInfo || lintConfig.fix) {
|
|
54
53
|
e.fix = (0, lint_1.fixBy)(e, 'delink', this.innerText);
|
|
@@ -59,6 +58,7 @@ class LinkToken extends base_1.LinkBaseToken {
|
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
60
|
/* NOT FOR BROWSER */
|
|
61
|
+
/* istanbul ignore next */
|
|
62
62
|
/**
|
|
63
63
|
* Set the interlanguage link
|
|
64
64
|
*
|
|
@@ -68,13 +68,10 @@ class LinkToken extends base_1.LinkBaseToken {
|
|
|
68
68
|
* @throws `SyntaxError` 仅有片段标识符
|
|
69
69
|
*/
|
|
70
70
|
setLangLink(lang, link) {
|
|
71
|
-
link
|
|
72
|
-
|
|
73
|
-
if (link.startsWith('#')) {
|
|
74
|
-
throw new SyntaxError('An interlanguage link cannot be fragment only!');
|
|
75
|
-
}
|
|
76
|
-
super.setTarget(lang + (link.startsWith(':') ? '' : ':') + link);
|
|
71
|
+
require('../../addon/link');
|
|
72
|
+
this.setLangLink(lang, link);
|
|
77
73
|
}
|
|
74
|
+
/* istanbul ignore next */
|
|
78
75
|
/**
|
|
79
76
|
* Convert to a self link
|
|
80
77
|
*
|
|
@@ -82,13 +79,11 @@ class LinkToken extends base_1.LinkBaseToken {
|
|
|
82
79
|
* @param fragment URI fragment / 片段标识符
|
|
83
80
|
* @throws `RangeError` 空的片段标识符
|
|
84
81
|
*/
|
|
85
|
-
asSelfLink(fragment
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
throw new RangeError('LinkToken.asSelfLink method must specify a non-empty fragment!');
|
|
89
|
-
}
|
|
90
|
-
this.setTarget(`#${(0, string_1.encode)(fragment)}`);
|
|
82
|
+
asSelfLink(fragment) {
|
|
83
|
+
require('../../addon/link');
|
|
84
|
+
this.asSelfLink(fragment);
|
|
91
85
|
}
|
|
86
|
+
/* istanbul ignore next */
|
|
92
87
|
/**
|
|
93
88
|
* Automatically generate the link text after the pipe
|
|
94
89
|
*
|
|
@@ -96,24 +91,8 @@ class LinkToken extends base_1.LinkBaseToken {
|
|
|
96
91
|
* @throws `Error` 带有"#"或"%"时不可用
|
|
97
92
|
*/
|
|
98
93
|
pipeTrick() {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (linkText.includes('#') || linkText.includes('%')) {
|
|
102
|
-
throw new Error('Pipe trick cannot be used with "#" or "%"!');
|
|
103
|
-
}
|
|
104
|
-
const m1 = /^:?(?:[ \w\x80-\xFF-]+:)?([^(]+?) ?\(.+\)$/u.exec(linkText);
|
|
105
|
-
if (m1) {
|
|
106
|
-
this.setLinkText(m1[1]);
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
const m2 = /^:?(?:[ \w\x80-\xFF-]+:)?([^(]+?) ?(.+)$/u.exec(linkText);
|
|
110
|
-
if (m2) {
|
|
111
|
-
this.setLinkText(m2[1]);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
const m3 = /^:?(?:[ \w\x80-\xFF-]+:)?(.*?)(?: ?(?<!\()\(.+\))?(?:(?:, |,|، ).|$)/u
|
|
115
|
-
.exec(linkText);
|
|
116
|
-
this.setLinkText(m3[1]);
|
|
94
|
+
require('../../addon/link');
|
|
95
|
+
this.pipeTrick();
|
|
117
96
|
}
|
|
118
97
|
}
|
|
119
98
|
exports.LinkToken = LinkToken;
|
|
@@ -116,7 +116,7 @@ let CommentToken = (() => {
|
|
|
116
116
|
}
|
|
117
117
|
/** @private */
|
|
118
118
|
print() {
|
|
119
|
-
return super.print({ pre: '<!--', post: this.closed ? '-->' : '' });
|
|
119
|
+
PRINT: return super.print({ pre: '<!--', post: this.closed ? '-->' : '' });
|
|
120
120
|
}
|
|
121
121
|
/* NOT FOR BROWSER */
|
|
122
122
|
cloneNode() {
|
|
@@ -91,8 +91,10 @@ let DoubleUnderscoreToken = (() => {
|
|
|
91
91
|
}
|
|
92
92
|
/** @private */
|
|
93
93
|
print() {
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
PRINT: {
|
|
95
|
+
const underscore = this.#fullWidth ? '__' : '__';
|
|
96
|
+
return super.print({ pre: underscore, post: underscore });
|
|
97
|
+
}
|
|
96
98
|
}
|
|
97
99
|
/* NOT FOR BROWSER */
|
|
98
100
|
cloneNode() {
|
package/dist/src/nowiki/index.js
CHANGED
|
@@ -60,38 +60,41 @@ class NowikiToken extends base_1.NowikiBaseToken {
|
|
|
60
60
|
NPM: {
|
|
61
61
|
rule = 'invalid-math';
|
|
62
62
|
s = lintConfig.getSeverity(rule);
|
|
63
|
-
if (s &&
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
tex =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (result.status !== '
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
63
|
+
if (s && constants_1.mathTags.has(name)) {
|
|
64
|
+
const texvcjs = (0, document_1.loadTexvcjs)();
|
|
65
|
+
if (texvcjs) {
|
|
66
|
+
const isChem = name !== 'math', display = previousSibling?.getAttr('display') ?? 'block';
|
|
67
|
+
let tex = innerText, n = 0;
|
|
68
|
+
if (isChem) {
|
|
69
|
+
tex = String.raw `\ce{${tex}}`;
|
|
70
|
+
n = 4;
|
|
71
|
+
}
|
|
72
|
+
switch (display) {
|
|
73
|
+
case 'block':
|
|
74
|
+
tex = String.raw `{\displaystyle ${tex}}`;
|
|
75
|
+
n += 15;
|
|
76
|
+
break;
|
|
77
|
+
case 'inline':
|
|
78
|
+
tex = String.raw `{\textstyle ${tex}}`;
|
|
79
|
+
n += 12;
|
|
80
|
+
break;
|
|
81
|
+
case 'linebreak':
|
|
82
|
+
tex = String.raw `\[ ${tex} \]`;
|
|
83
|
+
n += 3;
|
|
84
|
+
// no default
|
|
85
|
+
}
|
|
86
|
+
const result = texvcjs.check(tex, {
|
|
87
|
+
usemhchem: isChem || Boolean(previousSibling?.hasAttr('chem')),
|
|
88
|
+
});
|
|
89
|
+
if (result.status !== '+') {
|
|
90
|
+
const e = (0, lint_1.generateForSelf)(this, { start }, rule, 'chem-required', s);
|
|
91
|
+
if (result.status !== 'C') {
|
|
92
|
+
const { message, location } = result.error, [endIndex, endLine, endCol] = updateLocation(e, location.end, n);
|
|
93
|
+
[e.startIndex, e.startLine, e.startCol] = updateLocation(e, location.start, n);
|
|
94
|
+
Object.assign(e, { endIndex, endLine, endCol, message });
|
|
95
|
+
}
|
|
96
|
+
errors.push(e);
|
|
93
97
|
}
|
|
94
|
-
errors.push(e);
|
|
95
98
|
}
|
|
96
99
|
}
|
|
97
100
|
}
|
package/dist/src/nowiki/list.js
CHANGED
|
@@ -75,9 +75,11 @@ let ListToken = (() => {
|
|
|
75
75
|
const rule = 'syntax-like', s = index_1.default.lintConfig.getSeverity(rule, 'redirect'), { innerText } = this;
|
|
76
76
|
if (s && innerText === '#') {
|
|
77
77
|
let { nextSibling } = this;
|
|
78
|
-
|
|
78
|
+
/* NOT FOR BROWSER */
|
|
79
|
+
if (nextSibling?.is('list-range')) {
|
|
79
80
|
nextSibling = nextSibling.firstChild;
|
|
80
81
|
}
|
|
82
|
+
/* NOT FOR BROWSER END */
|
|
81
83
|
if (nextSibling?.type === 'text' && linkTypes.has(nextSibling.nextSibling?.type)) {
|
|
82
84
|
/^redirect\s*(?::\s*)?$/iu; // eslint-disable-line @typescript-eslint/no-unused-expressions
|
|
83
85
|
const re = new RegExp(String.raw `^(?:${this.getAttribute('config').redirection.join('|')})\s*(?::\s*)?$`, 'iu');
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { NowikiBaseToken } from './base';
|
|
2
2
|
import type { AST } from '../../base';
|
|
3
|
+
import { AstText } from '../../lib/text';
|
|
3
4
|
import { Token } from '../index';
|
|
4
|
-
import type { DdToken, ListToken
|
|
5
|
+
import type { DdToken, ListToken } from '../../internal';
|
|
5
6
|
export interface ListRangeToken extends Token {
|
|
6
7
|
readonly type: 'list-range';
|
|
7
8
|
readonly previousSibling: ListToken | DdToken;
|
|
@@ -5,6 +5,7 @@ const base_1 = require("./base");
|
|
|
5
5
|
/* NOT FOR BROWSER */
|
|
6
6
|
const constants_1 = require("../../util/constants");
|
|
7
7
|
const debug_1 = require("../../util/debug");
|
|
8
|
+
const text_1 = require("../../lib/text");
|
|
8
9
|
const index_1 = require("../index");
|
|
9
10
|
/* NOT FOR BROWSER END */
|
|
10
11
|
/** `;:*#` */
|
|
@@ -90,10 +91,12 @@ class ListBaseToken extends base_1.NowikiBaseToken {
|
|
|
90
91
|
}
|
|
91
92
|
({ nextSibling } = nextSibling);
|
|
92
93
|
}
|
|
93
|
-
|
|
94
|
+
let start, end, contents;
|
|
94
95
|
if (nextSibling && nextSibling.type !== 'text') {
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
const { childNodes } = parentNode;
|
|
97
|
+
start = childNodes.indexOf(this) + 1;
|
|
98
|
+
end = childNodes.indexOf(nextSibling);
|
|
99
|
+
contents = childNodes.slice(start, end);
|
|
97
100
|
}
|
|
98
101
|
else {
|
|
99
102
|
if (type === 'list') {
|
|
@@ -112,12 +115,23 @@ class ListBaseToken extends base_1.NowikiBaseToken {
|
|
|
112
115
|
return parentNode;
|
|
113
116
|
}
|
|
114
117
|
}
|
|
115
|
-
|
|
118
|
+
const { childNodes } = parentNode;
|
|
119
|
+
start = childNodes.indexOf(this) + 1;
|
|
116
120
|
if (nextSibling) {
|
|
117
|
-
|
|
121
|
+
const { data } = nextSibling, offset = data.indexOf('\n'), text = new text_1.AstText(data.slice(0, offset));
|
|
122
|
+
end = childNodes.indexOf(nextSibling);
|
|
123
|
+
contents = childNodes.slice(start, end);
|
|
124
|
+
const last = contents.at(-1);
|
|
125
|
+
if (last) {
|
|
126
|
+
last.setAttribute('nextSibling', text);
|
|
127
|
+
text.setAttribute('previousSibling', last);
|
|
128
|
+
}
|
|
129
|
+
contents.push(text);
|
|
130
|
+
nextSibling.setAttribute('data', data.slice(offset));
|
|
118
131
|
}
|
|
119
132
|
else {
|
|
120
|
-
|
|
133
|
+
end = childNodes.length;
|
|
134
|
+
contents = childNodes.slice(start);
|
|
121
135
|
}
|
|
122
136
|
}
|
|
123
137
|
const token = debug_1.Shadow.run(() => {
|
|
@@ -125,8 +139,8 @@ class ListBaseToken extends base_1.NowikiBaseToken {
|
|
|
125
139
|
t.type = 'list-range';
|
|
126
140
|
return t;
|
|
127
141
|
});
|
|
128
|
-
token.concat(
|
|
129
|
-
(0, debug_1.setChildNodes)(parentNode,
|
|
142
|
+
token.concat(contents); // eslint-disable-line unicorn/prefer-spread
|
|
143
|
+
(0, debug_1.setChildNodes)(parentNode, start, end - start, [token]);
|
|
130
144
|
return token;
|
|
131
145
|
}
|
|
132
146
|
/** @private */
|
|
@@ -32,7 +32,7 @@ export declare abstract class QuoteToken extends NowikiBaseToken {
|
|
|
32
32
|
* Find the matching apostrophes
|
|
33
33
|
*
|
|
34
34
|
* 搜索匹配的直引号
|
|
35
|
-
* @since v1.
|
|
35
|
+
* @since v1.30.0
|
|
36
36
|
* @param type type of apostrophes to match / 匹配的直引号类型
|
|
37
37
|
* @throws `RangeError` ambiguous or wrong apostrophe type
|
|
38
38
|
*/
|
package/dist/src/nowiki/quote.js
CHANGED
|
@@ -138,7 +138,7 @@ let QuoteToken = (() => {
|
|
|
138
138
|
errors.push(eNew);
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
|
-
if (s && bold && this.
|
|
141
|
+
if (s && bold && this.isInside('heading-title')) {
|
|
142
142
|
const e = (0, lint_1.generateForSelf)(this, rect, rules[1], 'bold-in-header', s);
|
|
143
143
|
if (computeEditInfo) {
|
|
144
144
|
e.suggestions = [(0, lint_1.fixByRemove)(e)];
|
|
@@ -175,7 +175,7 @@ let QuoteToken = (() => {
|
|
|
175
175
|
}
|
|
176
176
|
/** @private */
|
|
177
177
|
toHtmlInternal() {
|
|
178
|
-
const {
|
|
178
|
+
const { bold, italic } = this.closing;
|
|
179
179
|
return (bold ? '</b>' : '') + (italic ? '</i>' : '')
|
|
180
180
|
+ (italic === false ? '<i>' : '') + (bold === false ? '<b>' : '');
|
|
181
181
|
}
|
|
@@ -183,7 +183,7 @@ let QuoteToken = (() => {
|
|
|
183
183
|
* Find the matching apostrophes
|
|
184
184
|
*
|
|
185
185
|
* 搜索匹配的直引号
|
|
186
|
-
* @since v1.
|
|
186
|
+
* @since v1.30.0
|
|
187
187
|
* @param type type of apostrophes to match / 匹配的直引号类型
|
|
188
188
|
* @throws `RangeError` ambiguous or wrong apostrophe type
|
|
189
189
|
*/
|
package/dist/src/onlyinclude.js
CHANGED
|
@@ -99,7 +99,7 @@ let OnlyincludeToken = (() => {
|
|
|
99
99
|
}
|
|
100
100
|
/** @private */
|
|
101
101
|
print() {
|
|
102
|
-
return super.print({
|
|
102
|
+
PRINT: return super.print({
|
|
103
103
|
pre: '<span class="wpb-ext"><onlyinclude></span>',
|
|
104
104
|
post: '<span class="wpb-ext"></onlyinclude></span>',
|
|
105
105
|
});
|
package/dist/src/paramLine.js
CHANGED
|
@@ -37,6 +37,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
37
37
|
exports.ParamLineToken = void 0;
|
|
38
38
|
const index_1 = require("./index");
|
|
39
39
|
/* NOT FOR BROWSER */
|
|
40
|
+
const constants_1 = require("../util/constants");
|
|
40
41
|
const singleLine_1 = require("../mixin/singleLine");
|
|
41
42
|
const clone_1 = require("../mixin/clone");
|
|
42
43
|
/* NOT FOR BROWSER END */
|
|
@@ -81,3 +82,4 @@ let ParamLineToken = (() => {
|
|
|
81
82
|
return ParamLineToken = _classThis;
|
|
82
83
|
})();
|
|
83
84
|
exports.ParamLineToken = ParamLineToken;
|
|
85
|
+
constants_1.classes['ParamLineToken'] = __filename;
|
package/dist/src/parameter.js
CHANGED
|
@@ -203,7 +203,7 @@ let ParameterToken = (() => {
|
|
|
203
203
|
}
|
|
204
204
|
/** @private */
|
|
205
205
|
print() {
|
|
206
|
-
return super.print({ sep: this.anon ? '' : '=' });
|
|
206
|
+
PRINT: return super.print({ sep: this.anon ? '' : '=' });
|
|
207
207
|
}
|
|
208
208
|
/** @private */
|
|
209
209
|
json(_, start = this.getAbsoluteIndex()) {
|