wikiparser-node 1.39.1 → 1.41.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.
Files changed (59) hide show
  1. package/README.md +51 -5
  2. package/bundle/bundle-es8.min.js +30 -29
  3. package/bundle/bundle-lsp.min.js +28 -28
  4. package/bundle/bundle.min.js +16 -16
  5. package/config/.schema.json +5 -0
  6. package/config/default.json +11 -2
  7. package/config/enwiki.json +91 -89
  8. package/config/jawiki.json +168 -158
  9. package/config/llwiki.json +2 -1
  10. package/config/minimum.json +3 -81
  11. package/config/moegirl.json +2 -1
  12. package/config/zhwiki.json +128 -126
  13. package/data/signatures.json +1 -1
  14. package/dist/addon/attribute.js +1 -1
  15. package/dist/addon/table.js +1 -1
  16. package/dist/addon/transclude.js +3 -1
  17. package/dist/base.d.mts +11 -9
  18. package/dist/base.d.ts +11 -9
  19. package/dist/base.js +1 -0
  20. package/dist/base.mjs +1 -0
  21. package/dist/bin/config.js +11 -10
  22. package/dist/index.d.ts +5 -5
  23. package/dist/index.js +5 -1
  24. package/dist/lib/lintConfig.js +42 -23
  25. package/dist/lib/lsp.js +6 -12
  26. package/dist/lib/node.js +5 -2
  27. package/dist/lib/text.js +5 -2
  28. package/dist/lib/title.js +8 -4
  29. package/dist/mixin/elementLike.js +2 -2
  30. package/dist/parser/commentAndExt.js +2 -1
  31. package/dist/render/expand.js +3 -3
  32. package/dist/render/extension.js +15 -3
  33. package/dist/render/magicWords.js +13 -10
  34. package/dist/src/attribute.d.ts +4 -1
  35. package/dist/src/attribute.js +5 -4
  36. package/dist/src/attributes.js +29 -7
  37. package/dist/src/heading.js +8 -3
  38. package/dist/src/link/base.d.ts +1 -1
  39. package/dist/src/link/base.js +10 -6
  40. package/dist/src/link/file.js +2 -2
  41. package/dist/src/magicLink.js +20 -16
  42. package/dist/src/multiLine/gallery.d.ts +5 -3
  43. package/dist/src/multiLine/gallery.js +6 -4
  44. package/dist/src/nowiki/base.d.ts +1 -1
  45. package/dist/src/parameter.js +5 -2
  46. package/dist/src/table/tr.js +1 -1
  47. package/dist/src/tagPair/ext.js +12 -18
  48. package/dist/src/tagPair/index.d.ts +1 -1
  49. package/dist/src/transclude.d.ts +6 -1
  50. package/dist/src/transclude.js +27 -19
  51. package/dist/util/constants.js +2 -1
  52. package/dist/util/sharable.js +2 -0
  53. package/dist/util/sharable.mjs +3 -1
  54. package/extensions/dist/base.js +3 -2
  55. package/extensions/dist/env.js +34 -0
  56. package/i18n/en.json +1 -0
  57. package/i18n/zh-hans.json +1 -0
  58. package/i18n/zh-hant.json +1 -0
  59. package/package.json +20 -33
@@ -425,89 +425,89 @@
425
425
  "variable": [
426
426
  "!",
427
427
  "=",
428
+ "articlepath",
429
+ "basepagename",
430
+ "basepagenamee",
431
+ "bcp47",
432
+ "cascadingsources",
433
+ "contentlanguage",
434
+ "contentmodel",
435
+ "currentday",
436
+ "currentday2",
437
+ "currentdayname",
438
+ "currentdow",
439
+ "currenthour",
428
440
  "currentmonth",
429
441
  "currentmonth1",
430
442
  "currentmonthname",
431
443
  "currentmonthnamegen",
432
444
  "currentmonthabbrev",
433
- "currentday",
434
- "currentday2",
435
- "currentdayname",
436
- "currentyear",
437
445
  "currenttime",
438
- "currenthour",
446
+ "currenttimestamp",
447
+ "currentversion",
448
+ "currentweek",
449
+ "currentyear",
450
+ "dir",
451
+ "directionmark",
452
+ "fullpagename",
453
+ "fullpagenamee",
454
+ "isbn",
455
+ "language",
456
+ "localday",
457
+ "localday2",
458
+ "localdayname",
459
+ "localdow",
460
+ "localhour",
439
461
  "localmonth",
440
462
  "localmonth1",
463
+ "localmonthabbrev",
441
464
  "localmonthname",
442
465
  "localmonthnamegen",
443
- "localmonthabbrev",
444
- "localday",
445
- "localday2",
446
- "localdayname",
447
- "localyear",
448
466
  "localtime",
449
- "localhour",
467
+ "localtimestamp",
468
+ "localweek",
469
+ "localyear",
470
+ "namespace",
471
+ "namespacee",
472
+ "namespacenumber",
473
+ "numberofactiveusers",
474
+ "numberofadmins",
450
475
  "numberofarticles",
451
- "numberoffiles",
452
476
  "numberofedits",
453
- "articlepath",
477
+ "numberoffiles",
478
+ "numberofpages",
479
+ "numberofusers",
454
480
  "pageid",
455
- "sitename",
456
- "server",
457
- "servername",
458
- "scriptpath",
459
- "stylepath",
481
+ "pagelanguage",
460
482
  "pagename",
461
483
  "pagenamee",
462
- "fullpagename",
463
- "fullpagenamee",
464
- "namespace",
465
- "namespacee",
466
- "namespacenumber",
467
- "currentweek",
468
- "currentdow",
469
- "localweek",
470
- "localdow",
471
- "revisionid",
472
484
  "revisionday",
473
485
  "revisionday2",
486
+ "revisionid",
474
487
  "revisionmonth",
475
488
  "revisionmonth1",
476
- "revisionyear",
489
+ "revisionsize",
477
490
  "revisiontimestamp",
491
+ "revisionyear",
478
492
  "revisionuser",
479
- "revisionsize",
493
+ "rootpagename",
494
+ "rootpagenamee",
495
+ "scriptpath",
496
+ "server",
497
+ "servername",
498
+ "sitename",
499
+ "stylepath",
500
+ "subjectpagename",
501
+ "subjectpagenamee",
502
+ "subjectspace",
503
+ "subjectspacee",
480
504
  "subpagename",
481
505
  "subpagenamee",
482
506
  "talkspace",
483
507
  "talkspacee",
484
- "subjectspace",
485
- "subjectspacee",
486
508
  "talkpagename",
487
509
  "talkpagenamee",
488
- "subjectpagename",
489
- "subjectpagenamee",
490
- "numberofusers",
491
- "numberofactiveusers",
492
- "numberofpages",
493
- "currentversion",
494
- "rootpagename",
495
- "rootpagenamee",
496
- "basepagename",
497
- "basepagenamee",
498
- "currenttimestamp",
499
- "localtimestamp",
500
- "directionmark",
501
- "contentlanguage",
502
510
  "userlanguage",
503
- "pagelanguage",
504
- "numberofadmins",
505
- "cascadingsources",
506
- "bcp47",
507
- "contentmodel",
508
- "dir",
509
- "language",
510
- "isbn",
511
511
  "numberofwikis",
512
512
  "noexternallanglinks",
513
513
  "wbreponame"
@@ -652,14 +652,14 @@
652
652
  "#mentor": "mentor",
653
653
  "articlepath": "articlepath",
654
654
  "条目路径": "articlepath",
655
+ "scriptpath": "scriptpath",
656
+ "脚本路径": "scriptpath",
655
657
  "server": "server",
656
658
  "服务器": "server",
657
659
  "伺服器": "server",
658
660
  "servername": "servername",
659
661
  "服务器名": "servername",
660
662
  "伺服器名稱": "servername",
661
- "scriptpath": "scriptpath",
662
- "脚本路径": "scriptpath",
663
663
  "stylepath": "stylepath",
664
664
  "样式路径": "stylepath",
665
665
  "numberofwikis": "numberofwikis",
@@ -803,6 +803,22 @@
803
803
  "#timefl": "timefl",
804
804
  "!": "!",
805
805
  "=": "=",
806
+ "CONTENTLANGUAGE": "contentlanguage",
807
+ "CONTENTLANG": "contentlanguage",
808
+ "内容语言": "contentlanguage",
809
+ "內容語言": "contentlanguage",
810
+ "CURRENTDAY": "currentday",
811
+ "今天": "currentday",
812
+ "CURRENTDAY2": "currentday2",
813
+ "今天2": "currentday2",
814
+ "CURRENTDAYNAME": "currentdayname",
815
+ "星期": "currentdayname",
816
+ "今天名": "currentdayname",
817
+ "今天名称": "currentdayname",
818
+ "CURRENTDOW": "currentdow",
819
+ "当前DOW": "currentdow",
820
+ "CURRENTHOUR": "currenthour",
821
+ "当前小时": "currenthour",
806
822
  "CURRENTMONTH": "currentmonth",
807
823
  "CURRENTMONTH2": "currentmonth",
808
824
  "本月": "currentmonth",
@@ -818,75 +834,59 @@
818
834
  "CURRENTMONTHABBREV": "currentmonthabbrev",
819
835
  "本月简称": "currentmonthabbrev",
820
836
  "本月縮寫": "currentmonthabbrev",
821
- "CURRENTDAY": "currentday",
822
- "今天": "currentday",
823
- "CURRENTDAY2": "currentday2",
824
- "今天2": "currentday2",
825
- "CURRENTDAYNAME": "currentdayname",
826
- "星期": "currentdayname",
827
- "今天名": "currentdayname",
828
- "今天名称": "currentdayname",
829
- "CURRENTYEAR": "currentyear",
830
- "今年": "currentyear",
831
837
  "CURRENTTIME": "currenttime",
832
838
  "当前时间": "currenttime",
833
839
  "此时": "currenttime",
834
840
  "目前時間": "currenttime",
835
- "CURRENTHOUR": "currenthour",
836
- "当前小时": "currenthour",
841
+ "CURRENTTIMESTAMP": "currenttimestamp",
842
+ "当前时间戳": "currenttimestamp",
843
+ "CURRENTVERSION": "currentversion",
844
+ "当前版本": "currentversion",
845
+ "目前版本": "currentversion",
846
+ "CURRENTWEEK": "currentweek",
847
+ "本周": "currentweek",
848
+ "CURRENTYEAR": "currentyear",
849
+ "今年": "currentyear",
850
+ "DIRECTIONMARK": "directionmark",
851
+ "DIRMARK": "directionmark",
852
+ "方向标记": "directionmark",
853
+ "LOCALDAY": "localday",
854
+ "本地日": "localday",
855
+ "LOCALDAY2": "localday2",
856
+ "本地日2": "localday2",
857
+ "LOCALDAYNAME": "localdayname",
858
+ "本地日名": "localdayname",
859
+ "LOCALDOW": "localdow",
860
+ "本地DOW": "localdow",
861
+ "LOCALHOUR": "localhour",
862
+ "本地小时": "localhour",
837
863
  "LOCALMONTH": "localmonth",
838
864
  "LOCALMONTH2": "localmonth",
839
865
  "本地月": "localmonth",
840
866
  "本地月2": "localmonth",
841
867
  "LOCALMONTH1": "localmonth1",
842
868
  "本地月1": "localmonth1",
869
+ "LOCALMONTHABBREV": "localmonthabbrev",
870
+ "本地月缩写": "localmonthabbrev",
843
871
  "LOCALMONTHNAME": "localmonthname",
844
872
  "本地月份名": "localmonthname",
845
873
  "LOCALMONTHNAMEGEN": "localmonthnamegen",
846
874
  "本地月历": "localmonthnamegen",
847
- "LOCALMONTHABBREV": "localmonthabbrev",
848
- "本地月缩写": "localmonthabbrev",
849
- "LOCALDAY": "localday",
850
- "本地日": "localday",
851
- "LOCALDAY2": "localday2",
852
- "本地日2": "localday2",
853
- "LOCALDAYNAME": "localdayname",
854
- "本地日名": "localdayname",
855
- "LOCALYEAR": "localyear",
856
- "本地年": "localyear",
857
875
  "LOCALTIME": "localtime",
858
876
  "本地时间": "localtime",
859
- "LOCALHOUR": "localhour",
860
- "本地小时": "localhour",
861
- "SITENAME": "sitename",
862
- "站点名称": "sitename",
863
- "網站名稱": "sitename",
864
- "CURRENTWEEK": "currentweek",
865
- "本周": "currentweek",
866
- "CURRENTDOW": "currentdow",
867
- "当前DOW": "currentdow",
877
+ "LOCALTIMESTAMP": "localtimestamp",
878
+ "本地时间戳": "localtimestamp",
868
879
  "LOCALWEEK": "localweek",
869
880
  "本地周": "localweek",
870
- "LOCALDOW": "localdow",
871
- "本地DOW": "localdow",
881
+ "LOCALYEAR": "localyear",
882
+ "本地年": "localyear",
883
+ "PAGELANGUAGE": "pagelanguage",
872
884
  "REVISIONSIZE": "revisionsize",
873
885
  "修订大小": "revisionsize",
874
- "CURRENTVERSION": "currentversion",
875
- "当前版本": "currentversion",
876
- "目前版本": "currentversion",
877
- "CURRENTTIMESTAMP": "currenttimestamp",
878
- "当前时间戳": "currenttimestamp",
879
- "LOCALTIMESTAMP": "localtimestamp",
880
- "本地时间戳": "localtimestamp",
881
- "DIRECTIONMARK": "directionmark",
882
- "DIRMARK": "directionmark",
883
- "方向标记": "directionmark",
884
- "CONTENTLANGUAGE": "contentlanguage",
885
- "CONTENTLANG": "contentlanguage",
886
- "内容语言": "contentlanguage",
887
- "內容語言": "contentlanguage",
888
- "USERLANGUAGE": "userlanguage",
889
- "PAGELANGUAGE": "pagelanguage"
886
+ "SITENAME": "sitename",
887
+ "站点名称": "sitename",
888
+ "網站名稱": "sitename",
889
+ "USERLANGUAGE": "userlanguage"
890
890
  },
891
891
  [
892
892
  "msg",
@@ -907,49 +907,50 @@
907
907
  [],
908
908
  [],
909
909
  {
910
- "notoc": "notoc",
911
- "无目录": "notoc",
912
- "無目錄": "notoc",
913
- "nogallery": "nogallery",
914
- "无图库": "nogallery",
915
- "無圖庫": "nogallery",
916
910
  "forcetoc": "forcetoc",
917
911
  "强显目录": "forcetoc",
918
912
  "強制目錄": "forcetoc",
919
- "toc": "toc",
920
- "目录": "toc",
921
- "目錄": "toc",
913
+ "nocontentconvert": "nocontentconvert",
914
+ "nocc": "nocontentconvert",
915
+ "不转换内容": "nocontentconvert",
916
+ "不轉換內容": "nocontentconvert",
922
917
  "noeditsection": "noeditsection",
923
918
  "无编辑段落": "noeditsection",
924
919
  "无段落编辑": "noeditsection",
925
920
  "無段落編輯": "noeditsection",
921
+ "nogallery": "nogallery",
922
+ "无图库": "nogallery",
923
+ "無圖庫": "nogallery",
926
924
  "notitleconvert": "notitleconvert",
927
925
  "notc": "notitleconvert",
928
926
  "不转换标题": "notitleconvert",
929
927
  "不轉換標題": "notitleconvert",
930
- "nocontentconvert": "nocontentconvert",
931
- "nocc": "nocontentconvert",
932
- "不转换内容": "nocontentconvert",
933
- "不轉換內容": "nocontentconvert",
928
+ "notoc": "notoc",
929
+ "无目录": "notoc",
930
+ "無目錄": "notoc",
931
+ "toc": "toc",
932
+ "目录": "toc",
933
+ "目錄": "toc",
934
+ "nomediaviewercarousel": "nomediaviewercarousel",
934
935
  "已存档讨论": "archivedtalk",
935
936
  "archivedtalk": "archivedtalk",
936
937
  "禁用讨论": "notalk",
937
938
  "notalk": "notalk"
938
939
  },
939
940
  {
940
- "NEWSECTIONLINK": "NEWSECTIONLINK",
941
- "新段落链接": "NEWSECTIONLINK",
942
- "NONEWSECTIONLINK": "NONEWSECTIONLINK",
943
- "无新段落链接": "NONEWSECTIONLINK",
941
+ "EXPECTUNUSEDCATEGORY": "EXPECTUNUSEDCATEGORY",
942
+ "EXPECTUNUSEDTEMPLATE": "EXPECTUNUSEDTEMPLATE",
944
943
  "HIDDENCAT": "HIDDENCAT",
945
944
  "隐藏分类": "HIDDENCAT",
946
945
  "隱藏分類": "HIDDENCAT",
947
- "EXPECTUNUSEDCATEGORY": "EXPECTUNUSEDCATEGORY",
948
- "EXPECTUNUSEDTEMPLATE": "EXPECTUNUSEDTEMPLATE",
949
946
  "INDEX": "INDEX",
950
947
  "索引": "INDEX",
948
+ "NEWSECTIONLINK": "NEWSECTIONLINK",
949
+ "新段落链接": "NEWSECTIONLINK",
951
950
  "NOINDEX": "NOINDEX",
952
951
  "无索引": "NOINDEX",
952
+ "NONEWSECTIONLINK": "NONEWSECTIONLINK",
953
+ "无新段落链接": "NONEWSECTIONLINK",
953
954
  "STATICREDIRECT": "STATICREDIRECT",
954
955
  "静态重定向": "STATICREDIRECT",
955
956
  "靜態重新導向": "STATICREDIRECT",
@@ -960,7 +961,7 @@
960
961
  "EXPECTED_UNCONNECTED_PAGE": "EXPECTEDUNCONNECTEDPAGE"
961
962
  }
962
963
  ],
963
- "protocol": "bitcoin:|ftp://|ftps://|geo:|git://|gopher://|http://|https://|irc://|ircs://|magnet:|mailto:|matrix:|mms://|news:|nntp://|redis://|sftp://|sip:|sips:|sms:|ssh://|svn://|tel:|telnet://|urn:|wikipedia://|worldwind://|xmpp:",
964
+ "protocol": "bitcoin:|ftp://|ftps://|geo:|git://|gopher://|http://|https://|irc://|ircs://|magnet:|mailto:|matrix:|mms://|news:|nntp://|redis://|sftp://|sip:|sips:|sms:|ssh://|svn://|tel:|telnet://|urn:|wikipedia://|worldwind://|xmpp:|commonsfinder://",
964
965
  "interwiki": [],
965
966
  "img": {
966
967
  "alt=$1": "alt",
@@ -1059,5 +1060,6 @@
1059
1060
  "zh-sg",
1060
1061
  "zh-tw"
1061
1062
  ],
1062
- "articlePath": "/wiki/$1"
1063
+ "articlePath": "/wiki/$1",
1064
+ "server": "//zh.wikipedia.org"
1063
1065
  }
@@ -1962,7 +1962,7 @@
1962
1962
  }
1963
1963
  ]
1964
1964
  ],
1965
- "description": "The canonical or localized name of the content model of the specified page."
1965
+ "description": "**[Expensive]** The canonical or localized name of the content model of the specified page."
1966
1966
  },
1967
1967
  {
1968
1968
  "aliases": [
@@ -90,7 +90,7 @@ attribute_1.AttributeToken.prototype.css =
90
90
  start = offset + length;
91
91
  }
92
92
  output += style.slice(start);
93
- this.setValue(output.replace(/^\s*;\s*|;\s*(?=;)/gu, ''));
93
+ this.setValue(output.replaceAll(/^\s*;\s*|;\s*(?=;)/gu, ''));
94
94
  }
95
95
  return undefined;
96
96
  }
@@ -436,7 +436,7 @@ index_2.TableToken.prototype.removeTableCol =
436
436
  index_2.TableToken.prototype.mergeCells =
437
437
  /** @implements */
438
438
  function (xlim, ylim) {
439
- const layout = this.getLayout(), maxCol = getMaxCol(layout), [xmin, xmax] = xlim.map(x => x < 0 ? x + maxCol : x).sort(compare), [ymin, ymax] = ylim.map(y => y < 0 ? y + layout.length : y).sort(compare), set = new Set(layout.slice(ymin, ymax).flatMap(rowLayout => rowLayout.slice(xmin, xmax)));
439
+ const layout = this.getLayout(), maxCol = getMaxCol(layout), [xmin, xmax] = xlim.map(x => x < 0 ? x + maxCol : x).toSorted(compare), [ymin, ymax] = ylim.map(y => y < 0 ? y + layout.length : y).toSorted(compare), set = new Set(layout.slice(ymin, ymax).flatMap(rowLayout => rowLayout.slice(xmin, xmax)));
440
440
  if ([...layout[ymin - 1] ?? [], ...layout[ymax] ?? []].some(coords => set.has(coords))
441
441
  || layout.some(rowLayout => set.has(rowLayout[xmin - 1]) || set.has(rowLayout[xmax]))) {
442
442
  throw new RangeError('The area to be merged overlaps with the outer area!');
@@ -18,7 +18,9 @@ const atom_1 = require("../src/atom");
18
18
  */
19
19
  const format = (token) => {
20
20
  const { lastChild, type } = token, isParameter = lastChild.is('parameter');
21
- if (!(type === 'template' ? isParameter && lastChild.anon : lastChild.is('magic-word-name'))
21
+ if (!(type === 'template'
22
+ ? isParameter && lastChild.anon
23
+ : lastChild.is('magic-word-name'))
22
24
  && !lastChild.toString().endsWith('\n')) {
23
25
  (isParameter ? lastChild.lastChild : lastChild).insertAt('\n');
24
26
  }
package/dist/base.d.mts CHANGED
@@ -9,13 +9,14 @@ export interface Config {
9
9
  readonly parserFunction: [Record<string, string>, Record<string, string>, string[], string[]];
10
10
  readonly doubleUnderscore: [string[], string[], Record<string, string>, Record<string, string>];
11
11
  readonly protocol: string;
12
- readonly interwiki: string[];
13
12
  readonly img: Record<string, string>;
14
13
  readonly redirection: string[];
15
14
  readonly variants: string[];
16
- readonly articlePath?: string;
15
+ articlePath?: string;
17
16
  readonly conversionTable?: [string, string][];
18
17
  readonly redirects?: [string, string][];
18
+ readonly interwiki: string[];
19
+ server?: string;
19
20
  }
20
21
  export type ConfigData = Omit<Config, 'excludes'>;
21
22
  export type TokenTypes = 'root' | 'plain' | 'redirect' | 'redirect-syntax' | 'redirect-target' | 'translate' | 'translate-attr' | 'translate-inner' | 'tvar' | 'tvar-name' | 'onlyinclude' | 'noinclude' | 'include' | 'comment' | 'ext' | 'ext-attrs' | 'ext-attr-dirty' | 'ext-attr' | 'attr-key' | 'attr-value' | 'ext-inner' | 'arg' | 'arg-name' | 'arg-default' | 'hidden' | 'magic-word' | 'magic-word-name' | 'invoke-function' | 'invoke-module' | 'template' | 'template-name' | 'parameter' | 'parameter-key' | 'parameter-value' | 'heading' | 'heading-title' | 'heading-trail' | 'html' | 'html-attrs' | 'html-attr-dirty' | 'html-attr' | 'table' | 'tr' | 'td' | 'table-syntax' | 'table-attrs' | 'table-attr-dirty' | 'table-attr' | 'table-inter' | 'td-inner' | 'hr' | 'double-underscore' | 'link' | 'link-target' | 'link-text' | 'category' | 'file' | 'gallery-image' | 'imagemap-image' | 'image-parameter' | 'quote' | 'ext-link' | 'ext-link-text' | 'ext-link-url' | 'free-ext-link' | 'magic-link' | 'list' | 'dd' | 'converter' | 'converter-flags' | 'converter-flag' | 'converter-rule' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'param-line' | 'imagemap-link' | 'list-range';
@@ -47,7 +48,7 @@ export declare const stages: {
47
48
  'list-range': number;
48
49
  };
49
50
  export type Stage = keyof typeof stages;
50
- export declare const rules: readonly ["arg-in-ext", "blank-alt", "bold-header", "format-leakage", "fostered-content", "h1", "illegal-attr", "insecure-style", "invalid-gallery", "invalid-imagemap", "invalid-invoke", "invalid-isbn", "invalid-json", "invalid-url", "lonely-apos", "lonely-bracket", "lonely-http", "nested-link", "no-arg", "no-duplicate", "no-ignored", "obsolete-attr", "obsolete-tag", "parsing-order", "pipe-like", "syntax-like", "table-layout", "tag-like", "unbalanced-header", "unclosed-comment", "unclosed-quote", "unclosed-table", "unescaped", "unknown-page", "unmatched-tag", "unterminated-url", "url-encoding", "var-anchor", "void-ext", "invalid-css", "invalid-math"];
51
+ export declare const rules: readonly ["arg-in-ext", "blank-alt", "bold-header", "format-leakage", "fostered-content", "h1", "illegal-attr", "insecure-style", "invalid-gallery", "invalid-imagemap", "invalid-invoke", "invalid-isbn", "invalid-json", "invalid-url", "lonely-apos", "lonely-bracket", "lonely-http", "nested-link", "no-arg", "no-duplicate", "no-ignored", "obsolete-attr", "obsolete-tag", "parsing-order", "pipe-like", "required-attr", "syntax-like", "table-layout", "tag-like", "unbalanced-header", "unclosed-comment", "unclosed-quote", "unclosed-table", "unescaped", "unknown-page", "unmatched-tag", "unterminated-url", "url-encoding", "var-anchor", "void-ext", "invalid-css", "invalid-math"];
51
52
  export declare namespace LintError {
52
53
  type Severity = 'error' | 'warning';
53
54
  type Rule = typeof rules[number];
@@ -298,8 +299,9 @@ export interface LanguageService {
298
299
  [Symbol.dispose](): void;
299
300
  }
300
301
  export type SeverityLevel = 0 | 1 | 2 | false | 'off' | 'warning' | 'error';
301
- export type LintConfigValue = SeverityLevel | [SeverityLevel, Record<string, SeverityLevel>?];
302
- export type LintRuleConfig = Partial<Record<LintError.Rule, LintConfigValue>>;
302
+ export type FullLintConfigValue = [SeverityLevel, Record<string, SeverityLevel>?];
303
+ export type LintConfigValue = SeverityLevel | FullLintConfigValue | Record<string, SeverityLevel>;
304
+ export type LintRuleConfig<T = LintConfigValue> = Partial<Record<LintError.Rule, T>>;
303
305
  export interface FullLintConfig {
304
306
  rules: LintRuleConfig;
305
307
  configurationComment?: string;
@@ -315,9 +317,9 @@ export interface LintConfiguration extends FullLintConfig {
315
317
  rules: LintRuleConfiguration;
316
318
  getSeverity(rule: LintError.Rule, key?: string): LintError.Severity | false;
317
319
  }
320
+ export type MaxStage = number | Stage | Stage[];
318
321
  export interface Parser {
319
- config: string | // eslint-disable-line @stylistic/operator-linebreak
320
- ConfigData;
322
+ config: string | ConfigData;
321
323
  i18n: Record<string, string> | string | undefined;
322
324
  /** @since v1.22.0 */
323
325
  lintConfig: LintConfig;
@@ -338,8 +340,8 @@ export interface Parser {
338
340
  * @param maxStage max stage for parsing / 最大解析层级
339
341
  * @param page page name / 页面名称
340
342
  */
341
- parse(wikitext: string, include?: boolean, maxStage?: number | Stage | Stage[], config?: Config, page?: string): Token;
342
- parse(wikitext: string, page: string, include?: boolean, maxStage?: number | Stage | Stage[], config?: Config): Token;
343
+ parse(wikitext: string, include?: boolean, maxStage?: MaxStage, config?: Config, page?: string): Token;
344
+ parse(wikitext: string, page: string, include?: boolean, maxStage?: MaxStage, config?: Config): Token;
343
345
  /**
344
346
  * Create a language server
345
347
  *
package/dist/base.d.ts CHANGED
@@ -9,13 +9,14 @@ export interface Config {
9
9
  readonly parserFunction: [Record<string, string>, Record<string, string>, string[], string[]];
10
10
  readonly doubleUnderscore: [string[], string[], Record<string, string>, Record<string, string>];
11
11
  readonly protocol: string;
12
- readonly interwiki: string[];
13
12
  readonly img: Record<string, string>;
14
13
  readonly redirection: string[];
15
14
  readonly variants: string[];
16
- readonly articlePath?: string;
15
+ articlePath?: string;
17
16
  readonly conversionTable?: [string, string][];
18
17
  readonly redirects?: [string, string][];
18
+ readonly interwiki: string[];
19
+ server?: string;
19
20
  }
20
21
  export type ConfigData = Omit<Config, 'excludes'>;
21
22
  export type TokenTypes = 'root' | 'plain' | 'redirect' | 'redirect-syntax' | 'redirect-target' | 'translate' | 'translate-attr' | 'translate-inner' | 'tvar' | 'tvar-name' | 'onlyinclude' | 'noinclude' | 'include' | 'comment' | 'ext' | 'ext-attrs' | 'ext-attr-dirty' | 'ext-attr' | 'attr-key' | 'attr-value' | 'ext-inner' | 'arg' | 'arg-name' | 'arg-default' | 'hidden' | 'magic-word' | 'magic-word-name' | 'invoke-function' | 'invoke-module' | 'template' | 'template-name' | 'parameter' | 'parameter-key' | 'parameter-value' | 'heading' | 'heading-title' | 'heading-trail' | 'html' | 'html-attrs' | 'html-attr-dirty' | 'html-attr' | 'table' | 'tr' | 'td' | 'table-syntax' | 'table-attrs' | 'table-attr-dirty' | 'table-attr' | 'table-inter' | 'td-inner' | 'hr' | 'double-underscore' | 'link' | 'link-target' | 'link-text' | 'category' | 'file' | 'gallery-image' | 'imagemap-image' | 'image-parameter' | 'quote' | 'ext-link' | 'ext-link-text' | 'ext-link-url' | 'free-ext-link' | 'magic-link' | 'list' | 'dd' | 'converter' | 'converter-flags' | 'converter-flag' | 'converter-rule' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'param-line' | 'imagemap-link' | 'list-range';
@@ -47,7 +48,7 @@ export declare const stages: {
47
48
  'list-range': number;
48
49
  };
49
50
  export type Stage = keyof typeof stages;
50
- export declare const rules: readonly ["arg-in-ext", "blank-alt", "bold-header", "format-leakage", "fostered-content", "h1", "illegal-attr", "insecure-style", "invalid-gallery", "invalid-imagemap", "invalid-invoke", "invalid-isbn", "invalid-json", "invalid-url", "lonely-apos", "lonely-bracket", "lonely-http", "nested-link", "no-arg", "no-duplicate", "no-ignored", "obsolete-attr", "obsolete-tag", "parsing-order", "pipe-like", "syntax-like", "table-layout", "tag-like", "unbalanced-header", "unclosed-comment", "unclosed-quote", "unclosed-table", "unescaped", "unknown-page", "unmatched-tag", "unterminated-url", "url-encoding", "var-anchor", "void-ext", "invalid-css", "invalid-math"];
51
+ export declare const rules: readonly ["arg-in-ext", "blank-alt", "bold-header", "format-leakage", "fostered-content", "h1", "illegal-attr", "insecure-style", "invalid-gallery", "invalid-imagemap", "invalid-invoke", "invalid-isbn", "invalid-json", "invalid-url", "lonely-apos", "lonely-bracket", "lonely-http", "nested-link", "no-arg", "no-duplicate", "no-ignored", "obsolete-attr", "obsolete-tag", "parsing-order", "pipe-like", "required-attr", "syntax-like", "table-layout", "tag-like", "unbalanced-header", "unclosed-comment", "unclosed-quote", "unclosed-table", "unescaped", "unknown-page", "unmatched-tag", "unterminated-url", "url-encoding", "var-anchor", "void-ext", "invalid-css", "invalid-math"];
51
52
  export declare namespace LintError {
52
53
  type Severity = 'error' | 'warning';
53
54
  type Rule = typeof rules[number];
@@ -298,8 +299,9 @@ export interface LanguageService {
298
299
  [Symbol.dispose](): void;
299
300
  }
300
301
  export type SeverityLevel = 0 | 1 | 2 | false | 'off' | 'warning' | 'error';
301
- export type LintConfigValue = SeverityLevel | [SeverityLevel, Record<string, SeverityLevel>?];
302
- export type LintRuleConfig = Partial<Record<LintError.Rule, LintConfigValue>>;
302
+ export type FullLintConfigValue = [SeverityLevel, Record<string, SeverityLevel>?];
303
+ export type LintConfigValue = SeverityLevel | FullLintConfigValue | Record<string, SeverityLevel>;
304
+ export type LintRuleConfig<T = LintConfigValue> = Partial<Record<LintError.Rule, T>>;
303
305
  export interface FullLintConfig {
304
306
  rules: LintRuleConfig;
305
307
  configurationComment?: string;
@@ -315,9 +317,9 @@ export interface LintConfiguration extends FullLintConfig {
315
317
  rules: LintRuleConfiguration;
316
318
  getSeverity(rule: LintError.Rule, key?: string): LintError.Severity | false;
317
319
  }
320
+ export type MaxStage = number | Stage | Stage[];
318
321
  export interface Parser {
319
- config: string | // eslint-disable-line @stylistic/operator-linebreak
320
- ConfigData;
322
+ config: string | ConfigData;
321
323
  i18n: Record<string, string> | string | undefined;
322
324
  /** @since v1.22.0 */
323
325
  lintConfig: LintConfig;
@@ -338,8 +340,8 @@ export interface Parser {
338
340
  * @param maxStage max stage for parsing / 最大解析层级
339
341
  * @param page page name / 页面名称
340
342
  */
341
- parse(wikitext: string, include?: boolean, maxStage?: number | Stage | Stage[], config?: Config, page?: string): Token;
342
- parse(wikitext: string, page: string, include?: boolean, maxStage?: number | Stage | Stage[], config?: Config): Token;
343
+ parse(wikitext: string, include?: boolean, maxStage?: MaxStage, config?: Config, page?: string): Token;
344
+ parse(wikitext: string, page: string, include?: boolean, maxStage?: MaxStage, config?: Config): Token;
343
345
  /**
344
346
  * Create a language server
345
347
  *
package/dist/base.js CHANGED
@@ -60,6 +60,7 @@ exports.rules = (() => {
60
60
  'obsolete-tag',
61
61
  'parsing-order',
62
62
  'pipe-like',
63
+ 'required-attr',
63
64
  'syntax-like',
64
65
  'table-layout',
65
66
  'tag-like',
package/dist/base.mjs CHANGED
@@ -57,6 +57,7 @@ const rules = /* @__PURE__ */ (() => {
57
57
  "obsolete-tag",
58
58
  "parsing-order",
59
59
  "pipe-like",
60
+ "required-attr",
60
61
  "syntax-like",
61
62
  "table-layout",
62
63
  "tag-like",
@@ -40,7 +40,7 @@ const filterGadget = (id) => {
40
40
  const n = Number(id);
41
41
  return n < 2300 || n > 2303; // Gadget, Gadget talk, Gadget definition, Gadget definition talk
42
42
  };
43
- const pkg = "wikiparser-node", version = "1.39.1";
43
+ const pkg = "wikiparser-node", version = "1.41.0";
44
44
  /**
45
45
  * Get the parser configuration for a Wikimedia Foundation project.
46
46
  * @param site site nickname
@@ -78,13 +78,7 @@ exports.default = async (site, url, user, force, internal) => {
78
78
  'User-Agent': `${pkg}/${version} (https://www.npmjs.com/package/${pkg}; ${user}) Node.js/${process.version}`,
79
79
  },
80
80
  }
81
- : undefined, m = await (await fetch(`${url}/load.php?modules=ext.CodeMirror.data|ext.CodeMirror`, headers)).text(), params = {
82
- action: 'query',
83
- meta: 'siteinfo',
84
- siprop: 'general|magicwords|functionhooks|namespaces|namespacealiases',
85
- format: 'json',
86
- formatversion: '2',
87
- }, { general: { articlepath, variants, langconversion }, magicwords, namespaces, namespacealiases, functionhooks, } = (await (await fetch(`${url}/api.php?${new URLSearchParams(params).toString()}`, headers)).json()).query, tempFile = path_1.default.join(__dirname, 'mw.js');
81
+ : undefined, m = await (await fetch(`${url}/load.php?modules=ext.CodeMirror.data|ext.CodeMirror`, headers)).text(), tempFile = path_1.default.join(__dirname, 'mw.js');
88
82
  fs_1.default.writeFileSync(tempFile, m);
89
83
  const { stdout, stderr } = (0, child_process_1.spawnSync)(process.execPath, [
90
84
  '-r',
@@ -108,13 +102,19 @@ exports.default = async (site, url, user, force, internal) => {
108
102
  catch {
109
103
  throw new RangeError('Extension:CodeMirror is not installed!');
110
104
  }
111
- const ns = Object.entries(namespaces).filter(([id]) => filterGadget(id))
105
+ const params = {
106
+ action: 'query',
107
+ meta: 'siteinfo',
108
+ siprop: `general|magicwords|namespaces|namespacealiases${mwConfig.functionHooks ? '' : '|functionhooks'}`,
109
+ format: 'json',
110
+ formatversion: '2',
111
+ }, { general: { articlepath, server, variants, langconversion }, magicwords, namespaces, namespacealiases, functionhooks, } = (await (await fetch(`${url}/api.php?${new URLSearchParams(params).toString()}`, headers)).json()).query, ns = Object.entries(namespaces).filter(([id]) => filterGadget(id))
112
112
  .flatMap(([id, { name, canonical = '' }]) => [
113
113
  [id, name],
114
114
  ...name === canonical ? [] : [[id, canonical]],
115
115
  ]), config = {
116
116
  ...(0, cm_util_1.getParserConfig)(require(path_1.default.join(dir, 'minimum.json')), mwConfig),
117
- ...(0, cm_util_1.getKeywords)(magicwords),
117
+ ...!(mwConfig.imageKeywords && mwConfig.redirection) && (0, cm_util_1.getKeywords)(magicwords),
118
118
  variants: langconversion ? (0, cm_util_1.getVariants)(variants) : [],
119
119
  namespaces: Object.fromEntries(ns),
120
120
  nsid: Object.fromEntries([
@@ -122,6 +122,7 @@ exports.default = async (site, url, user, force, internal) => {
122
122
  ...namespacealiases.filter(({ id }) => filterGadget(id)).map(({ id, alias }) => [alias.toLowerCase(), id]),
123
123
  ]),
124
124
  articlePath: articlepath,
125
+ server,
125
126
  }, { doubleUnderscore, parserFunction, variable } = config;
126
127
  doubleUnderscore[0] = [];
127
128
  doubleUnderscore[1] = [];
package/dist/index.d.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  import { LintConfiguration } from './lib/lintConfig';
2
2
  import { Title } from './lib/title';
3
- import type { Config, ConfigData, LintError, LintConfig, TokenTypes, Parser as ParserBase, Stage, AST } from './base';
3
+ import type { MaxStage, Config, ConfigData, LintError, LintConfig, TokenTypes, Parser as ParserBase, AST } from './base';
4
4
  import type { TitleOptions } from './lib/title';
5
5
  import type { LanguageService, QuickFixData } from './lib/lsp';
6
6
  import type { Token, FunctionHook, TagHook } from './internal';
7
- import type { AstRange } from './lib/range';
8
7
  declare interface Parser extends ParserBase {
9
8
  default: Parser;
10
9
  /** @since v1.5.1 */
@@ -34,8 +33,8 @@ declare interface Parser extends ParserBase {
34
33
  * @param include whether to be transcluded / 是否嵌入
35
34
  */
36
35
  normalizeTitle(title: string, defaultNs?: number, include?: boolean, config?: Config): Title;
37
- parse(wikitext: string, include?: boolean, maxStage?: number | Stage | Stage[], config?: Config, page?: string): Token;
38
- parse(wikitext: string, page: string, include?: boolean, maxStage?: number | Stage | Stage[], config?: Config): Token;
36
+ parse(wikitext: string, include?: boolean, maxStage?: MaxStage, config?: Config, page?: string): Token;
37
+ parse(wikitext: string, page: string, include?: boolean, maxStage?: MaxStage, config?: Config): Token;
39
38
  /**
40
39
  * Create a language server
41
40
  *
@@ -122,6 +121,7 @@ declare const Parser: Parser;
122
121
  // @ts-expect-error mixed export styles
123
122
  export = Parser;
124
123
  export default Parser;
125
- export type { Config, ConfigData, LintConfig, LintError, TokenTypes, LanguageService, QuickFixData, Title, AST, AstRange, };
124
+ export type { Config, ConfigData, LintConfig, LintError, TokenTypes, LanguageService, QuickFixData, Title, AST, };
126
125
  export type * from './internal';
126
+ export type { AstRange } from './lib/range';
127
127
  declare global { type WikiParserAcceptable = Record<string, any>; }