wikilint 2.4.0 → 2.4.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.
Files changed (99) hide show
  1. package/config/default.json +18 -3
  2. package/config/enwiki.json +411 -0
  3. package/dist/index.js +3 -6
  4. package/dist/lib/element.d.ts +6 -0
  5. package/dist/lib/element.js +25 -0
  6. package/dist/lib/node.d.ts +1 -0
  7. package/dist/lib/text.d.ts +1 -0
  8. package/dist/lib/text.js +13 -4
  9. package/dist/parser/braces.js +3 -0
  10. package/dist/parser/commentAndExt.js +5 -0
  11. package/dist/parser/converter.js +1 -0
  12. package/dist/parser/externalLinks.js +1 -0
  13. package/dist/parser/hrAndDoubleUnderscore.js +3 -0
  14. package/dist/parser/html.js +4 -1
  15. package/dist/parser/links.js +1 -0
  16. package/dist/parser/list.js +2 -0
  17. package/dist/parser/magicLinks.js +1 -0
  18. package/dist/parser/quotes.js +1 -0
  19. package/dist/parser/table.js +4 -0
  20. package/dist/src/arg.d.ts +1 -1
  21. package/dist/src/attribute.d.ts +2 -1
  22. package/dist/src/attributes.d.ts +1 -1
  23. package/dist/src/attributes.js +3 -1
  24. package/dist/src/converter.d.ts +1 -1
  25. package/dist/src/converter.js +8 -2
  26. package/dist/src/converterFlags.d.ts +2 -1
  27. package/dist/src/converterRule.d.ts +1 -1
  28. package/dist/src/extLink.d.ts +5 -1
  29. package/dist/src/extLink.js +10 -0
  30. package/dist/src/gallery.d.ts +2 -1
  31. package/dist/src/gallery.js +3 -0
  32. package/dist/src/heading.d.ts +2 -1
  33. package/dist/src/hidden.d.ts +0 -2
  34. package/dist/src/html.d.ts +2 -1
  35. package/dist/src/imageParameter.d.ts +2 -1
  36. package/dist/src/imagemap.d.ts +1 -1
  37. package/dist/src/imagemap.js +4 -0
  38. package/dist/src/imagemapLink.d.ts +1 -1
  39. package/dist/src/imagemapLink.js +5 -1
  40. package/dist/src/index.d.ts +1 -0
  41. package/dist/src/index.js +12 -12
  42. package/dist/src/link/base.d.ts +1 -0
  43. package/dist/src/link/category.d.ts +1 -1
  44. package/dist/src/link/category.js +0 -1
  45. package/dist/src/link/file.d.ts +2 -1
  46. package/dist/src/link/file.js +3 -2
  47. package/dist/src/link/galleryImage.d.ts +6 -3
  48. package/dist/src/link/galleryImage.js +0 -1
  49. package/dist/src/link/index.d.ts +1 -1
  50. package/dist/src/link/index.js +0 -1
  51. package/dist/src/magicLink.d.ts +1 -1
  52. package/dist/src/magicLink.js +1 -1
  53. package/dist/src/nested.d.ts +1 -1
  54. package/dist/src/nested.js +4 -1
  55. package/dist/src/nowiki/comment.d.ts +1 -3
  56. package/dist/src/nowiki/comment.js +0 -1
  57. package/dist/src/nowiki/dd.d.ts +1 -1
  58. package/dist/src/nowiki/dd.js +0 -1
  59. package/dist/src/nowiki/doubleUnderscore.d.ts +1 -3
  60. package/dist/src/nowiki/doubleUnderscore.js +0 -1
  61. package/dist/src/nowiki/hr.d.ts +1 -1
  62. package/dist/src/nowiki/hr.js +0 -1
  63. package/dist/src/nowiki/index.d.ts +1 -1
  64. package/dist/src/nowiki/index.js +0 -1
  65. package/dist/src/nowiki/list.d.ts +1 -1
  66. package/dist/src/nowiki/list.js +0 -1
  67. package/dist/src/nowiki/listBase.d.ts +1 -1
  68. package/dist/src/nowiki/listBase.js +0 -1
  69. package/dist/src/nowiki/noinclude.d.ts +1 -3
  70. package/dist/src/nowiki/noinclude.js +0 -1
  71. package/dist/src/nowiki/quote.d.ts +1 -1
  72. package/dist/src/nowiki/quote.js +0 -1
  73. package/dist/src/paramTag/index.d.ts +1 -1
  74. package/dist/src/paramTag/index.js +1 -1
  75. package/dist/src/paramTag/inputbox.d.ts +1 -1
  76. package/dist/src/paramTag/inputbox.js +0 -1
  77. package/dist/src/parameter.d.ts +1 -1
  78. package/dist/src/pre.d.ts +1 -1
  79. package/dist/src/pre.js +2 -0
  80. package/dist/src/table/base.js +3 -1
  81. package/dist/src/table/index.d.ts +1 -1
  82. package/dist/src/table/index.js +0 -1
  83. package/dist/src/table/td.d.ts +2 -1
  84. package/dist/src/table/td.js +0 -1
  85. package/dist/src/table/tr.d.ts +1 -1
  86. package/dist/src/table/tr.js +0 -1
  87. package/dist/src/table/trBase.js +1 -0
  88. package/dist/src/tagPair/ext.d.ts +1 -1
  89. package/dist/src/tagPair/ext.js +18 -2
  90. package/dist/src/tagPair/include.d.ts +1 -3
  91. package/dist/src/tagPair/index.d.ts +3 -0
  92. package/dist/src/tagPair/index.js +5 -0
  93. package/dist/src/transclude.d.ts +2 -1
  94. package/dist/src/transclude.js +1 -0
  95. package/dist/util/string.js +3 -1
  96. package/i18n/zh-hans.json +4 -3
  97. package/i18n/zh-hant.json +5 -4
  98. package/package.json +14 -13
  99. package/dist/bin/declaration.js +0 -27
@@ -31,6 +31,7 @@
31
31
  "mapframe",
32
32
  "maplink",
33
33
  "math",
34
+ "phonos",
34
35
  "quiz",
35
36
  "section",
36
37
  "source",
@@ -139,6 +140,10 @@
139
140
  "711": "TimedText talk",
140
141
  "828": "Module",
141
142
  "829": "Module talk",
143
+ "2300": "Gadget",
144
+ "2301": "Gadget talk",
145
+ "2302": "Gadget definition",
146
+ "2303": "Gadget definition talk",
142
147
  "2600": "Topic"
143
148
  },
144
149
  "nsid": {
@@ -295,7 +300,11 @@
295
300
  "模組討論": 829,
296
301
  "模组对话": 829,
297
302
  "模组讨论": 829,
298
- "モジュール・トーク": 829
303
+ "モジュール・トーク": 829,
304
+ "gadget": 2300,
305
+ "gadget talk": 2301,
306
+ "gadget definition": 2302,
307
+ "gadget definition talk": 2303
299
308
  },
300
309
  "parserFunction": [
301
310
  {
@@ -414,6 +423,7 @@
414
423
  "#rel2abs": "rel2abs",
415
424
  "#标题组成部分": "titleparts",
416
425
  "#titleparts": "titleparts",
426
+ "pendingchangelevel": "pendingchangelevel",
417
427
  "#categorytree": "categorytree",
418
428
  "#分類樹": "categorytree",
419
429
  "#分类树": "categorytree",
@@ -463,6 +473,7 @@
463
473
  "#lst": "lst",
464
474
  "#lsth": "lsth",
465
475
  "#lstx": "lstx",
476
+ "#assessment": "assessment",
466
477
  "#mentor": "mentor",
467
478
  "#property": "property",
468
479
  "#屬性": "property",
@@ -606,6 +617,7 @@
606
617
  "显示标题",
607
618
  "顯示標題",
608
619
  "DISPLAYTITLE",
620
+ "SHORTDESC",
609
621
  "!",
610
622
  "本月",
611
623
  "本月2",
@@ -729,7 +741,9 @@
729
741
  "無目錄",
730
742
  "toc",
731
743
  "目录",
732
- "目錄"
744
+ "目錄",
745
+ "archivedtalk",
746
+ "notalk"
733
747
  ],
734
748
  [
735
749
  "EXPECTUNUSEDCATEGORY",
@@ -816,7 +830,8 @@
816
830
  "page=$1": "page",
817
831
  "page $1": "page",
818
832
  "页数=$1": "page",
819
- "$1页": "page"
833
+ "$1页": "page",
834
+ "lossy=$1": "lossy"
820
835
  },
821
836
  "variants": [
822
837
  "zh",
@@ -0,0 +1,411 @@
1
+ {
2
+ "ext": [
3
+ "nowiki",
4
+ "pre",
5
+ "gallery",
6
+ "indicator",
7
+ "poem",
8
+ "ref",
9
+ "references",
10
+ "categorytree",
11
+ "charinsert",
12
+ "imagemap",
13
+ "inputbox",
14
+ "templatestyles",
15
+ "score",
16
+ "ce",
17
+ "chem",
18
+ "graph",
19
+ "hiero",
20
+ "langconvert",
21
+ "mapframe",
22
+ "maplink",
23
+ "math",
24
+ "phonos",
25
+ "section",
26
+ "source",
27
+ "syntaxhighlight",
28
+ "templatedata",
29
+ "timeline"
30
+ ],
31
+ "html": [
32
+ [
33
+ "b",
34
+ "bdi",
35
+ "del",
36
+ "i",
37
+ "ins",
38
+ "u",
39
+ "font",
40
+ "big",
41
+ "small",
42
+ "sub",
43
+ "sup",
44
+ "h1",
45
+ "h2",
46
+ "h3",
47
+ "h4",
48
+ "h5",
49
+ "h6",
50
+ "cite",
51
+ "code",
52
+ "em",
53
+ "s",
54
+ "strike",
55
+ "strong",
56
+ "tt",
57
+ "var",
58
+ "div",
59
+ "center",
60
+ "blockquote",
61
+ "ol",
62
+ "ul",
63
+ "dl",
64
+ "table",
65
+ "caption",
66
+ "pre",
67
+ "ruby",
68
+ "rb",
69
+ "rp",
70
+ "rt",
71
+ "rtc",
72
+ "p",
73
+ "span",
74
+ "abbr",
75
+ "dfn",
76
+ "kbd",
77
+ "samp",
78
+ "data",
79
+ "time",
80
+ "mark",
81
+ "tr",
82
+ "td",
83
+ "th",
84
+ "q",
85
+ "bdo"
86
+ ],
87
+ [
88
+ "li",
89
+ "dt",
90
+ "dd"
91
+ ],
92
+ [
93
+ "br",
94
+ "wbr",
95
+ "hr",
96
+ "meta",
97
+ "link"
98
+ ]
99
+ ],
100
+ "namespaces": {
101
+ "-2": "Media",
102
+ "-1": "Special",
103
+ "0": "",
104
+ "1": "Talk",
105
+ "2": "User",
106
+ "3": "User talk",
107
+ "4": "Project",
108
+ "5": "Project talk",
109
+ "6": "File",
110
+ "7": "File talk",
111
+ "8": "MediaWiki",
112
+ "9": "MediaWiki talk",
113
+ "10": "Template",
114
+ "11": "Template talk",
115
+ "12": "Help",
116
+ "13": "Help talk",
117
+ "14": "Category",
118
+ "15": "Category talk",
119
+ "100": "Portal",
120
+ "101": "Portal talk",
121
+ "118": "Draft",
122
+ "119": "Draft talk",
123
+ "710": "TimedText",
124
+ "711": "TimedText talk",
125
+ "828": "Module",
126
+ "829": "Module talk",
127
+ "2300": "Gadget",
128
+ "2301": "Gadget talk",
129
+ "2302": "Gadget definition",
130
+ "2303": "Gadget definition talk"
131
+ },
132
+ "nsid": {
133
+ "": 0,
134
+ "media": -2,
135
+ "special": -1,
136
+ "talk": 1,
137
+ "user": 2,
138
+ "user talk": 3,
139
+ "wp": 4,
140
+ "wikipedia": 4,
141
+ "project": 4,
142
+ "wt": 5,
143
+ "wikipedia talk": 5,
144
+ "project talk": 5,
145
+ "file": 6,
146
+ "image": 6,
147
+ "file talk": 7,
148
+ "image talk": 7,
149
+ "mediawiki": 8,
150
+ "mediawiki talk": 9,
151
+ "template": 10,
152
+ "template talk": 11,
153
+ "help": 12,
154
+ "help talk": 13,
155
+ "category": 14,
156
+ "category talk": 15,
157
+ "portal": 100,
158
+ "portal talk": 101,
159
+ "draft": 118,
160
+ "draft talk": 119,
161
+ "timedtext": 710,
162
+ "timedtext talk": 711,
163
+ "module": 828,
164
+ "module talk": 829,
165
+ "gadget": 2300,
166
+ "gadget talk": 2301,
167
+ "gadget definition": 2302,
168
+ "gadget definition talk": 2303
169
+ },
170
+ "parserFunction": [
171
+ {
172
+ "ns": "ns",
173
+ "nse": "nse",
174
+ "urlencode": "urlencode",
175
+ "lcfirst": "lcfirst",
176
+ "ucfirst": "ucfirst",
177
+ "lc": "lc",
178
+ "uc": "uc",
179
+ "localurl": "localurl",
180
+ "localurle": "localurle",
181
+ "fullurl": "fullurl",
182
+ "fullurle": "fullurle",
183
+ "canonicalurl": "canonicalurl",
184
+ "canonicalurle": "canonicalurle",
185
+ "formatnum": "formatnum",
186
+ "grammar": "grammar",
187
+ "gender": "gender",
188
+ "plural": "plural",
189
+ "bidi": "bidi",
190
+ "#language": "language",
191
+ "padleft": "padleft",
192
+ "padright": "padright",
193
+ "anchorencode": "anchorencode",
194
+ "filepath": "filepath",
195
+ "pageid": "pageid",
196
+ "int": "int",
197
+ "#special": "special",
198
+ "#speciale": "speciale",
199
+ "#tag": "tag",
200
+ "#formatdate": "formatdate",
201
+ "#dateformat": "formatdate",
202
+ "#invoke": "invoke",
203
+ "#if": "if",
204
+ "#ifeq": "ifeq",
205
+ "#switch": "switch",
206
+ "#ifexist": "ifexist",
207
+ "#ifexpr": "ifexpr",
208
+ "#iferror": "iferror",
209
+ "#time": "time",
210
+ "#timel": "timel",
211
+ "#expr": "expr",
212
+ "#rel2abs": "rel2abs",
213
+ "#titleparts": "titleparts",
214
+ "pendingchangelevel": "pendingchangelevel",
215
+ "#categorytree": "categorytree",
216
+ "articlepath": "articlepath",
217
+ "server": "server",
218
+ "servername": "servername",
219
+ "scriptpath": "scriptpath",
220
+ "stylepath": "stylepath",
221
+ "msgnw": "msgnw",
222
+ "#related": "related",
223
+ "#babel": "babel",
224
+ "#commaseparatedlist": "commaseparatedlist",
225
+ "#coordinates": "coordinates",
226
+ "#lst": "lst",
227
+ "#lsth": "lsth",
228
+ "#lstx": "lstx",
229
+ "#assessment": "assessment",
230
+ "#mentor": "mentor",
231
+ "#property": "property",
232
+ "#target": "target",
233
+ "#section": "section",
234
+ "#section-x": "section-x",
235
+ "#section-h": "section-h",
236
+ "noexternallanglinks": "noexternallanglinks",
237
+ "#statements": "statements",
238
+ "numberofwikis": "numberofwikis",
239
+ "wbreponame": "wbreponame"
240
+ },
241
+ [
242
+ "NUMBEROFPAGES",
243
+ "NUMBEROFUSERS",
244
+ "NUMBEROFACTIVEUSERS",
245
+ "NUMBEROFARTICLES",
246
+ "NUMBEROFFILES",
247
+ "NUMBEROFADMINS",
248
+ "NUMBERINGROUP",
249
+ "NUMINGROUP",
250
+ "NUMBEROFEDITS",
251
+ "DEFAULTSORT",
252
+ "DEFAULTSORTKEY",
253
+ "DEFAULTCATEGORYSORT",
254
+ "PAGESINCATEGORY",
255
+ "PAGESINCAT",
256
+ "PAGESIZE",
257
+ "PROTECTIONLEVEL",
258
+ "PROTECTIONEXPIRY",
259
+ "NAMESPACEE",
260
+ "NAMESPACENUMBER",
261
+ "TALKSPACE",
262
+ "TALKSPACEE",
263
+ "SUBJECTSPACE",
264
+ "ARTICLESPACE",
265
+ "SUBJECTSPACEE",
266
+ "ARTICLESPACEE",
267
+ "PAGENAME",
268
+ "PAGENAMEE",
269
+ "FULLPAGENAME",
270
+ "FULLPAGENAMEE",
271
+ "ROOTPAGENAME",
272
+ "ROOTPAGENAMEE",
273
+ "BASEPAGENAME",
274
+ "BASEPAGENAMEE",
275
+ "SUBPAGENAME",
276
+ "SUBPAGENAMEE",
277
+ "TALKPAGENAME",
278
+ "TALKPAGENAMEE",
279
+ "SUBJECTPAGENAME",
280
+ "ARTICLEPAGENAME",
281
+ "SUBJECTPAGENAMEE",
282
+ "ARTICLEPAGENAMEE",
283
+ "REVISIONID",
284
+ "REVISIONDAY",
285
+ "REVISIONDAY2",
286
+ "REVISIONMONTH",
287
+ "REVISIONMONTH1",
288
+ "REVISIONYEAR",
289
+ "REVISIONTIMESTAMP",
290
+ "REVISIONUSER",
291
+ "CASCADINGSOURCES",
292
+ "NAMESPACE",
293
+ "DISPLAYTITLE",
294
+ "SHORTDESC",
295
+ "!",
296
+ "CURRENTMONTH",
297
+ "CURRENTMONTH2",
298
+ "CURRENTMONTH1",
299
+ "CURRENTMONTHNAME",
300
+ "CURRENTMONTHNAMEGEN",
301
+ "CURRENTMONTHABBREV",
302
+ "CURRENTDAY",
303
+ "CURRENTDAY2",
304
+ "CURRENTDAYNAME",
305
+ "CURRENTYEAR",
306
+ "CURRENTTIME",
307
+ "CURRENTHOUR",
308
+ "LOCALMONTH",
309
+ "LOCALMONTH2",
310
+ "LOCALMONTH1",
311
+ "LOCALMONTHNAME",
312
+ "LOCALMONTHNAMEGEN",
313
+ "LOCALMONTHABBREV",
314
+ "LOCALDAY",
315
+ "LOCALDAY2",
316
+ "LOCALDAYNAME",
317
+ "LOCALYEAR",
318
+ "LOCALTIME",
319
+ "LOCALHOUR",
320
+ "SITENAME",
321
+ "CURRENTWEEK",
322
+ "CURRENTDOW",
323
+ "LOCALWEEK",
324
+ "LOCALDOW",
325
+ "REVISIONSIZE",
326
+ "CURRENTVERSION",
327
+ "CURRENTTIMESTAMP",
328
+ "LOCALTIMESTAMP",
329
+ "DIRECTIONMARK",
330
+ "DIRMARK",
331
+ "CONTENTLANGUAGE",
332
+ "CONTENTLANG",
333
+ "PAGELANGUAGE",
334
+ "="
335
+ ],
336
+ [
337
+ "msg",
338
+ "raw"
339
+ ],
340
+ [
341
+ "subst",
342
+ "safesubst"
343
+ ]
344
+ ],
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
+ ],
359
+ [
360
+ "EXPECTUNUSEDCATEGORY",
361
+ "DISAMBIG",
362
+ "HIDDENCAT",
363
+ "INDEX",
364
+ "NEWSECTIONLINK",
365
+ "NOINDEX",
366
+ "NONEWSECTIONLINK",
367
+ "STATICREDIRECT",
368
+ "NOGLOBAL",
369
+ "EXPECTED_UNCONNECTED_PAGE"
370
+ ]
371
+ ],
372
+ "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:",
373
+ "interwiki": [],
374
+ "img": {
375
+ "thumbnail": "thumbnail",
376
+ "thumb": "thumbnail",
377
+ "thumbnail=$1": "manualthumb",
378
+ "thumb=$1": "manualthumb",
379
+ "left": "left",
380
+ "right": "right",
381
+ "none": "none",
382
+ "$1px": "width",
383
+ "center": "center",
384
+ "centre": "center",
385
+ "framed": "framed",
386
+ "enframed": "framed",
387
+ "frame": "framed",
388
+ "frameless": "frameless",
389
+ "upright": "upright",
390
+ "upright=$1": "manual-upright",
391
+ "upright $1": "manual-upright",
392
+ "border": "border",
393
+ "alt=$1": "alt",
394
+ "class=$1": "class",
395
+ "link=$1": "link",
396
+ "baseline": "baseline",
397
+ "sub": "sub",
398
+ "super": "super",
399
+ "sup": "super",
400
+ "top": "top",
401
+ "text-top": "text-top",
402
+ "middle": "middle",
403
+ "bottom": "bottom",
404
+ "text-bottom": "text-bottom",
405
+ "lang=$1": "lang",
406
+ "page=$1": "page",
407
+ "page $1": "page",
408
+ "lossy=$1": "lossy"
409
+ },
410
+ "variants": []
411
+ }
package/dist/index.js CHANGED
@@ -4,17 +4,13 @@ const fs = require("fs");
4
4
  const path = require("path");
5
5
  const debug_1 = require("./util/debug");
6
6
  const constants_1 = require("./util/constants");
7
+ const string_1 = require("./util/string");
7
8
  /**
8
9
  * 从根路径require
9
10
  * @param file 文件名
10
11
  * @param dir 子路径
11
12
  */
12
13
  const rootRequire = (file, dir) => require(file.startsWith('/') ? file : `../${file.includes('/') ? '' : dir}${file}`);
13
- /**
14
- * 清理解析专用的不可见字符
15
- * @param text 源文本
16
- */
17
- const tidy = (text) => text.replace(/[\0\x7F]/gu, '');
18
14
  // eslint-disable-next-line @typescript-eslint/no-redeclare
19
15
  const Parser = {
20
16
  config: 'default',
@@ -50,9 +46,10 @@ const Parser = {
50
46
  },
51
47
  /** @implements */
52
48
  parse(wikitext, include, maxStage = constants_1.MAX_STAGE, config = Parser.getConfig()) {
49
+ wikitext = (0, string_1.tidy)(wikitext);
53
50
  const { Token } = require('./src/index');
54
51
  const root = debug_1.Shadow.run(() => {
55
- const token = new Token(tidy(wikitext), config);
52
+ const token = new Token(wikitext, config);
56
53
  try {
57
54
  return token.parse(maxStage, include);
58
55
  }
@@ -3,6 +3,7 @@ import type { LintError } from '../base';
3
3
  import type { AstNodes, Token } from '../internal';
4
4
  /** 类似HTMLElement */
5
5
  export declare abstract class AstElement extends AstNode {
6
+ #private;
6
7
  readonly name?: string;
7
8
  readonly data: undefined;
8
9
  /** 子节点总数 */
@@ -30,6 +31,11 @@ export declare abstract class AstElement extends AstNode {
30
31
  * @param selector 选择器
31
32
  */
32
33
  closest<T = Token>(selector: string): T | undefined;
34
+ /**
35
+ * 符合选择器的所有后代节点
36
+ * @param selector 选择器
37
+ */
38
+ querySelectorAll<T = Token>(selector: string): T[];
33
39
  /**
34
40
  * 在末尾批量插入子节点
35
41
  * @param elements 插入节点
@@ -77,6 +77,31 @@ class AstElement extends node_1.AstNode {
77
77
  }
78
78
  return undefined;
79
79
  }
80
+ /**
81
+ * 符合条件的所有后代节点
82
+ * @param condition 条件
83
+ */
84
+ #getElementsBy(condition) {
85
+ const descendants = [];
86
+ for (const child of this.childNodes) {
87
+ if (child.type === 'text') {
88
+ continue;
89
+ }
90
+ else if (condition(child)) {
91
+ descendants.push(child);
92
+ }
93
+ descendants.push(...child.#getElementsBy(condition));
94
+ }
95
+ return descendants;
96
+ }
97
+ /**
98
+ * 符合选择器的所有后代节点
99
+ * @param selector 选择器
100
+ */
101
+ querySelectorAll(selector) {
102
+ const condition = this.#getCondition(selector);
103
+ return this.#getElementsBy(condition);
104
+ }
80
105
  /**
81
106
  * 在末尾批量插入子节点
82
107
  * @param elements 插入节点
@@ -16,6 +16,7 @@ export interface CaretPosition {
16
16
  }
17
17
  /** 类似Node */
18
18
  export declare abstract class AstNode implements AstNodeBase {
19
+ #private;
19
20
  type: TokenTypes | 'text';
20
21
  data?: string | undefined;
21
22
  readonly childNodes: readonly AstNodes[];
@@ -2,6 +2,7 @@ import { AstNode } from './node';
2
2
  import type { LintError } from '../base';
3
3
  /** 文本节点 */
4
4
  export declare class AstText extends AstNode {
5
+ #private;
5
6
  readonly type = "text";
6
7
  readonly name: undefined;
7
8
  readonly data: string;
package/dist/lib/text.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AstText = void 0;
4
4
  const Parser = require("../index");
5
5
  const node_1 = require("./node");
6
- const errorSyntax = /<\s*\/?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*\])|((?:^|\])[^[]*?)\]+|https?[:/]\/+/giu, errorSyntaxUrl = /<\s*\/?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*\])|((?:^|\])[^[]*?)\]+/giu, disallowedTags = [
6
+ const errorSyntax = /<\s*(?:\/\s*)?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*\])|((?:^|\])[^[]*?)\]+|https?[:/]\/+/giu, errorSyntaxUrl = /<\s*(?:\/\s*)?([a-z]\w*)|\{+|\}+|\[{2,}|\[(?![^[]*\])|((?:^|\])[^[]*?)\]+/giu, disallowedTags = [
7
7
  'html',
8
8
  'head',
9
9
  'style',
@@ -58,10 +58,10 @@ class AstText extends node_1.AstNode {
58
58
  lint(start = this.getAbsoluteIndex()) {
59
59
  const { data, parentNode, nextSibling, previousSibling } = this;
60
60
  const { NowikiToken } = require('../src/nowiki');
61
- const { type, name } = parentNode, nextType = nextSibling?.type, previousType = previousSibling?.type;
61
+ const { type, name } = parentNode, nowiki = name === 'nowiki' || name === 'pre', nextType = nextSibling?.type, nextName = nextSibling?.name, previousType = previousSibling?.type;
62
62
  let errorRegex;
63
63
  if (type === 'ext-inner' && (name === 'pre' || parentNode instanceof NowikiToken)) {
64
- errorRegex = new RegExp(`<\\s*\\/?(${name})\\b`, 'giu');
64
+ errorRegex = new RegExp(`<\\s*(?:\\/\\s*)${nowiki ? '' : '?'}(${name})\\b`, 'giu');
65
65
  }
66
66
  else if (type === 'free-ext-link'
67
67
  || type === 'ext-link-url'
@@ -84,7 +84,16 @@ class AstText extends node_1.AstNode {
84
84
  index += length;
85
85
  error = error.slice(length);
86
86
  }
87
- const startIndex = start + index, lines = data.slice(0, index).split('\n'), startLine = lines.length + top - 1, line = lines[lines.length - 1], startCol = lines.length === 1 ? left + line.length : line.length, { 0: char, length } = error, endIndex = startIndex + length, rootStr = String(root), nextChar = rootStr[endIndex], previousChar = rootStr[startIndex - 1], severity = length > 1 && (char !== '<' || /[\s/>]/u.test(nextChar ?? ''))
87
+ const { 0: char, length } = error;
88
+ if (char === '['
89
+ && type === 'ext-link-text'
90
+ && (/&(?:rbrack|#93|#x5[Dd];);/u.test(data.slice(index + 1))
91
+ || nextType === 'ext'
92
+ && nextName === 'nowiki'
93
+ && nextSibling.innerText?.includes(']'))) {
94
+ continue;
95
+ }
96
+ const startIndex = start + index, lines = data.slice(0, index).split('\n'), startLine = lines.length + top - 1, line = lines[lines.length - 1], startCol = lines.length === 1 ? left + line.length : line.length, endIndex = startIndex + length, rootStr = String(root), nextChar = rootStr[endIndex], previousChar = rootStr[startIndex - 1], severity = length > 1 && (char !== '<' || !nowiki && /[\s/>]/u.test(nextChar ?? ''))
88
97
  || char === '{' && (nextChar === char || previousChar === '-')
89
98
  || char === '}' && (previousChar === char || nextChar === '-')
90
99
  || char === '[' && (nextChar === char
@@ -43,6 +43,7 @@ const parseBraces = (wikitext, config = Parser.getConfig(), accum = []) => {
43
43
  if (rmt) {
44
44
  wikitext = `${wikitext.slice(0, index)}\0${accum.length}h\x7F${wikitext.slice(curIndex)}`;
45
45
  lastIndex = index + 4 + String(accum.length).length;
46
+ // @ts-expect-error abstract class
46
47
  new heading_1.HeadingToken(rmt[1].length, rmt.slice(2), config, accum);
47
48
  }
48
49
  }
@@ -64,6 +65,7 @@ const parseBraces = (wikitext, config = Parser.getConfig(), accum = []) => {
64
65
  let skip = false, ch = 't';
65
66
  if (close.length === 3) {
66
67
  const argParts = parts.map(part => part.join('=')), str = argParts.length > 1 && (0, string_1.removeComment)(argParts[1]).trim();
68
+ // @ts-expect-error abstract class
67
69
  new arg_1.ArgToken(argParts, config, accum);
68
70
  if (str && str.endsWith(':') && subst.includes(str.slice(0, -1).toLowerCase())) {
69
71
  ch = 's';
@@ -71,6 +73,7 @@ const parseBraces = (wikitext, config = Parser.getConfig(), accum = []) => {
71
73
  }
72
74
  else {
73
75
  try {
76
+ // @ts-expect-error abstract class
74
77
  new transclude_1.TranscludeToken(parts[0][0], parts.slice(1), config, accum);
75
78
  const name = (0, string_1.removeComment)(parts[0][0]).trim();
76
79
  if (marks.has(name)) {
@@ -30,6 +30,7 @@ const parseCommentAndExt = (wikitext, config = Parser.getConfig(), accum = [], i
30
30
  * @param text 未被包裹的内容
31
31
  */
32
32
  const noinclude = (text) => {
33
+ // @ts-expect-error abstract class
33
34
  new noinclude_1.NoincludeToken(text, config, accum);
34
35
  str += `\0${accum.length - 1}c\x7F`;
35
36
  };
@@ -65,16 +66,20 @@ const parseCommentAndExt = (wikitext, config = Parser.getConfig(), accum = [], i
65
66
  return wikitext.replace(regex, (substr, name, attr, inner, closing, include, includeAttr, includeInner, includeClosing) => {
66
67
  const str = `\0${accum.length}${name ? 'e' : 'c'}\x7F`;
67
68
  if (name) {
69
+ // @ts-expect-error abstract class
68
70
  new ext_1.ExtToken(name, attr, inner, closing, config, accum);
69
71
  }
70
72
  else if (substr.startsWith('<!--')) {
71
73
  const closed = substr.endsWith('-->');
74
+ // @ts-expect-error abstract class
72
75
  new comment_1.CommentToken(substr.slice(4, closed ? -3 : undefined), closed, config, accum);
73
76
  }
74
77
  else if (include) {
78
+ // @ts-expect-error abstract class
75
79
  new include_1.IncludeToken(include, includeAttr, includeInner, includeClosing, config, accum);
76
80
  }
77
81
  else {
82
+ // @ts-expect-error abstract class
78
83
  new noinclude_1.NoincludeToken(substr, config, accum);
79
84
  }
80
85
  return str;
@@ -19,6 +19,7 @@ const parseConverter = (text, config = Parser.getConfig(), accum = []) => {
19
19
  /;(?=(?:[^;]*?=>)?\s*foo\s*:|(?:\s|\0\d+c\x7F)*$)/u;
20
20
  const top = stack.pop(), { length } = accum, str = text.slice(top.index + 2, index), i = str.indexOf('|'), [flags, raw] = i === -1 ? [[], str] : [str.slice(0, i).split(';'), str.slice(i + 1)], temp = raw.replace(/(&[#a-z\d]+);/giu, '$1\x01'), variants = `(?:${config.variants.join('|')})`, rules = temp.split(new RegExp(`;(?=(?:[^;]*?=>)?\\s*${variants}\\s*:|(?:\\s|\0\\d+c\x7F)*$)`, 'u'))
21
21
  .map(rule => rule.replace(/\x01/gu, ';'));
22
+ // @ts-expect-error abstract class
22
23
  new converter_1.ConverterToken(flags, rules, config, accum);
23
24
  text = `${text.slice(0, top.index)}\0${length}v\x7F${text.slice(index + 2)}`;
24
25
  if (stack.length === 0) {