wikilint 2.11.1 → 2.12.2
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/config/.schema.json +24 -7
- package/config/default.json +30 -29
- package/config/enwiki.json +15 -14
- package/config/llwiki.json +21 -20
- package/config/moegirl.json +21 -20
- package/config/zhwiki.json +28 -27
- package/dist/base.d.ts +1 -1
- package/dist/index.js +16 -1
- package/dist/lib/text.js +1 -0
- package/dist/lib/title.d.ts +6 -2
- package/dist/lib/title.js +30 -13
- package/dist/parser/braces.js +4 -4
- package/dist/parser/commentAndExt.js +6 -3
- package/dist/parser/converter.js +1 -1
- package/dist/parser/hrAndDoubleUnderscore.js +6 -6
- package/dist/parser/list.js +1 -1
- package/dist/parser/redirect.js +1 -1
- package/dist/parser/table.js +1 -1
- package/dist/src/arg.js +4 -4
- package/dist/src/attribute.js +2 -2
- package/dist/src/attributes.d.ts +2 -1
- package/dist/src/attributes.js +4 -5
- package/dist/src/converterFlags.js +3 -3
- package/dist/src/extLink.js +1 -1
- package/dist/src/gallery.js +2 -2
- package/dist/src/heading.d.ts +2 -0
- package/dist/src/heading.js +2 -2
- package/dist/src/html.js +1 -1
- package/dist/src/imagemap.js +1 -1
- package/dist/src/imagemapLink.d.ts +3 -1
- package/dist/src/index.js +5 -3
- package/dist/src/magicLink.js +7 -5
- package/dist/src/nested.js +2 -2
- package/dist/src/nowiki/doubleUnderscore.d.ts +2 -2
- package/dist/src/nowiki/doubleUnderscore.js +2 -1
- package/dist/src/parameter.js +2 -1
- package/dist/src/pre.js +1 -1
- package/dist/src/table/index.js +2 -3
- package/dist/src/table/td.js +1 -1
- package/dist/src/tagPair/ext.js +18 -24
- package/dist/src/transclude.js +4 -5
- package/dist/util/string.js +7 -7
- package/package.json +2 -2
package/config/.schema.json
CHANGED
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"parserFunction": {
|
|
47
47
|
"type": "array",
|
|
48
|
-
"
|
|
48
|
+
"prefixItems": [
|
|
49
49
|
{
|
|
50
50
|
"description": "case-insensitive parser functions",
|
|
51
51
|
"type": "object",
|
|
@@ -93,14 +93,31 @@
|
|
|
93
93
|
"doubleUnderscore": {
|
|
94
94
|
"description": "behavior switches",
|
|
95
95
|
"type": "array",
|
|
96
|
-
"
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
"type": "
|
|
96
|
+
"prefixItems": [
|
|
97
|
+
{
|
|
98
|
+
"description": "case-insensitive behavior switches",
|
|
99
|
+
"type": "array",
|
|
100
|
+
"items": {
|
|
101
|
+
"type": "string"
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"description": "case-sensitive behavior switches",
|
|
106
|
+
"type": "array",
|
|
107
|
+
"items": {
|
|
108
|
+
"type": "string"
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"description": "case-insensitive behavior switches",
|
|
113
|
+
"type": "object",
|
|
114
|
+
"additionalProperties": {
|
|
115
|
+
"type": "string"
|
|
116
|
+
}
|
|
100
117
|
}
|
|
101
|
-
|
|
118
|
+
],
|
|
102
119
|
"minItems": 2,
|
|
103
|
-
"maxItems":
|
|
120
|
+
"maxItems": 3
|
|
104
121
|
},
|
|
105
122
|
"protocol": {
|
|
106
123
|
"description": "external link protocols",
|
package/config/default.json
CHANGED
|
@@ -717,34 +717,7 @@
|
|
|
717
717
|
]
|
|
718
718
|
],
|
|
719
719
|
"doubleUnderscore": [
|
|
720
|
-
[
|
|
721
|
-
"forcetoc",
|
|
722
|
-
"强显目录",
|
|
723
|
-
"強制目錄",
|
|
724
|
-
"nocc",
|
|
725
|
-
"nocontentconvert",
|
|
726
|
-
"不转换内容",
|
|
727
|
-
"不轉換內容",
|
|
728
|
-
"noeditsection",
|
|
729
|
-
"无段落编辑",
|
|
730
|
-
"无编辑段落",
|
|
731
|
-
"無段落編輯",
|
|
732
|
-
"nogallery",
|
|
733
|
-
"无图库",
|
|
734
|
-
"無圖庫",
|
|
735
|
-
"notc",
|
|
736
|
-
"notitleconvert",
|
|
737
|
-
"不转换标题",
|
|
738
|
-
"不轉換標題",
|
|
739
|
-
"notoc",
|
|
740
|
-
"无目录",
|
|
741
|
-
"無目錄",
|
|
742
|
-
"toc",
|
|
743
|
-
"目录",
|
|
744
|
-
"目錄",
|
|
745
|
-
"archivedtalk",
|
|
746
|
-
"notalk"
|
|
747
|
-
],
|
|
720
|
+
[],
|
|
748
721
|
[
|
|
749
722
|
"EXPECTUNUSEDCATEGORY",
|
|
750
723
|
"DISAMBIG",
|
|
@@ -765,7 +738,35 @@
|
|
|
765
738
|
"靜態重新導向",
|
|
766
739
|
"NOGLOBAL",
|
|
767
740
|
"EXPECTED_UNCONNECTED_PAGE"
|
|
768
|
-
]
|
|
741
|
+
],
|
|
742
|
+
{
|
|
743
|
+
"forcetoc": "forcetoc",
|
|
744
|
+
"强显目录": "forcetoc",
|
|
745
|
+
"強制目錄": "forcetoc",
|
|
746
|
+
"nocc": "nocontentconvert",
|
|
747
|
+
"nocontentconvert": "nocontentconvert",
|
|
748
|
+
"不转换内容": "nocontentconvert",
|
|
749
|
+
"不轉換內容": "nocontentconvert",
|
|
750
|
+
"noeditsection": "noeditsection",
|
|
751
|
+
"无段落编辑": "noeditsection",
|
|
752
|
+
"无编辑段落": "noeditsection",
|
|
753
|
+
"無段落編輯": "noeditsection",
|
|
754
|
+
"nogallery": "nogallery",
|
|
755
|
+
"无图库": "nogallery",
|
|
756
|
+
"無圖庫": "nogallery",
|
|
757
|
+
"notc": "notitleconvert",
|
|
758
|
+
"notitleconvert": "notitleconvert",
|
|
759
|
+
"不转换标题": "notitleconvert",
|
|
760
|
+
"不轉換標題": "notitleconvert",
|
|
761
|
+
"notoc": "notoc",
|
|
762
|
+
"无目录": "notoc",
|
|
763
|
+
"無目錄": "notoc",
|
|
764
|
+
"toc": "toc",
|
|
765
|
+
"目录": "toc",
|
|
766
|
+
"目錄": "toc",
|
|
767
|
+
"archivedtalk": "archivedtalk",
|
|
768
|
+
"notalk": "notalk"
|
|
769
|
+
}
|
|
769
770
|
],
|
|
770
771
|
"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:|worldwind://|xmpp:",
|
|
771
772
|
"interwiki": [],
|
package/config/enwiki.json
CHANGED
|
@@ -343,19 +343,7 @@
|
|
|
343
343
|
]
|
|
344
344
|
],
|
|
345
345
|
"doubleUnderscore": [
|
|
346
|
-
[
|
|
347
|
-
"forcetoc",
|
|
348
|
-
"nocc",
|
|
349
|
-
"nocontentconvert",
|
|
350
|
-
"noeditsection",
|
|
351
|
-
"nogallery",
|
|
352
|
-
"notc",
|
|
353
|
-
"notitleconvert",
|
|
354
|
-
"notoc",
|
|
355
|
-
"toc",
|
|
356
|
-
"archivedtalk",
|
|
357
|
-
"notalk"
|
|
358
|
-
],
|
|
346
|
+
[],
|
|
359
347
|
[
|
|
360
348
|
"EXPECTUNUSEDCATEGORY",
|
|
361
349
|
"DISAMBIG",
|
|
@@ -367,7 +355,20 @@
|
|
|
367
355
|
"STATICREDIRECT",
|
|
368
356
|
"NOGLOBAL",
|
|
369
357
|
"EXPECTED_UNCONNECTED_PAGE"
|
|
370
|
-
]
|
|
358
|
+
],
|
|
359
|
+
{
|
|
360
|
+
"forcetoc": "forcetoc",
|
|
361
|
+
"nocc": "nocontentconvert",
|
|
362
|
+
"nocontentconvert": "nocontentconvert",
|
|
363
|
+
"noeditsection": "noeditsection",
|
|
364
|
+
"nogallery": "nogallery",
|
|
365
|
+
"notc": "notitleconvert",
|
|
366
|
+
"notitleconvert": "notitleconvert",
|
|
367
|
+
"notoc": "notoc",
|
|
368
|
+
"toc": "toc",
|
|
369
|
+
"archivedtalk": "archivedtalk",
|
|
370
|
+
"notalk": "notalk"
|
|
371
|
+
}
|
|
371
372
|
],
|
|
372
373
|
"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:|worldwind://|xmpp:",
|
|
373
374
|
"interwiki": [],
|
package/config/llwiki.json
CHANGED
|
@@ -483,25 +483,7 @@
|
|
|
483
483
|
]
|
|
484
484
|
],
|
|
485
485
|
"doubleUnderscore": [
|
|
486
|
-
[
|
|
487
|
-
"forcetoc",
|
|
488
|
-
"强显目录",
|
|
489
|
-
"nocc",
|
|
490
|
-
"nocontentconvert",
|
|
491
|
-
"不转换内容",
|
|
492
|
-
"noeditsection",
|
|
493
|
-
"无段落编辑",
|
|
494
|
-
"无编辑段落",
|
|
495
|
-
"nogallery",
|
|
496
|
-
"无图库",
|
|
497
|
-
"notc",
|
|
498
|
-
"notitleconvert",
|
|
499
|
-
"不转换标题",
|
|
500
|
-
"notoc",
|
|
501
|
-
"无目录",
|
|
502
|
-
"toc",
|
|
503
|
-
"目录"
|
|
504
|
-
],
|
|
486
|
+
[],
|
|
505
487
|
[
|
|
506
488
|
"EXPECTUNUSEDCATEGORY",
|
|
507
489
|
"HIDDENCAT",
|
|
@@ -516,7 +498,26 @@
|
|
|
516
498
|
"无新段落链接",
|
|
517
499
|
"STATICREDIRECT",
|
|
518
500
|
"静态重定向"
|
|
519
|
-
]
|
|
501
|
+
],
|
|
502
|
+
{
|
|
503
|
+
"forcetoc": "forcetoc",
|
|
504
|
+
"强显目录": "forcetoc",
|
|
505
|
+
"nocc": "nocontentconvert",
|
|
506
|
+
"nocontentconvert": "nocontentconvert",
|
|
507
|
+
"不转换内容": "nocontentconvert",
|
|
508
|
+
"noeditsection": "noeditsection",
|
|
509
|
+
"无段落编辑": "noeditsection",
|
|
510
|
+
"无编辑段落": "noeditsection",
|
|
511
|
+
"nogallery": "nogallery",
|
|
512
|
+
"无图库": "nogallery",
|
|
513
|
+
"notc": "notitleconvert",
|
|
514
|
+
"notitleconvert": "notitleconvert",
|
|
515
|
+
"不转换标题": "notitleconvert",
|
|
516
|
+
"notoc": "notoc",
|
|
517
|
+
"无目录": "notoc",
|
|
518
|
+
"toc": "toc",
|
|
519
|
+
"目录": "toc"
|
|
520
|
+
}
|
|
520
521
|
],
|
|
521
522
|
"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:|worldwind://|xmpp:",
|
|
522
523
|
"interwiki": [],
|
package/config/moegirl.json
CHANGED
|
@@ -575,25 +575,7 @@
|
|
|
575
575
|
]
|
|
576
576
|
],
|
|
577
577
|
"doubleUnderscore": [
|
|
578
|
-
[
|
|
579
|
-
"forcetoc",
|
|
580
|
-
"强显目录",
|
|
581
|
-
"nocc",
|
|
582
|
-
"nocontentconvert",
|
|
583
|
-
"不转换内容",
|
|
584
|
-
"noeditsection",
|
|
585
|
-
"无段落编辑",
|
|
586
|
-
"无编辑段落",
|
|
587
|
-
"nogallery",
|
|
588
|
-
"无图库",
|
|
589
|
-
"notc",
|
|
590
|
-
"notitleconvert",
|
|
591
|
-
"不转换标题",
|
|
592
|
-
"notoc",
|
|
593
|
-
"无目录",
|
|
594
|
-
"toc",
|
|
595
|
-
"目录"
|
|
596
|
-
],
|
|
578
|
+
[],
|
|
597
579
|
[
|
|
598
580
|
"DISAMBIG",
|
|
599
581
|
"消除歧义",
|
|
@@ -609,7 +591,26 @@
|
|
|
609
591
|
"无新段落链接",
|
|
610
592
|
"STATICREDIRECT",
|
|
611
593
|
"静态重定向"
|
|
612
|
-
]
|
|
594
|
+
],
|
|
595
|
+
{
|
|
596
|
+
"forcetoc": "forcetoc",
|
|
597
|
+
"强显目录": "forcetoc",
|
|
598
|
+
"nocc": "nocontentconvert",
|
|
599
|
+
"nocontentconvert": "nocontentconvert",
|
|
600
|
+
"不转换内容": "nocontentconvert",
|
|
601
|
+
"noeditsection": "noeditsection",
|
|
602
|
+
"无段落编辑": "noeditsection",
|
|
603
|
+
"无编辑段落": "noeditsection",
|
|
604
|
+
"nogallery": "nogallery",
|
|
605
|
+
"无图库": "nogallery",
|
|
606
|
+
"notc": "notitleconvert",
|
|
607
|
+
"notitleconvert": "notitleconvert",
|
|
608
|
+
"不转换标题": "notitleconvert",
|
|
609
|
+
"notoc": "notoc",
|
|
610
|
+
"无目录": "notoc",
|
|
611
|
+
"toc": "toc",
|
|
612
|
+
"目录": "toc"
|
|
613
|
+
}
|
|
613
614
|
],
|
|
614
615
|
"protocol": "bitcoin:|ftp://|ftps://|geo:|git://|gopher://|http://|https://|irc://|ircs://|magnet:|mailto:|mms://|news:|nntp://|redis://|sftp://|sip:|sips:|sms:|ssh://|svn://|tel:|telnet://|urn:|worldwind://|xmpp:",
|
|
615
616
|
"interwiki": [],
|
package/config/zhwiki.json
CHANGED
|
@@ -659,32 +659,7 @@
|
|
|
659
659
|
]
|
|
660
660
|
],
|
|
661
661
|
"doubleUnderscore": [
|
|
662
|
-
[
|
|
663
|
-
"forcetoc",
|
|
664
|
-
"强显目录",
|
|
665
|
-
"強制目錄",
|
|
666
|
-
"nocc",
|
|
667
|
-
"nocontentconvert",
|
|
668
|
-
"不转换内容",
|
|
669
|
-
"不轉換內容",
|
|
670
|
-
"noeditsection",
|
|
671
|
-
"无段落编辑",
|
|
672
|
-
"无编辑段落",
|
|
673
|
-
"無段落編輯",
|
|
674
|
-
"nogallery",
|
|
675
|
-
"无图库",
|
|
676
|
-
"無圖庫",
|
|
677
|
-
"notc",
|
|
678
|
-
"notitleconvert",
|
|
679
|
-
"不转换标题",
|
|
680
|
-
"不轉換標題",
|
|
681
|
-
"notoc",
|
|
682
|
-
"无目录",
|
|
683
|
-
"無目錄",
|
|
684
|
-
"toc",
|
|
685
|
-
"目录",
|
|
686
|
-
"目錄"
|
|
687
|
-
],
|
|
662
|
+
[],
|
|
688
663
|
[
|
|
689
664
|
"EXPECTUNUSEDCATEGORY",
|
|
690
665
|
"DISAMBIG",
|
|
@@ -705,7 +680,33 @@
|
|
|
705
680
|
"靜態重新導向",
|
|
706
681
|
"NOGLOBAL",
|
|
707
682
|
"EXPECTED_UNCONNECTED_PAGE"
|
|
708
|
-
]
|
|
683
|
+
],
|
|
684
|
+
{
|
|
685
|
+
"forcetoc": "forcetoc",
|
|
686
|
+
"强显目录": "forcetoc",
|
|
687
|
+
"強制目錄": "forcetoc",
|
|
688
|
+
"nocc": "nocontentconvert",
|
|
689
|
+
"nocontentconvert": "nocontentconvert",
|
|
690
|
+
"不转换内容": "nocontentconvert",
|
|
691
|
+
"不轉換內容": "nocontentconvert",
|
|
692
|
+
"noeditsection": "noeditsection",
|
|
693
|
+
"无段落编辑": "noeditsection",
|
|
694
|
+
"无编辑段落": "noeditsection",
|
|
695
|
+
"無段落編輯": "noeditsection",
|
|
696
|
+
"nogallery": "nogallery",
|
|
697
|
+
"无图库": "nogallery",
|
|
698
|
+
"無圖庫": "nogallery",
|
|
699
|
+
"notc": "notitleconvert",
|
|
700
|
+
"notitleconvert": "notitleconvert",
|
|
701
|
+
"不转换标题": "notitleconvert",
|
|
702
|
+
"不轉換標題": "notitleconvert",
|
|
703
|
+
"notoc": "notoc",
|
|
704
|
+
"无目录": "notoc",
|
|
705
|
+
"無目錄": "notoc",
|
|
706
|
+
"toc": "toc",
|
|
707
|
+
"目录": "toc",
|
|
708
|
+
"目錄": "toc"
|
|
709
|
+
}
|
|
709
710
|
],
|
|
710
711
|
"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:|worldwind://|xmpp:",
|
|
711
712
|
"interwiki": [],
|
package/dist/base.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export interface Config {
|
|
|
4
4
|
readonly namespaces: Record<string, string>;
|
|
5
5
|
readonly nsid: Record<string, number>;
|
|
6
6
|
readonly parserFunction: [Record<string, string>, string[], string[], string[]];
|
|
7
|
-
readonly doubleUnderscore: [string[], string[]];
|
|
7
|
+
readonly doubleUnderscore: [string[], string[], Record<string, string>?];
|
|
8
8
|
readonly protocol: string;
|
|
9
9
|
readonly img: Record<string, string>;
|
|
10
10
|
readonly redirection: string[];
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,8 @@ const base_1 = require("./base");
|
|
|
6
6
|
const debug_1 = require("./util/debug");
|
|
7
7
|
const constants_1 = require("./util/constants");
|
|
8
8
|
const string_1 = require("./util/string");
|
|
9
|
+
/* NOT FOR BROWSER */
|
|
10
|
+
const diff_1 = require("./util/diff");
|
|
9
11
|
/**
|
|
10
12
|
* 从根路径require
|
|
11
13
|
* @param file 文件名
|
|
@@ -22,6 +24,13 @@ const Parser = {
|
|
|
22
24
|
this.config = rootRequire(this.config, 'config');
|
|
23
25
|
return this.getConfig();
|
|
24
26
|
}
|
|
27
|
+
const { doubleUnderscore } = this.config;
|
|
28
|
+
if (doubleUnderscore.length === 2) {
|
|
29
|
+
(0, diff_1.error)(`The schema (${path.resolve(__dirname, '..', 'config', '.schema.json')}) of parser configuration is updated.`);
|
|
30
|
+
}
|
|
31
|
+
else if (doubleUnderscore[0].length === 0) {
|
|
32
|
+
doubleUnderscore[0] = Object.keys(doubleUnderscore[2]);
|
|
33
|
+
}
|
|
25
34
|
return {
|
|
26
35
|
...this.config,
|
|
27
36
|
excludes: [],
|
|
@@ -52,7 +61,13 @@ const Parser = {
|
|
|
52
61
|
for (const key of ['main', 'fragment']) {
|
|
53
62
|
const str = t[key];
|
|
54
63
|
if (str?.includes('\0')) {
|
|
55
|
-
|
|
64
|
+
const s = root.buildFromStr(str, constants_1.BuildMethod.Text);
|
|
65
|
+
if (key === 'main') {
|
|
66
|
+
t.main = s;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
t.setFragment(s);
|
|
70
|
+
}
|
|
56
71
|
}
|
|
57
72
|
}
|
|
58
73
|
return t;
|
package/dist/lib/text.js
CHANGED
package/dist/lib/title.d.ts
CHANGED
|
@@ -2,10 +2,12 @@ import type { Config } from '../base';
|
|
|
2
2
|
/** MediaWiki页面标题对象 */
|
|
3
3
|
export declare class Title {
|
|
4
4
|
#private;
|
|
5
|
-
ns: number;
|
|
6
|
-
fragment: string | undefined;
|
|
7
5
|
interwiki: string;
|
|
8
6
|
readonly valid: boolean;
|
|
7
|
+
/** 命名空间 */
|
|
8
|
+
get ns(): number;
|
|
9
|
+
/** 片段标识符 */
|
|
10
|
+
get fragment(): string | undefined;
|
|
9
11
|
/** 不含命名空间的标题主体部分 */
|
|
10
12
|
get main(): string;
|
|
11
13
|
set main(title: string);
|
|
@@ -24,4 +26,6 @@ export declare class Title {
|
|
|
24
26
|
* @param selfLink 是否允许selfLink
|
|
25
27
|
*/
|
|
26
28
|
constructor(title: string, defaultNs: number, config: Config, decode: boolean, selfLink: boolean);
|
|
29
|
+
/** 检测是否是重定向 */
|
|
30
|
+
getRedirection(): [boolean, string];
|
|
27
31
|
}
|
package/dist/lib/title.js
CHANGED
|
@@ -6,12 +6,20 @@ const string_1 = require("../util/string");
|
|
|
6
6
|
class Title {
|
|
7
7
|
#main;
|
|
8
8
|
#namespaces;
|
|
9
|
-
ns;
|
|
10
|
-
fragment;
|
|
9
|
+
#ns;
|
|
10
|
+
#fragment;
|
|
11
11
|
interwiki = '';
|
|
12
12
|
valid;
|
|
13
13
|
/** @private */
|
|
14
14
|
encoded = false;
|
|
15
|
+
/** 命名空间 */
|
|
16
|
+
get ns() {
|
|
17
|
+
return this.#ns;
|
|
18
|
+
}
|
|
19
|
+
/** 片段标识符 */
|
|
20
|
+
get fragment() {
|
|
21
|
+
return this.#fragment;
|
|
22
|
+
}
|
|
15
23
|
/** 不含命名空间的标题主体部分 */
|
|
16
24
|
get main() {
|
|
17
25
|
return this.#main;
|
|
@@ -27,10 +35,7 @@ class Title {
|
|
|
27
35
|
}
|
|
28
36
|
/** 完整标题 */
|
|
29
37
|
get title() {
|
|
30
|
-
|
|
31
|
-
// eslint-disable-next-line prefer-const
|
|
32
|
-
let title = (prefix + this.main).replace(/ /gu, '_');
|
|
33
|
-
return title;
|
|
38
|
+
return this.getRedirection()[1];
|
|
34
39
|
}
|
|
35
40
|
/** 扩展名 */
|
|
36
41
|
get extension() {
|
|
@@ -58,7 +63,7 @@ class Title {
|
|
|
58
63
|
}
|
|
59
64
|
title = title.replace(/[_ ]+/gu, ' ').trim();
|
|
60
65
|
if (subpage) {
|
|
61
|
-
this
|
|
66
|
+
this.#ns = 0;
|
|
62
67
|
}
|
|
63
68
|
else {
|
|
64
69
|
let ns = defaultNs;
|
|
@@ -74,7 +79,7 @@ class Title {
|
|
|
74
79
|
title = m.slice(1).join(':').trim();
|
|
75
80
|
}
|
|
76
81
|
}
|
|
77
|
-
this
|
|
82
|
+
this.#ns = ns;
|
|
78
83
|
}
|
|
79
84
|
const i = title.indexOf('#');
|
|
80
85
|
if (i !== -1) {
|
|
@@ -85,10 +90,11 @@ class Title {
|
|
|
85
90
|
}
|
|
86
91
|
catch { }
|
|
87
92
|
}
|
|
88
|
-
this
|
|
93
|
+
this.#fragment = fragment.replace(/ /gu, '_');
|
|
89
94
|
title = title.slice(0, i).trim();
|
|
90
95
|
}
|
|
91
|
-
this.valid = Boolean(title || this.interwiki || selfLink && this.ns === 0 && this
|
|
96
|
+
this.valid = Boolean(title || this.interwiki || selfLink && this.ns === 0 && this.#fragment !== undefined)
|
|
97
|
+
&& (0, string_1.decodeHtml)(title) === title
|
|
92
98
|
&& !/^:|\0\d+[eh!+-]\x7F|[<>[\]{}|\n]|%[\da-f]{2}|(?:^|\/)\.{1,2}(?:$|\/)/iu.test(subpage ? /^(?:\.\.\/)+(.*)/u.exec(title)[1] : title);
|
|
93
99
|
this.main = title;
|
|
94
100
|
Object.defineProperties(this, {
|
|
@@ -97,10 +103,21 @@ class Title {
|
|
|
97
103
|
this.#namespaces = config.namespaces;
|
|
98
104
|
}
|
|
99
105
|
/** @private */
|
|
100
|
-
toString() {
|
|
101
|
-
return `${this.title}${this
|
|
106
|
+
toString(display) {
|
|
107
|
+
return `${display ? this.title.replace(/_/gu, ' ') : this.title}${this.#fragment === undefined
|
|
102
108
|
? ''
|
|
103
|
-
: `#${this
|
|
109
|
+
: `#${this.#fragment}`}`;
|
|
110
|
+
}
|
|
111
|
+
/** 检测是否是重定向 */
|
|
112
|
+
getRedirection() {
|
|
113
|
+
const prefix = this.interwiki + (this.interwiki && ':') + this.prefix;
|
|
114
|
+
// eslint-disable-next-line prefer-const
|
|
115
|
+
let title = (prefix + this.main).replace(/ /gu, '_');
|
|
116
|
+
return [false, title];
|
|
117
|
+
}
|
|
118
|
+
/** @private */
|
|
119
|
+
setFragment(fragment) {
|
|
120
|
+
this.#fragment = fragment;
|
|
104
121
|
}
|
|
105
122
|
}
|
|
106
123
|
exports.Title = Title;
|
package/dist/parser/braces.js
CHANGED
|
@@ -6,7 +6,7 @@ const heading_1 = require("../src/heading");
|
|
|
6
6
|
const transclude_1 = require("../src/transclude");
|
|
7
7
|
const arg_1 = require("../src/arg");
|
|
8
8
|
const closes = {
|
|
9
|
-
'=':
|
|
9
|
+
'=': String.raw `\n(?!(?:[^\S\n]|\0\d+[cn]\x7F)*\n)`,
|
|
10
10
|
'{': String.raw `\}{2,}|\|`,
|
|
11
11
|
'-': String.raw `\}-`,
|
|
12
12
|
'[': String.raw `\]\]`,
|
|
@@ -19,7 +19,7 @@ const closes = {
|
|
|
19
19
|
* @throws TranscludeToken.constructor()
|
|
20
20
|
*/
|
|
21
21
|
const parseBraces = (wikitext, config, accum) => {
|
|
22
|
-
const source = String.raw `${config.excludes?.includes('heading') ? '' : String.raw `^(
|
|
22
|
+
const source = String.raw `${config.excludes?.includes('heading') ? '' : String.raw `^((?:\0\d+[cno]\x7F)*)={1,6}|`}\[\[|-\{(?!\{)`, openBraces = String.raw `|\{{2,}`, { parserFunction: [, , , subst] } = config, stack = [];
|
|
23
23
|
wikitext = wikitext.replace(re, (m, p1) => {
|
|
24
24
|
// @ts-expect-error abstract class
|
|
25
25
|
new transclude_1.TranscludeToken(m.slice(2, -2), [], config, accum);
|
|
@@ -49,7 +49,7 @@ const parseBraces = (wikitext, config, accum) => {
|
|
|
49
49
|
lastIndex = curIndex + 1;
|
|
50
50
|
const { pos, findEqual } = stack[stack.length - 1] ?? {};
|
|
51
51
|
if (pos === undefined || findEqual || (0, string_1.removeComment)(wikitext.slice(pos, index)) !== '') {
|
|
52
|
-
const rmt = /^(={1,6})(.+)\1((?:\s|\0\d+
|
|
52
|
+
const rmt = /^(={1,6})(.+)\1((?:\s|\0\d+[cn]\x7F)*)$/u
|
|
53
53
|
.exec(wikitext.slice(index, curIndex));
|
|
54
54
|
if (rmt) {
|
|
55
55
|
wikitext = `${wikitext.slice(0, index)}\0${accum.length}h\x7F${wikitext.slice(curIndex)}`;
|
|
@@ -94,7 +94,7 @@ const parseBraces = (wikitext, config, accum) => {
|
|
|
94
94
|
ch = 'm';
|
|
95
95
|
}
|
|
96
96
|
else if (/^#vardefine:./iu.test(name)) {
|
|
97
|
-
ch = '
|
|
97
|
+
ch = 'n';
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
catch (e) {
|
|
@@ -31,7 +31,7 @@ const parseCommentAndExt = (wikitext, config, accum, includeOnly) => {
|
|
|
31
31
|
const noinclude = (text) => {
|
|
32
32
|
// @ts-expect-error abstract class
|
|
33
33
|
new noinclude_1.NoincludeToken(text, config, accum);
|
|
34
|
-
str += `\0${accum.length - 1}
|
|
34
|
+
str += `\0${accum.length - 1}n\x7F`;
|
|
35
35
|
};
|
|
36
36
|
while (i !== -1 && j !== -1) {
|
|
37
37
|
const token = `\0${accum.length}e\x7F`;
|
|
@@ -51,12 +51,15 @@ const parseCommentAndExt = (wikitext, config, accum, includeOnly) => {
|
|
|
51
51
|
}
|
|
52
52
|
const ext = config.ext.join('|'), noincludeRegex = includeOnly ? 'includeonly' : '(?:no|only)include', includeRegex = includeOnly ? 'noinclude' : 'includeonly', regex = new RegExp(String.raw `<!--.*?(?:-->|$)|<${noincludeRegex}(?:\s[^>]*)?/?>|</${noincludeRegex}\s*>|<(${ext})(\s[^>]*?)?(?:/>|>(.*?)</(\1\s*)>)|<(${includeRegex})(\s[^>]*?)?(?:/>|>(.*?)(?:</(${includeRegex}\s*)>|$))`, 'gisu');
|
|
53
53
|
return wikitext.replace(regex, (substr, name, attr, inner, closing, include, includeAttr, includeInner, includeClosing) => {
|
|
54
|
-
const
|
|
54
|
+
const l = accum.length;
|
|
55
|
+
let ch = 'n';
|
|
55
56
|
if (name) {
|
|
57
|
+
ch = 'e';
|
|
56
58
|
// @ts-expect-error abstract class
|
|
57
59
|
new ext_1.ExtToken(name, attr, inner, closing, config, accum);
|
|
58
60
|
}
|
|
59
61
|
else if (substr.startsWith('<!--')) {
|
|
62
|
+
ch = 'c';
|
|
60
63
|
const closed = substr.endsWith('-->');
|
|
61
64
|
// @ts-expect-error abstract class
|
|
62
65
|
new comment_1.CommentToken(substr.slice(4, closed ? -3 : undefined), closed, config, accum);
|
|
@@ -69,7 +72,7 @@ const parseCommentAndExt = (wikitext, config, accum, includeOnly) => {
|
|
|
69
72
|
// @ts-expect-error abstract class
|
|
70
73
|
new noinclude_1.NoincludeToken(substr, config, accum);
|
|
71
74
|
}
|
|
72
|
-
return
|
|
75
|
+
return `\0${l}${ch}\x7F`;
|
|
73
76
|
});
|
|
74
77
|
};
|
|
75
78
|
exports.parseCommentAndExt = parseCommentAndExt;
|
package/dist/parser/converter.js
CHANGED
|
@@ -9,7 +9,7 @@ const converter_1 = require("../src/converter");
|
|
|
9
9
|
* @param accum
|
|
10
10
|
*/
|
|
11
11
|
const parseConverter = (text, config, accum) => {
|
|
12
|
-
const variants = `(?:${config.variants.join('|')})`, regex1 = /-\{/gu, regex2 = /-\{|\}-/gu, regex3 = new RegExp(String.raw `;(?=(?:[^;]*?=>)?\s*${variants}\s*:|(?:\s|\0\d+
|
|
12
|
+
const variants = `(?:${config.variants.join('|')})`, regex1 = /-\{/gu, regex2 = /-\{|\}-/gu, regex3 = new RegExp(String.raw `;(?=(?:[^;]*?=>)?\s*${variants}\s*:|(?:\s|\0\d+[cn]\x7F)*$)`, 'u'), stack = [];
|
|
13
13
|
let regex = regex1, mt = regex.exec(text);
|
|
14
14
|
while (mt) {
|
|
15
15
|
const { 0: syntax, index } = mt;
|
|
@@ -15,19 +15,19 @@ const parseHrAndDoubleUnderscore = ({ firstChild: { data }, type, name }, config
|
|
|
15
15
|
if (type !== 'root' && (type !== 'ext-inner' || name !== 'poem')) {
|
|
16
16
|
data = `\0${data}`;
|
|
17
17
|
}
|
|
18
|
-
data = data.replace(/^((?:\0\d+
|
|
18
|
+
data = data.replace(/^((?:\0\d+[cno]\x7F)*)(-{4,})/gmu, (_, lead, m) => {
|
|
19
19
|
// @ts-expect-error abstract class
|
|
20
20
|
new hr_1.HrToken(m, config, accum);
|
|
21
21
|
return `${lead}\0${accum.length - 1}r\x7F`;
|
|
22
|
-
}).replace(new RegExp(`__(${[...
|
|
23
|
-
const caseSensitive = sensitive.has(p1);
|
|
24
|
-
if (caseSensitive ||
|
|
22
|
+
}).replace(new RegExp(`__(${[...insensitive, ...sensitive].join('|')})__`, 'giu'), (m, p1) => {
|
|
23
|
+
const caseSensitive = sensitive.has(p1), lc = p1.toLowerCase(), caseInsensitive = insensitive.has(lc);
|
|
24
|
+
if (caseSensitive || caseInsensitive) {
|
|
25
25
|
// @ts-expect-error abstract class
|
|
26
26
|
new doubleUnderscore_1.DoubleUnderscoreToken(p1, caseSensitive, config, accum);
|
|
27
|
-
return `\0${accum.length - 1}u\x7F`;
|
|
27
|
+
return `\0${accum.length - 1}${caseInsensitive && (doubleUnderscore[2]?.[lc] ?? lc) === 'toc' ? 'u' : 'n'}\x7F`;
|
|
28
28
|
}
|
|
29
29
|
return m;
|
|
30
|
-
}).replace(/^((?:\0\d+
|
|
30
|
+
}).replace(/^((?:\0\d+[cn]\x7F)*)(={1,6})(.+)\2((?:\s|\0\d+[cn]\x7F)*)$/gmu, (_, lead, equals, heading, trail) => {
|
|
31
31
|
const text = `${lead}\0${accum.length}h\x7F`;
|
|
32
32
|
// @ts-expect-error abstract class
|
|
33
33
|
new heading_1.HeadingToken(equals.length, [heading, trail], config, accum);
|
package/dist/parser/list.js
CHANGED
|
@@ -13,7 +13,7 @@ const dd_1 = require("../src/nowiki/dd");
|
|
|
13
13
|
* @param accum
|
|
14
14
|
*/
|
|
15
15
|
const parseList = (wikitext, state, config, accum) => {
|
|
16
|
-
const mt = /^((?:\0\d+
|
|
16
|
+
const mt = /^((?:\0\d+[cno]\x7F)*)([;:*#]+\s*)/u.exec(wikitext);
|
|
17
17
|
if (!mt) {
|
|
18
18
|
state.lastPrefix = '';
|
|
19
19
|
return wikitext;
|
package/dist/parser/redirect.js
CHANGED
|
@@ -12,7 +12,7 @@ const redirect_1 = require("../src/redirect");
|
|
|
12
12
|
const parseRedirect = (text, config, accum) => {
|
|
13
13
|
const re = new RegExp(String.raw `^(\s*)((?:${config.redirection.join('|')})\s*(?::\s*)?)\[\[([^\n|\]]+)(\|.*?)?\]\](\s*)`, 'iu'), mt = re.exec(text);
|
|
14
14
|
if (mt && index_1.default.normalizeTitle(mt[3], 0, false, config, true, true).valid) {
|
|
15
|
-
text = `\0${accum.length}
|
|
15
|
+
text = `\0${accum.length}o\x7F${text.slice(mt[0].length)}`;
|
|
16
16
|
// @ts-expect-error abstract class
|
|
17
17
|
new redirect_1.RedirectToken(...mt.slice(1), config, accum);
|
|
18
18
|
return text;
|
package/dist/parser/table.js
CHANGED
|
@@ -47,7 +47,7 @@ const parseTable = ({ firstChild: { data }, type, name }, config, accum) => {
|
|
|
47
47
|
pop = () => top.type === 'td' ? stack.pop() : top;
|
|
48
48
|
for (const outLine of lines) {
|
|
49
49
|
top = stack.pop();
|
|
50
|
-
const [spaces] = /^(?:\s|\0\d+
|
|
50
|
+
const [spaces] = /^(?:\s|\0\d+[cno]\x7F)*/u.exec(outLine), line = outLine.slice(spaces.length), matchesStart = /^(:*)((?:\s|\0\d+[cn]\x7F)*)(\{\||\{(?:\0\d+[cn]\x7F)*\0\d+!\x7F|\0\d+\{\x7F)(.*)$/u
|
|
51
51
|
.exec(line);
|
|
52
52
|
if (matchesStart) {
|
|
53
53
|
while (top && top.type !== 'td') {
|
package/dist/src/arg.js
CHANGED
|
@@ -23,17 +23,17 @@ class ArgToken extends index_2.Token {
|
|
|
23
23
|
/** @param parts 以'|'分隔的各部分 */
|
|
24
24
|
constructor(parts, config = index_1.default.getConfig(), accum = []) {
|
|
25
25
|
super(undefined, config, accum, {});
|
|
26
|
-
for (
|
|
26
|
+
for (const [i, part] of parts.entries()) {
|
|
27
27
|
if (i === 0) {
|
|
28
|
-
const token = new atom_1.AtomToken(
|
|
28
|
+
const token = new atom_1.AtomToken(part, 'arg-name', config, accum, {});
|
|
29
29
|
super.insertAt(token);
|
|
30
30
|
}
|
|
31
31
|
else if (i > 1) {
|
|
32
|
-
const token = new hidden_1.HiddenToken(
|
|
32
|
+
const token = new hidden_1.HiddenToken(part, config, accum);
|
|
33
33
|
super.insertAt(token);
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
|
-
const token = new index_2.Token(
|
|
36
|
+
const token = new index_2.Token(part, config, accum);
|
|
37
37
|
token.type = 'arg-default';
|
|
38
38
|
token.setAttribute('stage', 2);
|
|
39
39
|
super.insertAt(token);
|
package/dist/src/attribute.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AttributeToken = void 0;
|
|
4
4
|
const lint_1 = require("../util/lint");
|
|
5
|
-
const rect_1 = require("../lib/rect");
|
|
6
5
|
const string_1 = require("../util/string");
|
|
7
6
|
const constants_1 = require("../util/constants");
|
|
7
|
+
const rect_1 = require("../lib/rect");
|
|
8
8
|
const index_1 = require("../index");
|
|
9
9
|
const index_2 = require("./index");
|
|
10
10
|
const atom_1 = require("./atom");
|
|
@@ -270,7 +270,7 @@ class AttributeToken extends index_2.Token {
|
|
|
270
270
|
if (attrs && !attrs.has(name)
|
|
271
271
|
|| (type === 'ext-attr' ? tag in htmlAttrs : !/\{\{[^{]+\}\}/u.test(name))
|
|
272
272
|
&& !htmlAttrs[tag]?.has(name)
|
|
273
|
-
&& !/^(?:xmlns:[\w:.-]+|data-[^:]*)$/u.test(name)
|
|
273
|
+
&& !/^(?:xmlns:[\w:.-]+|data-(?!ooui|mw|parsoid)[^:]*)$/u.test(name)
|
|
274
274
|
&& (tag === 'meta' || tag === 'link' || !commonHtmlAttrs.has(name))) {
|
|
275
275
|
errors.push((0, lint_1.generateForChild)(firstChild, rect, 'illegal-attr', 'illegal attribute name'));
|
|
276
276
|
}
|
package/dist/src/attributes.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Token } from './index';
|
|
|
3
3
|
import { AtomToken } from './atom';
|
|
4
4
|
import { AttributeToken } from './attribute';
|
|
5
5
|
import type { LintError } from '../base';
|
|
6
|
-
import type { ExtToken, HtmlToken, TdToken, TrToken, TableToken } from '../internal';
|
|
6
|
+
import type { ExtToken, HtmlToken, TdToken, TrToken, TableToken, SyntaxToken } from '../internal';
|
|
7
7
|
import type { AttributeTypes } from './attribute';
|
|
8
8
|
declare type AttributesTypes = `${AttributeTypes}s`;
|
|
9
9
|
/**
|
|
@@ -17,6 +17,7 @@ export declare abstract class AttributesToken extends Token {
|
|
|
17
17
|
abstract get firstChild(): AtomToken | AttributeToken | undefined;
|
|
18
18
|
abstract get lastChild(): AtomToken | AttributeToken | undefined;
|
|
19
19
|
abstract get parentNode(): ExtToken | HtmlToken | TableToken | TrToken | TdToken | undefined;
|
|
20
|
+
abstract get previousSibling(): SyntaxToken | undefined;
|
|
20
21
|
get type(): AttributesTypes;
|
|
21
22
|
/**
|
|
22
23
|
* @param attr 标签属性
|
package/dist/src/attributes.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AttributesToken = void 0;
|
|
4
4
|
const lint_1 = require("../util/lint");
|
|
5
|
-
const rect_1 = require("../lib/rect");
|
|
6
5
|
const string_1 = require("../util/string");
|
|
6
|
+
const rect_1 = require("../lib/rect");
|
|
7
7
|
const index_1 = require("../index");
|
|
8
8
|
const index_2 = require("./index");
|
|
9
9
|
const atom_1 = require("./atom");
|
|
@@ -37,7 +37,7 @@ class AttributesToken extends index_2.Token {
|
|
|
37
37
|
this.#type = type;
|
|
38
38
|
this.setAttribute('name', name);
|
|
39
39
|
if (attr) {
|
|
40
|
-
const regex = /([^\s/](?:(?!\0\d+~\x7F)[^\s/=])*)(?:((?:\s(?:\s|\0\d+
|
|
40
|
+
const regex = /([^\s/](?:(?!\0\d+~\x7F)[^\s/=])*)(?:((?:\s(?:\s|\0\d+[cn]\x7F)*)?(?:=|\0\d+~\x7F)(?:\s|\0\d+[cn]\x7F)*)(?:(["'])(.*?)(\3|$)|(\S*)))?/gsu;
|
|
41
41
|
let out = '', mt = regex.exec(attr), lastIndex = 0;
|
|
42
42
|
const insertDirty = /** 插入无效属性 */ () => {
|
|
43
43
|
if (out) {
|
|
@@ -97,14 +97,13 @@ class AttributesToken extends index_2.Token {
|
|
|
97
97
|
}
|
|
98
98
|
/** @private */
|
|
99
99
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
100
|
-
const errors = super.lint(start, re), { parentNode,
|
|
100
|
+
const errors = super.lint(start, re), { parentNode, childNodes } = this, attrs = new Map(), duplicated = new Set(), rect = new rect_1.BoundingRect(this, start);
|
|
101
101
|
if (parentNode?.type === 'html' && parentNode.closing && this.text().trim()) {
|
|
102
102
|
const e = (0, lint_1.generateForSelf)(this, rect, 'no-ignored', 'attributes of a closing tag');
|
|
103
103
|
e.fix = { range: [start, e.endIndex], text: '' };
|
|
104
104
|
errors.push(e);
|
|
105
105
|
}
|
|
106
|
-
for (
|
|
107
|
-
const attr = childNodes[i];
|
|
106
|
+
for (const attr of childNodes) {
|
|
108
107
|
if (attr instanceof atom_1.AtomToken && attr.text().trim()) {
|
|
109
108
|
const e = (0, lint_1.generateForChild)(attr, rect, 'no-ignored', 'containing invalid attribute');
|
|
110
109
|
e.suggestions = [
|
|
@@ -53,9 +53,9 @@ class ConverterFlagsToken extends index_2.Token {
|
|
|
53
53
|
if (variantFlags.size === knownFlagCount || validFlags.size === knownFlagCount) {
|
|
54
54
|
return errors;
|
|
55
55
|
}
|
|
56
|
-
const rect = new rect_1.BoundingRect(this, start)
|
|
57
|
-
for (
|
|
58
|
-
const
|
|
56
|
+
const rect = new rect_1.BoundingRect(this, start);
|
|
57
|
+
for (const [i, child] of this.childNodes.entries()) {
|
|
58
|
+
const flag = child.text().trim();
|
|
59
59
|
if (flag
|
|
60
60
|
&& !variantFlags.has(flag)
|
|
61
61
|
&& !unknownFlags.has(flag)
|
package/dist/src/extLink.js
CHANGED
|
@@ -22,7 +22,7 @@ class ExtLinkToken extends index_2.Token {
|
|
|
22
22
|
*/
|
|
23
23
|
constructor(url, space = '', text = '', config = index_1.default.getConfig(), accum = []) {
|
|
24
24
|
super(undefined, config, accum, {});
|
|
25
|
-
const link = url &&
|
|
25
|
+
const link = url && /^\0\d+f\x7F$/u.test(url)
|
|
26
26
|
? accum[Number(url.slice(1, -2))]
|
|
27
27
|
// @ts-expect-error abstract class
|
|
28
28
|
: new magicLink_1.MagicLinkToken(url, 'ext-link-url', config, accum);
|
package/dist/src/gallery.js
CHANGED
|
@@ -56,8 +56,8 @@ class GalleryToken extends index_2.Token {
|
|
|
56
56
|
/** @private */
|
|
57
57
|
lint(start = this.getAbsoluteIndex(), re) {
|
|
58
58
|
const { top, left } = this.getRootNode().posFromIndex(start), errors = [];
|
|
59
|
-
for (
|
|
60
|
-
const
|
|
59
|
+
for (const [i, child] of this.childNodes.entries()) {
|
|
60
|
+
const str = child.toString(), { length } = str, trimmed = str.trim(), startLine = top + i, startCol = i ? 0 : left;
|
|
61
61
|
if (child.type === 'noinclude' && trimmed && !/^<!--.*-->$/u.test(trimmed)) {
|
|
62
62
|
const endIndex = start + length;
|
|
63
63
|
errors.push({
|
package/dist/src/heading.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import Parser from '../index';
|
|
|
2
2
|
import { Token } from './index';
|
|
3
3
|
import { SyntaxToken } from './syntax';
|
|
4
4
|
import type { LintError } from '../base';
|
|
5
|
+
import type { AstText } from '../internal';
|
|
5
6
|
/**
|
|
6
7
|
* 章节标题
|
|
7
8
|
* @classdesc `{childNodes: [Token, SyntaxToken]}`
|
|
@@ -11,6 +12,7 @@ export declare abstract class HeadingToken extends Token {
|
|
|
11
12
|
readonly childNodes: readonly [Token, SyntaxToken];
|
|
12
13
|
abstract get firstChild(): Token;
|
|
13
14
|
abstract get lastChild(): SyntaxToken;
|
|
15
|
+
abstract get nextSibling(): AstText | undefined;
|
|
14
16
|
get type(): 'heading';
|
|
15
17
|
/** 标题层级 */
|
|
16
18
|
get level(): number;
|
package/dist/src/heading.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HeadingToken = void 0;
|
|
4
4
|
const lint_1 = require("../util/lint");
|
|
5
|
-
const rect_1 = require("../lib/rect");
|
|
6
5
|
const debug_1 = require("../util/debug");
|
|
6
|
+
const rect_1 = require("../lib/rect");
|
|
7
7
|
const index_1 = require("../index");
|
|
8
8
|
const index_2 = require("./index");
|
|
9
9
|
const syntax_1 = require("./syntax");
|
|
@@ -34,7 +34,7 @@ class HeadingToken extends index_2.Token {
|
|
|
34
34
|
const token = new index_2.Token(input[0], config, accum);
|
|
35
35
|
token.type = 'heading-title';
|
|
36
36
|
token.setAttribute('stage', 2);
|
|
37
|
-
const trail = new syntax_1.SyntaxToken(input[1],
|
|
37
|
+
const trail = new syntax_1.SyntaxToken(input[1], /^\s*$/u, 'heading-trail', config, accum, {});
|
|
38
38
|
this.append(token, trail);
|
|
39
39
|
}
|
|
40
40
|
/** @private */
|
package/dist/src/html.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HtmlToken = void 0;
|
|
4
4
|
const lint_1 = require("../util/lint");
|
|
5
|
-
const rect_1 = require("../lib/rect");
|
|
6
5
|
const string_1 = require("../util/string");
|
|
6
|
+
const rect_1 = require("../lib/rect");
|
|
7
7
|
const index_1 = require("./index");
|
|
8
8
|
const magicWords = new Set(['if', 'ifeq', 'ifexpr', 'ifexist', 'iferror', 'switch']), formattingTags = new Set([
|
|
9
9
|
'b',
|
package/dist/src/imagemap.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ImagemapToken = void 0;
|
|
4
4
|
const lint_1 = require("../util/lint");
|
|
5
|
-
const rect_1 = require("../lib/rect");
|
|
6
5
|
const debug_1 = require("../util/debug");
|
|
6
|
+
const rect_1 = require("../lib/rect");
|
|
7
7
|
const index_1 = require("../index");
|
|
8
8
|
const index_2 = require("./index");
|
|
9
9
|
const noinclude_1 = require("./nowiki/noinclude");
|
|
@@ -3,7 +3,7 @@ import { Token } from './index';
|
|
|
3
3
|
import { NoincludeToken } from './nowiki/noinclude';
|
|
4
4
|
import { LinkToken } from './link/index';
|
|
5
5
|
import { ExtLinkToken } from './extLink';
|
|
6
|
-
import type { AstText, ImagemapToken } from '../internal';
|
|
6
|
+
import type { AstText, ImagemapToken, GalleryImageToken } from '../internal';
|
|
7
7
|
/**
|
|
8
8
|
* `<imagemap>`内的链接
|
|
9
9
|
* @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
|
|
@@ -13,6 +13,8 @@ export declare abstract class ImagemapLinkToken extends Token {
|
|
|
13
13
|
abstract get firstChild(): AstText;
|
|
14
14
|
abstract get lastChild(): NoincludeToken;
|
|
15
15
|
abstract get parentNode(): ImagemapToken | undefined;
|
|
16
|
+
abstract get previousSibling(): GalleryImageToken | this | NoincludeToken | AstText;
|
|
17
|
+
abstract get nextSibling(): this | NoincludeToken | AstText | undefined;
|
|
16
18
|
get type(): 'imagemap-link';
|
|
17
19
|
/**
|
|
18
20
|
* @param pre 链接前的文本
|
package/dist/src/index.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
// ~: `{{=}}`专用
|
|
24
24
|
// a: AttributeToken
|
|
25
25
|
// b: TableToken
|
|
26
|
-
// c:
|
|
26
|
+
// c: CommentToke
|
|
27
27
|
// d: ListToken
|
|
28
28
|
// e: ExtToken
|
|
29
29
|
// f: MagicLinkToken inside ImageParameterToken
|
|
@@ -31,11 +31,13 @@
|
|
|
31
31
|
// i: RFC/PMID/ISBN
|
|
32
32
|
// l: LinkToken
|
|
33
33
|
// m: `{{fullurl:}}`、`{{canonicalurl:}}`或`{{filepath:}}`
|
|
34
|
+
// n: NoIncludeToken和IncludeToken
|
|
35
|
+
// o: RedirectToken
|
|
34
36
|
// q: QuoteToken
|
|
35
37
|
// r: HrToken
|
|
36
38
|
// s: `{{{|subst:}}}`
|
|
37
39
|
// t: ArgToken或TranscludeToken
|
|
38
|
-
// u:
|
|
40
|
+
// u: `__toc__`
|
|
39
41
|
// v: ConverterToken
|
|
40
42
|
// w: ExtLinkToken
|
|
41
43
|
// x: HtmlToken
|
|
@@ -157,7 +159,7 @@ class Token extends element_1.AstElement {
|
|
|
157
159
|
/** @private */
|
|
158
160
|
build() {
|
|
159
161
|
this.#stage = constants_1.MAX_STAGE;
|
|
160
|
-
const { length, firstChild } = this, str =
|
|
162
|
+
const { length, firstChild } = this, str = firstChild?.toString();
|
|
161
163
|
if (length === 1 && firstChild.type === 'text' && str.includes('\0')) {
|
|
162
164
|
this.replaceChildren(...this.buildFromStr(str));
|
|
163
165
|
this.normalize();
|
package/dist/src/magicLink.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MagicLinkToken = void 0;
|
|
4
4
|
const lint_1 = require("../util/lint");
|
|
5
|
-
const rect_1 = require("../lib/rect");
|
|
6
5
|
const string_1 = require("../util/string");
|
|
6
|
+
const rect_1 = require("../lib/rect");
|
|
7
7
|
const index_1 = require("../index");
|
|
8
8
|
const index_2 = require("./index");
|
|
9
9
|
const space = String.raw `(?:[\p{Zs}\t]| |�*160;|&#[xX]0*[aA]0;)`, spaceRegex = new RegExp(`${space}+`, 'gu');
|
|
@@ -30,11 +30,13 @@ class MagicLinkToken extends index_2.Token {
|
|
|
30
30
|
}
|
|
31
31
|
/** 和内链保持一致 */
|
|
32
32
|
get link() {
|
|
33
|
-
|
|
34
|
-
if (this.type === 'magic-link'
|
|
35
|
-
|
|
33
|
+
const { innerText } = this;
|
|
34
|
+
if (this.type === 'magic-link') {
|
|
35
|
+
return innerText.startsWith('ISBN')
|
|
36
|
+
? `ISBN ${innerText.slice(5).replace(/[- ]/gu, '').replace(/x$/u, 'X')}`
|
|
37
|
+
: innerText;
|
|
36
38
|
}
|
|
37
|
-
return innerText;
|
|
39
|
+
return (0, string_1.decodeNumber)(innerText);
|
|
38
40
|
}
|
|
39
41
|
/**
|
|
40
42
|
* @param url 网址
|
package/dist/src/nested.js
CHANGED
|
@@ -33,10 +33,10 @@ class NestedToken extends index_2.Token {
|
|
|
33
33
|
new comment_1.CommentToken(comment.slice(4, closed ? -3 : undefined), closed, config, accum);
|
|
34
34
|
}
|
|
35
35
|
return str;
|
|
36
|
-
}).replace(/(^|\0\d+[
|
|
36
|
+
}).replace(/(^|\0\d+[cne]\x7F)([^\0]+)(?=$|\0\d+[cne]\x7F)/gu, (_, lead, substr) => {
|
|
37
37
|
// @ts-expect-error abstract class
|
|
38
38
|
new noinclude_1.NoincludeToken(substr, config, accum);
|
|
39
|
-
return `${lead}\0${accum.length}
|
|
39
|
+
return `${lead}\0${accum.length}n\x7F`;
|
|
40
40
|
});
|
|
41
41
|
super(wikitext, config, accum, {});
|
|
42
42
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import Parser from '../../index';
|
|
1
2
|
import { NowikiBaseToken } from './base';
|
|
2
|
-
import type { Config } from '../../base';
|
|
3
3
|
import type { Token } from '../index';
|
|
4
4
|
/** 状态开关 */
|
|
5
5
|
export declare abstract class DoubleUnderscoreToken extends NowikiBaseToken {
|
|
@@ -8,5 +8,5 @@ export declare abstract class DoubleUnderscoreToken extends NowikiBaseToken {
|
|
|
8
8
|
* @param word 状态开关名
|
|
9
9
|
* @param sensitive 是否固定大小写
|
|
10
10
|
*/
|
|
11
|
-
constructor(word: string, sensitive: boolean, config?: Config, accum?: Token[]);
|
|
11
|
+
constructor(word: string, sensitive: boolean, config?: Parser.Config, accum?: Token[]);
|
|
12
12
|
}
|
|
@@ -36,6 +36,7 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
|
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
37
|
exports.DoubleUnderscoreToken = void 0;
|
|
38
38
|
const hidden_1 = require("../../mixin/hidden");
|
|
39
|
+
const index_1 = require("../../index");
|
|
39
40
|
const base_1 = require("./base");
|
|
40
41
|
/** 状态开关 */
|
|
41
42
|
let DoubleUnderscoreToken = (() => {
|
|
@@ -60,7 +61,7 @@ let DoubleUnderscoreToken = (() => {
|
|
|
60
61
|
* @param word 状态开关名
|
|
61
62
|
* @param sensitive 是否固定大小写
|
|
62
63
|
*/
|
|
63
|
-
constructor(word, sensitive, config, accum) {
|
|
64
|
+
constructor(word, sensitive, config = index_1.default.getConfig(), accum) {
|
|
64
65
|
super(word, config, accum);
|
|
65
66
|
}
|
|
66
67
|
/** @private */
|
package/dist/src/parameter.js
CHANGED
|
@@ -33,7 +33,8 @@ class ParameterToken extends index_2.Token {
|
|
|
33
33
|
}
|
|
34
34
|
/** @private */
|
|
35
35
|
trimName(name, set = true) {
|
|
36
|
-
const trimmed = (
|
|
36
|
+
const trimmed = (typeof name === 'string' ? name : name.toString(true))
|
|
37
|
+
.replace(/^[ \t\n\0\v]+|([^ \t\n\0\v])[ \t\n\0\v]+$/gu, '$1');
|
|
37
38
|
this.setAttribute('name', trimmed);
|
|
38
39
|
return trimmed;
|
|
39
40
|
}
|
package/dist/src/pre.js
CHANGED
|
@@ -23,7 +23,7 @@ class PreToken extends index_2.Token {
|
|
|
23
23
|
new noinclude_1.NoincludeToken(opening, config, accum);
|
|
24
24
|
// @ts-expect-error abstract class
|
|
25
25
|
new noinclude_1.NoincludeToken(closing, config, accum);
|
|
26
|
-
str += `${wikitext.slice(0, i)}\0${accum.length - 1}
|
|
26
|
+
str += `${wikitext.slice(0, i)}\0${accum.length - 1}n\x7F${wikitext.slice(i + length, j)}\0${accum.length}n\x7F`;
|
|
27
27
|
wikitext = wikitext.slice(j + length + 1);
|
|
28
28
|
i = wikitext.indexOf(opening);
|
|
29
29
|
j = wikitext.indexOf(closing, i + length);
|
package/dist/src/table/index.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TableToken = exports.Layout = exports.isRowEnd = void 0;
|
|
4
4
|
const lint_1 = require("../../util/lint");
|
|
5
|
-
const rect_1 = require("../../lib/rect");
|
|
6
5
|
const debug_1 = require("../../util/debug");
|
|
6
|
+
const rect_1 = require("../../lib/rect");
|
|
7
7
|
const index_1 = require("../../index");
|
|
8
8
|
const trBase_1 = require("./trBase");
|
|
9
9
|
const syntax_1 = require("../syntax");
|
|
@@ -91,8 +91,7 @@ class TableToken extends trBase_1.TrBaseToken {
|
|
|
91
91
|
*/
|
|
92
92
|
getLayout(stop) {
|
|
93
93
|
const rows = this.getAllRows(), { length } = rows, layout = new Layout(...(0, debug_1.emptyArray)(length, () => []));
|
|
94
|
-
for (
|
|
95
|
-
const rowLayout = layout[i];
|
|
94
|
+
for (const [i, rowLayout] of layout.entries()) {
|
|
96
95
|
let j = 0, k = 0, last;
|
|
97
96
|
for (const cell of rows[i].childNodes.slice(2)) {
|
|
98
97
|
if (cell.type === 'td') {
|
package/dist/src/table/td.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TdToken = void 0;
|
|
4
4
|
const lint_1 = require("../../util/lint");
|
|
5
|
-
const rect_1 = require("../../lib/rect");
|
|
6
5
|
const constants_1 = require("../../util/constants");
|
|
7
6
|
const debug_1 = require("../../util/debug");
|
|
7
|
+
const rect_1 = require("../../lib/rect");
|
|
8
8
|
const index_1 = require("../../index");
|
|
9
9
|
const index_2 = require("../index");
|
|
10
10
|
const base_1 = require("./base");
|
package/dist/src/tagPair/ext.js
CHANGED
|
@@ -7,6 +7,12 @@ const index_1 = require("../../index");
|
|
|
7
7
|
const index_2 = require("../index");
|
|
8
8
|
const index_3 = require("./index");
|
|
9
9
|
const attributes_1 = require("../attributes");
|
|
10
|
+
const pre_1 = require("../pre");
|
|
11
|
+
const index_4 = require("../paramTag/index");
|
|
12
|
+
const inputbox_1 = require("../paramTag/inputbox");
|
|
13
|
+
const gallery_1 = require("../gallery");
|
|
14
|
+
const imagemap_1 = require("../imagemap");
|
|
15
|
+
const index_5 = require("../nowiki/index");
|
|
10
16
|
/**
|
|
11
17
|
* 从数组中删除指定元素
|
|
12
18
|
* @param arr 数组
|
|
@@ -53,25 +59,19 @@ class ExtToken extends index_3.TagPairToken {
|
|
|
53
59
|
}
|
|
54
60
|
innerToken = new index_2.Token(inner, newConfig, accum);
|
|
55
61
|
break;
|
|
56
|
-
case 'pre':
|
|
57
|
-
const { PreToken } = require('../pre');
|
|
62
|
+
case 'pre':
|
|
58
63
|
// @ts-expect-error abstract class
|
|
59
|
-
innerToken = new PreToken(inner, newConfig, accum);
|
|
64
|
+
innerToken = new pre_1.PreToken(inner, newConfig, accum);
|
|
60
65
|
break;
|
|
61
|
-
|
|
62
|
-
case 'dynamicpagelist': {
|
|
63
|
-
const { ParamTagToken } = require('../paramTag/index');
|
|
66
|
+
case 'dynamicpagelist':
|
|
64
67
|
// @ts-expect-error abstract class
|
|
65
|
-
innerToken = new ParamTagToken(inner, newConfig, accum);
|
|
68
|
+
innerToken = new index_4.ParamTagToken(inner, newConfig, accum);
|
|
66
69
|
break;
|
|
67
|
-
|
|
68
|
-
case 'inputbox': {
|
|
70
|
+
case 'inputbox':
|
|
69
71
|
newConfig.excludes.push('heading');
|
|
70
|
-
const { InputboxToken } = require('../paramTag/inputbox');
|
|
71
72
|
// @ts-expect-error abstract class
|
|
72
|
-
innerToken = new InputboxToken(inner, newConfig, accum);
|
|
73
|
+
innerToken = new inputbox_1.InputboxToken(inner, newConfig, accum);
|
|
73
74
|
break;
|
|
74
|
-
}
|
|
75
75
|
case 'references': {
|
|
76
76
|
const { NestedToken } = require('../nested');
|
|
77
77
|
// @ts-expect-error abstract class
|
|
@@ -90,18 +90,14 @@ class ExtToken extends index_3.TagPairToken {
|
|
|
90
90
|
innerToken = new NestedToken(inner, /<(combooption)(\s[^>]*?)?(?:\/>|>(.*?)<\/(combooption\s*)>)/gisu, ['combooption'], newConfig, accum);
|
|
91
91
|
break;
|
|
92
92
|
}
|
|
93
|
-
case 'gallery':
|
|
94
|
-
const { GalleryToken } = require('../gallery');
|
|
93
|
+
case 'gallery':
|
|
95
94
|
// @ts-expect-error abstract class
|
|
96
|
-
innerToken = new GalleryToken(inner, newConfig, accum);
|
|
95
|
+
innerToken = new gallery_1.GalleryToken(inner, newConfig, accum);
|
|
97
96
|
break;
|
|
98
|
-
|
|
99
|
-
case 'imagemap': {
|
|
100
|
-
const { ImagemapToken } = require('../imagemap');
|
|
97
|
+
case 'imagemap':
|
|
101
98
|
// @ts-expect-error abstract class
|
|
102
|
-
innerToken = new ImagemapToken(inner, newConfig, accum);
|
|
99
|
+
innerToken = new imagemap_1.ImagemapToken(inner, newConfig, accum);
|
|
103
100
|
break;
|
|
104
|
-
}
|
|
105
101
|
// 更多定制扩展的代码示例:
|
|
106
102
|
// ```
|
|
107
103
|
// case 'extensionName': {
|
|
@@ -110,11 +106,9 @@ class ExtToken extends index_3.TagPairToken {
|
|
|
110
106
|
// break;
|
|
111
107
|
// }
|
|
112
108
|
// ```
|
|
113
|
-
default:
|
|
114
|
-
const { NowikiToken } = require('../nowiki/index');
|
|
109
|
+
default:
|
|
115
110
|
// @ts-expect-error abstract class
|
|
116
|
-
innerToken = new NowikiToken(inner, newConfig, accum);
|
|
117
|
-
}
|
|
111
|
+
innerToken = new index_5.NowikiToken(inner, newConfig, accum);
|
|
118
112
|
}
|
|
119
113
|
innerToken.setAttribute('name', lcName);
|
|
120
114
|
if (innerToken.type === 'plain') {
|
package/dist/src/transclude.js
CHANGED
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TranscludeToken = void 0;
|
|
4
4
|
const string_1 = require("../util/string");
|
|
5
5
|
const lint_1 = require("../util/lint");
|
|
6
|
-
const rect_1 = require("../lib/rect");
|
|
7
6
|
const debug_1 = require("../util/debug");
|
|
8
7
|
const constants_1 = require("../util/constants");
|
|
8
|
+
const rect_1 = require("../lib/rect");
|
|
9
9
|
const index_1 = require("../index");
|
|
10
10
|
const index_2 = require("./index");
|
|
11
11
|
const parameter_1 = require("./parameter");
|
|
@@ -38,13 +38,13 @@ class TranscludeToken extends index_2.Token {
|
|
|
38
38
|
*/
|
|
39
39
|
constructor(title, parts, config = index_1.default.getConfig(), accum = []) {
|
|
40
40
|
super(undefined, config, accum, {});
|
|
41
|
-
const { parserFunction: [insensitive, sensitive] } = config, argSubst = /^(?:\s|\0\d+
|
|
41
|
+
const { parserFunction: [insensitive, sensitive] } = config, argSubst = /^(?:\s|\0\d+[cn]\x7F)*\0\d+s\x7F/u.exec(title)?.[0];
|
|
42
42
|
if (argSubst) {
|
|
43
43
|
this.setAttribute('modifier', argSubst);
|
|
44
44
|
title = title.slice(argSubst.length);
|
|
45
45
|
}
|
|
46
46
|
else if (title.includes(':')) {
|
|
47
|
-
const [modifier, ...arg] = title.split(':'), [mt] = /^(?:\s|\0\d+
|
|
47
|
+
const [modifier, ...arg] = title.split(':'), [mt] = /^(?:\s|\0\d+[cn]\x7F)*/u.exec(arg[0] ?? '');
|
|
48
48
|
if (this.setModifier(`${modifier}:${mt}`)) {
|
|
49
49
|
title = arg.join(':').slice(mt.length);
|
|
50
50
|
}
|
|
@@ -83,8 +83,7 @@ class TranscludeToken extends index_2.Token {
|
|
|
83
83
|
}
|
|
84
84
|
const templateLike = this.isTemplate();
|
|
85
85
|
let i = 1;
|
|
86
|
-
for (
|
|
87
|
-
const part = parts[j];
|
|
86
|
+
for (const [j, part] of parts.entries()) {
|
|
88
87
|
if (!templateLike && !(this.name === 'switch' && j > 0)) {
|
|
89
88
|
part[0] = part.join('=');
|
|
90
89
|
part.length = 1;
|
package/dist/util/string.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noWrap = exports.
|
|
3
|
+
exports.noWrap = exports.decodeNumber = exports.decodeHtml = exports.text = exports.rawurldecode = exports.escapeRegExp = exports.removeComment = exports.tidy = exports.extUrlChar = exports.extUrlCharFirst = void 0;
|
|
4
4
|
const commonExtUrlChar = String.raw `[^[\]<>"\0-\x1F\x7F\p{Zs}\uFFFD]`;
|
|
5
5
|
exports.extUrlCharFirst = String.raw `(?:\[[\da-f:.]+\]|${commonExtUrlChar})`;
|
|
6
|
-
exports.extUrlChar = String.raw `(?:${commonExtUrlChar}|\0\d+[
|
|
6
|
+
exports.extUrlChar = String.raw `(?:${commonExtUrlChar}|\0\d+[cn!~]\x7F)*`;
|
|
7
7
|
/**
|
|
8
8
|
* 生成正则替换函数
|
|
9
9
|
* @param regex 正则表达式
|
|
@@ -13,7 +13,7 @@ const factory = (regex, replace) => (str) => str.replace(regex, replace);
|
|
|
13
13
|
/** 清理解析专用的不可见字符 */
|
|
14
14
|
exports.tidy = factory(/[\0\x7F]|\r$/gmu, '');
|
|
15
15
|
/** remove half-parsed comment-like tokens */
|
|
16
|
-
exports.removeComment = factory(/\0\d+
|
|
16
|
+
exports.removeComment = factory(/\0\d+[cn]\x7F/gu, '');
|
|
17
17
|
/** escape special chars for RegExp constructor */
|
|
18
18
|
exports.escapeRegExp = factory(/[\\{}()|.?*+^$[\]]/gu, String.raw `\$&`);
|
|
19
19
|
/**
|
|
@@ -22,8 +22,6 @@ exports.escapeRegExp = factory(/[\\{}()|.?*+^$[\]]/gu, String.raw `\$&`);
|
|
|
22
22
|
*/
|
|
23
23
|
const rawurldecode = (str) => decodeURIComponent(str.replace(/%(?![\da-f]{2})/giu, '%25'));
|
|
24
24
|
exports.rawurldecode = rawurldecode;
|
|
25
|
-
/** PHP的`trim`函数的JavaScript实现 */
|
|
26
|
-
exports.trimPHP = factory(/^[ \t\n\0\v]+|([^ \t\n\0\v])[ \t\n\0\v]+$/gu, '$1');
|
|
27
25
|
/**
|
|
28
26
|
* extract effective wikitext
|
|
29
27
|
* @param childNodes a Token's contents
|
|
@@ -31,10 +29,12 @@ exports.trimPHP = factory(/^[ \t\n\0\v]+|([^ \t\n\0\v])[ \t\n\0\v]+$/gu, '$1');
|
|
|
31
29
|
*/
|
|
32
30
|
const text = (childNodes, separator = '') => childNodes.map(child => typeof child === 'string' ? child : child.text()).join(separator);
|
|
33
31
|
exports.text = text;
|
|
34
|
-
const names = { lt: '<', gt: '>', lbrack: '[', rbrack: ']', lbrace: '{', rbrace: '}', nbsp: ' ' };
|
|
32
|
+
const names = { lt: '<', gt: '>', lbrack: '[', rbrack: ']', lbrace: '{', rbrace: '}', nbsp: ' ', amp: '&', quot: '"' };
|
|
35
33
|
/** decode HTML entities */
|
|
36
|
-
exports.decodeHtml = factory(/&(?:#(\d+|
|
|
34
|
+
exports.decodeHtml = factory(/&(?:#(\d+|[Xx][\da-fA-F]+)|([lLgG][tT]|[lr]brac[ke]|nbsp|amp|AMP|quot|QUOT));/gu, (_, code, name) => code
|
|
37
35
|
? String.fromCodePoint(Number((/^x/iu.test(code) ? '0' : '') + code))
|
|
38
36
|
: names[name.toLowerCase()]);
|
|
37
|
+
/** decode numbered HTML entities */
|
|
38
|
+
exports.decodeNumber = factory(/&#(\d+|x[\da-f]+);/giu, (_, code) => String.fromCodePoint(Number((/^x/iu.test(code) ? '0' : '') + code)));
|
|
39
39
|
/** escape newlines */
|
|
40
40
|
exports.noWrap = factory(/\n/gu, String.raw `\n`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wikilint",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.2",
|
|
4
4
|
"description": "A Node.js linter for MediaWiki markup",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mediawiki",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"lint:ts": "tsc --noEmit && eslint --cache .",
|
|
43
43
|
"lint:json": "v8r -s config/.schema.json config/*.json",
|
|
44
44
|
"lint": "npm run lint:ts && npm run lint:json",
|
|
45
|
-
"prof": "node
|
|
45
|
+
"prof": "node dist/test/prof.js",
|
|
46
46
|
"test": "node dist/test/test.js",
|
|
47
47
|
"test:end": "pkill -x http-server",
|
|
48
48
|
"test:real": "node dist/test/real.js"
|