wikiparser-node 1.15.0 → 1.15.1
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 +17 -1
- package/bundle/bundle.es7.js +24 -24
- package/bundle/bundle.min.js +24 -24
- package/config/.schema.json +14 -1
- package/config/enwiki.json +1 -814
- package/config/llwiki.json +2 -35
- package/config/minimum.json +2 -0
- package/config/moegirl.json +2 -44
- package/config/zhwiki.json +25 -489
- package/coverage/badge.svg +1 -0
- package/dist/addon/table.js +1 -1
- package/dist/addon/token.js +18 -14
- package/dist/addon/transclude.js +5 -1
- package/dist/index.js +13 -3
- package/dist/lib/element.js +4 -0
- package/dist/lib/node.js +8 -3
- package/dist/lib/range.js +13 -6
- package/dist/lib/ranges.js +5 -2
- package/dist/lib/text.js +7 -6
- package/dist/lib/title.js +1 -0
- package/dist/mixin/attributesParent.d.ts +1 -1
- package/dist/parser/braces.js +1 -0
- package/dist/parser/externalLinks.js +1 -1
- package/dist/parser/hrAndDoubleUnderscore.js +1 -1
- package/dist/parser/magicLinks.js +1 -1
- package/dist/parser/selector.js +10 -2
- package/dist/src/atom.js +1 -0
- package/dist/src/attribute.d.ts +6 -4
- package/dist/src/attributes.js +3 -4
- package/dist/src/link/base.js +1 -0
- package/dist/src/link/file.js +3 -0
- package/dist/src/link/index.js +5 -6
- package/dist/src/link/redirectTarget.d.ts +2 -3
- package/dist/src/link/redirectTarget.js +1 -2
- package/dist/src/nowiki/comment.js +1 -0
- package/dist/src/onlyinclude.js +1 -0
- package/dist/src/table/index.d.ts +0 -3
- package/dist/src/table/index.js +2 -1
- package/dist/src/table/trBase.js +3 -2
- package/dist/util/debug.js +10 -2
- package/dist/util/diff.js +5 -0
- package/dist/util/string.js +12 -1
- package/extensions/dist/base.js +1 -1
- package/extensions/dist/test-page.js +89 -0
- package/extensions/es7/base.js +1 -1
- package/package.json +12 -6
package/dist/src/attribute.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Token } from './index';
|
|
|
3
3
|
import { AtomToken } from './atom';
|
|
4
4
|
import type { LintError } from '../base';
|
|
5
5
|
import type { AttributesToken } from '../internal';
|
|
6
|
+
declare type Child = AtomToken | AttributeToken | undefined;
|
|
6
7
|
export type AttributeTypes = 'ext-attr' | 'html-attr' | 'table-attr';
|
|
7
8
|
/**
|
|
8
9
|
* 扩展和HTML标签属性
|
|
@@ -15,14 +16,14 @@ export declare abstract class AttributeToken extends Token {
|
|
|
15
16
|
abstract get firstChild(): AtomToken;
|
|
16
17
|
abstract get lastChild(): Token;
|
|
17
18
|
abstract get parentNode(): AttributesToken | undefined;
|
|
18
|
-
abstract get nextSibling():
|
|
19
|
-
abstract get previousSibling():
|
|
19
|
+
abstract get nextSibling(): Child;
|
|
20
|
+
abstract get previousSibling(): Child;
|
|
20
21
|
abstract get children(): [AtomToken, Token];
|
|
21
22
|
abstract get firstElementChild(): AtomToken;
|
|
22
23
|
abstract get lastElementChild(): Token;
|
|
23
24
|
abstract get parentElement(): AttributesToken | undefined;
|
|
24
|
-
abstract get nextElementSibling():
|
|
25
|
-
abstract get previousElementSibling():
|
|
25
|
+
abstract get nextElementSibling(): Child;
|
|
26
|
+
abstract get previousElementSibling(): Child;
|
|
26
27
|
get type(): AttributeTypes;
|
|
27
28
|
/** 标签名 */
|
|
28
29
|
get tag(): string;
|
|
@@ -62,3 +63,4 @@ export declare abstract class AttributeToken extends Token {
|
|
|
62
63
|
*/
|
|
63
64
|
rename(key: string): void;
|
|
64
65
|
}
|
|
66
|
+
export {};
|
package/dist/src/attributes.js
CHANGED
|
@@ -28,7 +28,7 @@ try {
|
|
|
28
28
|
// eslint-disable-next-line prefer-regex-literals, es-x/no-regexp-unicode-property-escapes
|
|
29
29
|
wordRegex = new RegExp(String.raw `[\p{L}\d]`, 'u');
|
|
30
30
|
}
|
|
31
|
-
catch {
|
|
31
|
+
catch /* istanbul ignore next */ {
|
|
32
32
|
wordRegex = /[^\W_]/u;
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
@@ -388,9 +388,8 @@ class AttributesToken extends index_2.Token {
|
|
|
388
388
|
}
|
|
389
389
|
/** @private */
|
|
390
390
|
toHtmlInternal() {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
], ' ')}`;
|
|
391
|
+
const map = new Map(this.childNodes.filter(child => child instanceof attribute_1.AttributeToken).map(child => [child.name, child]));
|
|
392
|
+
return map.size === 0 ? '' : ` ${(0, html_1.html)([...map.values()], ' ')}`;
|
|
394
393
|
}
|
|
395
394
|
}
|
|
396
395
|
exports.AttributesToken = AttributesToken;
|
package/dist/src/link/base.js
CHANGED
|
@@ -48,6 +48,7 @@ class LinkBaseToken extends index_2.Token {
|
|
|
48
48
|
set interwiki(interwiki) {
|
|
49
49
|
if (isLink(this.type)) {
|
|
50
50
|
const { prefix, main, fragment } = this.#title, link = `${interwiki}:${prefix}${main}${fragment === undefined ? '' : `#${fragment}`}`;
|
|
51
|
+
/* istanbul ignore if */
|
|
51
52
|
if (interwiki && !this.isInterwiki(link)) {
|
|
52
53
|
throw new RangeError(`${interwiki} is not a valid interwiki prefix!`);
|
|
53
54
|
}
|
package/dist/src/link/file.js
CHANGED
|
@@ -286,10 +286,12 @@ class FileToken extends base_1.LinkBaseToken {
|
|
|
286
286
|
return;
|
|
287
287
|
}
|
|
288
288
|
const config = this.getAttribute('config'), syntax = key === 'caption' ? '$1' : Object.entries(config.img).find(([, name]) => name === key)?.[0];
|
|
289
|
+
/* istanbul ignore if */
|
|
289
290
|
if (syntax === undefined) {
|
|
290
291
|
throw new RangeError(`Unknown image parameter: ${key}`);
|
|
291
292
|
}
|
|
292
293
|
const free = syntax.includes('$1');
|
|
294
|
+
/* istanbul ignore if */
|
|
293
295
|
if (value === true && free) {
|
|
294
296
|
this.typeError('setValue', 'String');
|
|
295
297
|
}
|
|
@@ -303,6 +305,7 @@ class FileToken extends base_1.LinkBaseToken {
|
|
|
303
305
|
parameter.afterBuild();
|
|
304
306
|
this.insertAt(parameter);
|
|
305
307
|
}
|
|
308
|
+
/* istanbul ignore next */
|
|
306
309
|
/**
|
|
307
310
|
* @override
|
|
308
311
|
* @throws `Error` 不适用于图片
|
package/dist/src/link/index.js
CHANGED
|
@@ -52,6 +52,7 @@ class LinkToken extends base_1.LinkBaseToken {
|
|
|
52
52
|
*/
|
|
53
53
|
setLangLink(lang, link) {
|
|
54
54
|
link = link.trim();
|
|
55
|
+
/* istanbul ignore if */
|
|
55
56
|
if (link.startsWith('#')) {
|
|
56
57
|
throw new SyntaxError('An interlanguage link cannot be fragment only!');
|
|
57
58
|
}
|
|
@@ -63,6 +64,7 @@ class LinkToken extends base_1.LinkBaseToken {
|
|
|
63
64
|
* @throws `RangeError` 空的片段标识符
|
|
64
65
|
*/
|
|
65
66
|
asSelfLink(fragment = this.fragment) {
|
|
67
|
+
/* istanbul ignore if */
|
|
66
68
|
if (!fragment?.trim()) {
|
|
67
69
|
throw new RangeError('LinkToken.asSelfLink method must specify a non-empty fragment!');
|
|
68
70
|
}
|
|
@@ -74,6 +76,7 @@ class LinkToken extends base_1.LinkBaseToken {
|
|
|
74
76
|
*/
|
|
75
77
|
pipeTrick() {
|
|
76
78
|
const linkText = this.firstChild.text();
|
|
79
|
+
/* istanbul ignore if */
|
|
77
80
|
if (linkText.includes('#') || linkText.includes('%')) {
|
|
78
81
|
throw new Error('Pipe trick cannot be used with "#" or "%"!');
|
|
79
82
|
}
|
|
@@ -87,13 +90,9 @@ class LinkToken extends base_1.LinkBaseToken {
|
|
|
87
90
|
this.setLinkText(m2[1]);
|
|
88
91
|
return;
|
|
89
92
|
}
|
|
90
|
-
const m3 = /^:?(?:[ \w\x80-\xFF-]+:)?(
|
|
93
|
+
const m3 = /^:?(?:[ \w\x80-\xFF-]+:)?(.*?)(?: ?(?<!\()\(.+\))?(?:(?:, |,|، ).|$)/u
|
|
91
94
|
.exec(linkText);
|
|
92
|
-
|
|
93
|
-
this.setLinkText(m3[1]);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
this.setLinkText(linkText);
|
|
95
|
+
this.setLinkText(m3[1]);
|
|
97
96
|
}
|
|
98
97
|
}
|
|
99
98
|
exports.LinkToken = LinkToken;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import Parser from '../../index';
|
|
2
1
|
import { LinkBaseToken } from './base';
|
|
3
2
|
import { NoincludeToken } from '../nowiki/noinclude';
|
|
4
|
-
import type { LintError } from '../../base';
|
|
3
|
+
import type { LintError, Config } from '../../base';
|
|
5
4
|
import type { Title } from '../../lib/title';
|
|
6
5
|
import type { Token, AtomToken } from '../../internal';
|
|
7
6
|
/**
|
|
@@ -23,5 +22,5 @@ export declare abstract class RedirectTargetToken extends LinkBaseToken {
|
|
|
23
22
|
* @param linkText 链接显示文字
|
|
24
23
|
* @param delimiter `|`
|
|
25
24
|
*/
|
|
26
|
-
constructor(link: string, linkText?: string, config?:
|
|
25
|
+
constructor(link: string, linkText?: string, config?: Config, accum?: Token[]);
|
|
27
26
|
}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RedirectTargetToken = void 0;
|
|
4
4
|
const lint_1 = require("../../util/lint");
|
|
5
|
-
const index_1 = require("../../index");
|
|
6
5
|
const base_1 = require("./base");
|
|
7
6
|
const noinclude_1 = require("../nowiki/noinclude");
|
|
8
7
|
/* NOT FOR BROWSER */
|
|
@@ -28,7 +27,7 @@ class RedirectTargetToken extends base_1.LinkBaseToken {
|
|
|
28
27
|
* @param linkText 链接显示文字
|
|
29
28
|
* @param delimiter `|`
|
|
30
29
|
*/
|
|
31
|
-
constructor(link, linkText, config
|
|
30
|
+
constructor(link, linkText, config, accum) {
|
|
32
31
|
super(link, undefined, config, accum);
|
|
33
32
|
if (linkText !== undefined) {
|
|
34
33
|
// @ts-expect-error abstract class
|
package/dist/src/onlyinclude.js
CHANGED
|
@@ -22,6 +22,7 @@ class OnlyincludeToken extends index_1.Token {
|
|
|
22
22
|
}
|
|
23
23
|
/** @throws `RangeError` 不允许包含`</onlyinclude>` */
|
|
24
24
|
set innerText(text) {
|
|
25
|
+
/* istanbul ignore if */
|
|
25
26
|
if (text.includes('</onlyinclude>')) {
|
|
26
27
|
throw new RangeError('"</onlyinclude>" is not allowed in the text!');
|
|
27
28
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { TrBaseToken } from './trBase';
|
|
2
2
|
import { SyntaxToken } from '../syntax';
|
|
3
3
|
import type { Config, LintError, AST } from '../../base';
|
|
4
|
-
import type { SyntaxBase } from '../../mixin/syntax';
|
|
5
4
|
import type { AttributesToken, TdToken, TrToken, Token } from '../../internal';
|
|
6
5
|
import type { TableCoords } from './trBase';
|
|
7
6
|
import type { TdAttrs, TdSubtypes, TdSpanAttrs } from './td';
|
|
@@ -11,8 +10,6 @@ export interface TableRenderedCoords {
|
|
|
11
10
|
readonly x: number;
|
|
12
11
|
readonly y: number;
|
|
13
12
|
}
|
|
14
|
-
export interface TableToken extends SyntaxBase {
|
|
15
|
-
}
|
|
16
13
|
export type TableTokens = TableToken | TrToken | TdToken;
|
|
17
14
|
/**
|
|
18
15
|
* 是否是行尾
|
package/dist/src/table/index.js
CHANGED
|
@@ -211,7 +211,7 @@ class TableToken extends trBase_1.TrBaseToken {
|
|
|
211
211
|
return this;
|
|
212
212
|
/* NOT FOR BROWSER */
|
|
213
213
|
}
|
|
214
|
-
else if (n < 0 || n > nRows || n === nRows && !insert) {
|
|
214
|
+
else /* istanbul ignore if */ if (n < 0 || n > nRows || n === nRows && !insert) {
|
|
215
215
|
throw new RangeError(`The table does not have row ${n}!`);
|
|
216
216
|
/* NOT FOR BROWSER END */
|
|
217
217
|
}
|
|
@@ -249,6 +249,7 @@ class TableToken extends trBase_1.TrBaseToken {
|
|
|
249
249
|
insertAt(token, i = this.length) {
|
|
250
250
|
i += i < 0 ? this.length : 0;
|
|
251
251
|
const previous = this.childNodes[i - 1];
|
|
252
|
+
/* istanbul ignore else */
|
|
252
253
|
if (typeof token !== 'string' && token.type === 'td' && previous?.type === 'tr') {
|
|
253
254
|
index_1.default.warn('The table cell is inserted into the current row instead.');
|
|
254
255
|
return previous.insertAt(token);
|
package/dist/src/table/trBase.js
CHANGED
|
@@ -8,7 +8,6 @@ const td_1 = require("./td");
|
|
|
8
8
|
const debug_1 = require("../../util/debug");
|
|
9
9
|
const constants_1 = require("../../util/constants");
|
|
10
10
|
const html_1 = require("../../util/html");
|
|
11
|
-
const debug_2 = require("../../util/debug");
|
|
12
11
|
const index_1 = require("../index");
|
|
13
12
|
/** 表格行或表格 */
|
|
14
13
|
class TrBaseToken extends base_1.TableBaseToken {
|
|
@@ -48,6 +47,7 @@ class TrBaseToken extends base_1.TableBaseToken {
|
|
|
48
47
|
/* NOT FOR BROWSER */
|
|
49
48
|
const nCols = this.getColCount();
|
|
50
49
|
n += n < 0 ? nCols : 0;
|
|
50
|
+
/* istanbul ignore if */
|
|
51
51
|
if (n < 0 || n > nCols || n === nCols && !insert) {
|
|
52
52
|
throw new RangeError(`There is no cell at position ${n}!`);
|
|
53
53
|
}
|
|
@@ -117,6 +117,7 @@ class TrBaseToken extends base_1.TableBaseToken {
|
|
|
117
117
|
*/
|
|
118
118
|
insertAt(token, i = this.length) {
|
|
119
119
|
if (!debug_1.Shadow.running && token.type !== 'td') {
|
|
120
|
+
/* istanbul ignore next */
|
|
120
121
|
if (this.type === 'tr') {
|
|
121
122
|
this.typeError('insertAt', 'TdToken');
|
|
122
123
|
}
|
|
@@ -155,7 +156,7 @@ class TrBaseToken extends base_1.TableBaseToken {
|
|
|
155
156
|
}
|
|
156
157
|
/** @private */
|
|
157
158
|
toHtmlInternal(opt) {
|
|
158
|
-
const { childNodes, type } = this, td = childNodes.filter((0,
|
|
159
|
+
const { childNodes, type } = this, td = childNodes.filter((0, debug_1.isToken)('td'));
|
|
159
160
|
return td.some(({ subtype }) => subtype !== 'caption')
|
|
160
161
|
? `<tr${type === 'tr' ? childNodes[1].toHtmlInternal() : ''}>${(0, html_1.html)(td, '', opt)}</tr>`
|
|
161
162
|
: (0, html_1.html)(td, '', opt);
|
package/dist/util/debug.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.undo = exports.mixin = exports.emptyArray = exports.setChildNodes = exports.isToken = exports.Shadow = void 0;
|
|
3
|
+
exports.undo = exports.compare = exports.mixin = exports.emptyArray = exports.setChildNodes = exports.isToken = exports.Shadow = void 0;
|
|
4
4
|
exports.Shadow = {
|
|
5
5
|
running: false,
|
|
6
6
|
/** @private */
|
|
@@ -16,7 +16,7 @@ exports.Shadow = {
|
|
|
16
16
|
this.running = running;
|
|
17
17
|
return result;
|
|
18
18
|
}
|
|
19
|
-
catch (e) {
|
|
19
|
+
catch (e) /* istanbul ignore next */ {
|
|
20
20
|
this.running = running;
|
|
21
21
|
throw e;
|
|
22
22
|
}
|
|
@@ -67,6 +67,13 @@ const mixin = (target, source) => {
|
|
|
67
67
|
};
|
|
68
68
|
exports.mixin = mixin;
|
|
69
69
|
/* NOT FOR BROWSER */
|
|
70
|
+
/**
|
|
71
|
+
* 比较两个数
|
|
72
|
+
* @param a
|
|
73
|
+
* @param b
|
|
74
|
+
*/
|
|
75
|
+
const compare = (a, b) => a - b;
|
|
76
|
+
exports.compare = compare;
|
|
70
77
|
/**
|
|
71
78
|
* 撤销最近一次Mutation
|
|
72
79
|
* @param e 事件
|
|
@@ -88,6 +95,7 @@ const undo = (e, data) => {
|
|
|
88
95
|
case 'text':
|
|
89
96
|
target.replaceData(data.oldText);
|
|
90
97
|
break;
|
|
98
|
+
/* istanbul ignore next */
|
|
91
99
|
default:
|
|
92
100
|
throw new RangeError(`Unable to undo events with an unknown type: ${type}`);
|
|
93
101
|
}
|
package/dist/util/diff.js
CHANGED
|
@@ -4,9 +4,11 @@ exports.info = exports.error = exports.diff = exports.cmd = void 0;
|
|
|
4
4
|
const fs = require("fs/promises");
|
|
5
5
|
const child_process_1 = require("child_process");
|
|
6
6
|
const chalk = require("chalk");
|
|
7
|
+
/* istanbul ignore next */
|
|
7
8
|
process.on('unhandledRejection', e => {
|
|
8
9
|
console.error(e);
|
|
9
10
|
});
|
|
11
|
+
/* istanbul ignore next */
|
|
10
12
|
/**
|
|
11
13
|
* 将shell命令转化为Promise对象
|
|
12
14
|
* @param command shell指令
|
|
@@ -47,6 +49,7 @@ const cmd = (command, args) => new Promise(resolve => {
|
|
|
47
49
|
}
|
|
48
50
|
});
|
|
49
51
|
exports.cmd = cmd;
|
|
52
|
+
/* istanbul ignore next */
|
|
50
53
|
/**
|
|
51
54
|
* 比较两个文件
|
|
52
55
|
* @param oldStr 旧文本
|
|
@@ -71,11 +74,13 @@ const diff = async (oldStr, newStr, uid) => {
|
|
|
71
74
|
await Promise.all([fs.unlink(oldFile), fs.unlink(newFile)]);
|
|
72
75
|
};
|
|
73
76
|
exports.diff = diff;
|
|
77
|
+
/* istanbul ignore next */
|
|
74
78
|
/** @implements */
|
|
75
79
|
const error = (msg, ...args) => {
|
|
76
80
|
console.error(chalk.red(msg), ...args);
|
|
77
81
|
};
|
|
78
82
|
exports.error = error;
|
|
83
|
+
/* istanbul ignore next */
|
|
79
84
|
/** @implements */
|
|
80
85
|
const info = (msg, ...args) => {
|
|
81
86
|
console.info(chalk.green(msg), ...args);
|
package/dist/util/string.js
CHANGED
|
@@ -27,10 +27,21 @@ exports.escapeRegExp = factory(/[\\{}()|.?*+^$[\]]/gu, String.raw `\$&`);
|
|
|
27
27
|
const text = (childNodes, separator = '') => childNodes.map(child => typeof child === 'string' ? child : child.text()).join(separator);
|
|
28
28
|
exports.text = text;
|
|
29
29
|
const names = { lt: '<', gt: '>', lbrack: '[', rbrack: ']', lbrace: '{', rbrace: '}', nbsp: ' ', amp: '&', quot: '"' };
|
|
30
|
+
/* istanbul ignore next */
|
|
30
31
|
/** decode HTML entities */
|
|
31
|
-
|
|
32
|
+
const decodeHtmlBasic = factory(/&(?:#(\d+|[Xx][\da-fA-F]+)|([lg]t|[LG]T|[lr]brac[ke]|nbsp|amp|AMP|quot|QUOT));/gu, (_, code, name) => code
|
|
32
33
|
? String.fromCodePoint(Number((/^x/iu.test(code) ? '0' : '') + code))
|
|
33
34
|
: names[name.toLowerCase()]);
|
|
35
|
+
/**
|
|
36
|
+
* decode HTML entities
|
|
37
|
+
* @param str
|
|
38
|
+
*/
|
|
39
|
+
const decodeHtml = (str) =>
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
41
|
+
typeof process === 'object' && typeof process.versions?.node === 'string'
|
|
42
|
+
? require('entities').decodeHTMLStrict(str).replace(/\xA0/gu, ' ')
|
|
43
|
+
: /* istanbul ignore next */ decodeHtmlBasic(str);
|
|
44
|
+
exports.decodeHtml = decodeHtml;
|
|
34
45
|
/** decode numbered HTML entities */
|
|
35
46
|
exports.decodeNumber = factory(/&#(\d+|x[\da-f]+);/giu, (_, code) => String.fromCodePoint(Number((/^x/iu.test(code) ? '0' : '') + code)));
|
|
36
47
|
/** escape newlines */
|
package/extensions/dist/base.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
var _a;
|
|
3
|
-
const version = '1.15.
|
|
3
|
+
const version = '1.15.1', src = (_a = document.currentScript) === null || _a === void 0 ? void 0 : _a.src, file = /\/extensions\/dist\/base\.(?:min\.)?js$/u, CDN = src && file.test(src)
|
|
4
4
|
? src.replace(file, '')
|
|
5
5
|
: `https://testingcf.jsdelivr.net/npm/wikiparser-node@${version}`;
|
|
6
6
|
const workerJS = () => {
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
"use strict";
|
|
3
|
+
(async () => {
|
|
4
|
+
const tests = await (await fetch('./test/parserTests.json')).json(), key = 'wikiparser-node-done', dones = new Set(JSON.parse(localStorage.getItem(key))), isGH = location.hostname.endsWith('.github.io'), isIframe = self !== top, select = document.querySelector('select'), btn = document.querySelector('button'), pre = document.querySelector('pre'), container = document.getElementById('frame'), container1 = document.getElementById('frame1'), container2 = document.getElementById('frame2');
|
|
5
|
+
Parser.config = await (await fetch('./config/default.json')).json();
|
|
6
|
+
wikiparse.print = (wikitext, include, stage) => {
|
|
7
|
+
const printed = Parser.parse(wikitext, include, stage).print();
|
|
8
|
+
return Promise.resolve([[stage !== null && stage !== void 0 ? stage : Infinity, wikitext, printed]]);
|
|
9
|
+
};
|
|
10
|
+
wikiparse.highlight(pre, false, true);
|
|
11
|
+
btn.disabled = !select.value;
|
|
12
|
+
if (!isGH) {
|
|
13
|
+
btn.style.display = '';
|
|
14
|
+
}
|
|
15
|
+
let optgroup;
|
|
16
|
+
for (const [i, { desc, wikitext, html }] of tests.entries()) {
|
|
17
|
+
if (wikitext === undefined) {
|
|
18
|
+
optgroup = document.createElement('optgroup');
|
|
19
|
+
optgroup.label = desc;
|
|
20
|
+
select.append(optgroup);
|
|
21
|
+
}
|
|
22
|
+
else if ((isIframe || html !== undefined) && (isGH || !dones.has(desc))) {
|
|
23
|
+
const option = document.createElement('option');
|
|
24
|
+
option.value = String(i);
|
|
25
|
+
option.textContent = desc;
|
|
26
|
+
optgroup.append(option);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
select.addEventListener('change', () => {
|
|
30
|
+
const { wikitext, html, render, desc } = tests[Number(select.value)];
|
|
31
|
+
pre.textContent = wikitext;
|
|
32
|
+
pre.classList.remove('wikiparser');
|
|
33
|
+
container.removeAttribute('data-source');
|
|
34
|
+
if (html === undefined) {
|
|
35
|
+
container.style.display = 'none';
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
container.style.display = '';
|
|
39
|
+
container1.innerHTML = html;
|
|
40
|
+
container2.innerHTML = render !== null && render !== void 0 ? render : '';
|
|
41
|
+
}
|
|
42
|
+
wikiparse.highlight(pre, false, true);
|
|
43
|
+
select.selectedOptions[0].disabled = true;
|
|
44
|
+
btn.disabled = false;
|
|
45
|
+
history.replaceState(null, '', `#${encodeURIComponent(desc)}`);
|
|
46
|
+
dispatchEvent(new Event('casechange'));
|
|
47
|
+
});
|
|
48
|
+
btn.addEventListener('click', () => {
|
|
49
|
+
dones.add(tests[Number(select.value)].desc);
|
|
50
|
+
localStorage.setItem(key, JSON.stringify([...dones]));
|
|
51
|
+
while (select.selectedOptions[0].disabled) {
|
|
52
|
+
select.selectedIndex++;
|
|
53
|
+
}
|
|
54
|
+
select.dispatchEvent(new Event('change'));
|
|
55
|
+
});
|
|
56
|
+
container.addEventListener('click', e => {
|
|
57
|
+
e.preventDefault();
|
|
58
|
+
}, { capture: true });
|
|
59
|
+
container.addEventListener('dblclick', e => {
|
|
60
|
+
e.preventDefault();
|
|
61
|
+
if (container.dataset['source']) {
|
|
62
|
+
container.removeAttribute('data-source');
|
|
63
|
+
container1.innerHTML = container1.textContent;
|
|
64
|
+
container2.innerHTML = container2.textContent;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
container.dataset['source'] = '1';
|
|
68
|
+
const pre1 = document.createElement('pre'), pre2 = document.createElement('pre'), code1 = document.createElement('code'), code2 = document.createElement('code');
|
|
69
|
+
code1.textContent = container1.innerHTML;
|
|
70
|
+
code2.textContent = container2.innerHTML;
|
|
71
|
+
pre1.className = 'language-html';
|
|
72
|
+
pre2.className = 'language-html';
|
|
73
|
+
pre1.append(code1);
|
|
74
|
+
pre2.append(code2);
|
|
75
|
+
container1.replaceChildren(pre1);
|
|
76
|
+
container2.replaceChildren(pre2);
|
|
77
|
+
Prism.highlightAllUnder(container);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
addEventListener('hashchange', () => {
|
|
81
|
+
const hash = decodeURIComponent(location.hash.slice(1)), i = tests.findIndex(({ desc }) => desc === hash);
|
|
82
|
+
if (i !== -1) {
|
|
83
|
+
select.value = String(i);
|
|
84
|
+
select.dispatchEvent(new Event('change'));
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
dispatchEvent(new Event('hashchange'));
|
|
88
|
+
})();
|
|
89
|
+
})();
|
package/extensions/es7/base.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
var _a;
|
|
3
|
-
const version = '1.15.
|
|
3
|
+
const version = '1.15.1', src = (_a = document.currentScript) === null || _a === void 0 ? void 0 : _a.src, file = /\/extensions\/dist\/base\.(?:min\.)?js$/u, CDN = src && file.test(src)
|
|
4
4
|
? src.replace(file, '')
|
|
5
5
|
: `https://testingcf.jsdelivr.net/npm/wikiparser-node@${version}`;
|
|
6
6
|
const workerJS = () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wikiparser-node",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.1",
|
|
4
4
|
"description": "A Node.js parser for MediaWiki markup with AST",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mediawiki",
|
|
@@ -24,8 +24,11 @@
|
|
|
24
24
|
"!/extensions/gh-page.css",
|
|
25
25
|
"!/extensions/dist/parserTests.js",
|
|
26
26
|
"!/extensions/test-page.css",
|
|
27
|
+
"!/extensions/dist/compare.js",
|
|
28
|
+
"!/extensions/compare.css",
|
|
27
29
|
"/config/",
|
|
28
30
|
"/i18n/",
|
|
31
|
+
"/coverage/badge.svg",
|
|
29
32
|
"/dist/",
|
|
30
33
|
"!/dist/[bt]*/"
|
|
31
34
|
],
|
|
@@ -37,17 +40,18 @@
|
|
|
37
40
|
"url": "git+https://github.com/bhsd-harry/wikiparser-node.git"
|
|
38
41
|
},
|
|
39
42
|
"scripts": {
|
|
40
|
-
"toc": "node
|
|
41
|
-
"declaration": "grep -rl --include='*.d.ts' '@private' dist/ | xargs bash sed.sh -i -E '/^\\s+\\/\\*\\* @private/,+1d'; grep -rl --include='*.d.ts' '/util/' dist/ | xargs bash sed.sh -i -E '/^import .+\\/util\\//d'; bash sed.sh -i -E 's/abstract (lint|print|text)\\b/\\1/' dist/lib/node.d.ts; node
|
|
43
|
+
"toc": "node dist/bin/toc.js",
|
|
44
|
+
"declaration": "grep -rl --include='*.d.ts' '@private' dist/ | xargs bash sed.sh -i -E '/^\\s+\\/\\*\\* @private/,+1d'; grep -rl --include='*.d.ts' '/util/' dist/ | xargs bash sed.sh -i -E '/^import .+\\/util\\//d'; bash sed.sh -i -E 's/abstract (lint|print|text)\\b/\\1/' dist/lib/node.d.ts; node dist/bin/declaration.js",
|
|
42
45
|
"prepublishOnly": "npm run build:core",
|
|
43
46
|
"build:core": "bash build.sh",
|
|
44
|
-
"build": "npm run build:core && node
|
|
47
|
+
"build": "npm run build:core && node dist/bin/parserTests.js",
|
|
45
48
|
"diff": "bash diff.sh",
|
|
46
49
|
"diff:stat": "f() { git diff --stat --ignore-all-space --color=always $1 $2 -- . ':!extensions/' ':!bin/' | grep '\\.ts'; }; f",
|
|
47
50
|
"lint:ts": "tsc --noEmit && eslint --cache .",
|
|
48
|
-
"lint:json": "v8r -s config/.schema.json config/*.json && node
|
|
51
|
+
"lint:json": "v8r -s config/.schema.json config/*.json && node dist/test/json.js",
|
|
49
52
|
"lint": "npm run lint:ts && npm run lint:json",
|
|
50
53
|
"prof": "node dist/test/prof.js",
|
|
54
|
+
"coverage": "nyc --reporter=html --reporter=text-summary --reporter=json-summary --cache-dir=./.cache/nyc npm test && node dist/bin/coverage.js && open coverage/index.html",
|
|
51
55
|
"test:unit": "mocha dist/test/test.js",
|
|
52
56
|
"test:parser": "mocha dist/test/parserTests.js",
|
|
53
57
|
"test": "npm run test:unit && npm run test:parser",
|
|
@@ -55,10 +59,11 @@
|
|
|
55
59
|
"test:real": "node dist/test/real.js"
|
|
56
60
|
},
|
|
57
61
|
"dependencies": {
|
|
58
|
-
"@bhsd/common": "^0.
|
|
62
|
+
"@bhsd/common": "^0.6.3",
|
|
59
63
|
"@codemirror/lint": "^6.8.4",
|
|
60
64
|
"chalk": "^4.1.2",
|
|
61
65
|
"codejar-async": "^4.2.6",
|
|
66
|
+
"entities": "^6.0.0",
|
|
62
67
|
"monaco-editor": "^0.52.0"
|
|
63
68
|
},
|
|
64
69
|
"devDependencies": {
|
|
@@ -81,6 +86,7 @@
|
|
|
81
86
|
"eslint-plugin-unicorn": "^56.0.1",
|
|
82
87
|
"http-server": "^14.1.0",
|
|
83
88
|
"mocha": "^10.8.2",
|
|
89
|
+
"nyc": "^17.1.0",
|
|
84
90
|
"stylelint": "^16.11.0",
|
|
85
91
|
"stylelint-config-recommended": "^14.0.0",
|
|
86
92
|
"typescript": "^5.7.2",
|