wikilint 2.48.2 → 3.1.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 (72) hide show
  1. package/README.md +1 -1
  2. package/config/.schema.json +5 -0
  3. package/data/signatures.json +2 -2
  4. package/dist/base.d.mts +4 -2
  5. package/dist/base.d.ts +4 -2
  6. package/dist/base.js +1 -0
  7. package/dist/base.mjs +2 -1
  8. package/dist/bin/config.js +1 -1
  9. package/dist/index.d.ts +1 -3
  10. package/dist/index.js +20 -14
  11. package/dist/internal.d.ts +1 -0
  12. package/dist/lib/document.d.ts +7 -6
  13. package/dist/lib/document.js +3 -1
  14. package/dist/lib/lintConfig.js +1 -0
  15. package/dist/lib/lsp.js +9 -7
  16. package/dist/lib/node.d.ts +0 -4
  17. package/dist/lib/node.js +8 -0
  18. package/dist/lib/text.js +4 -3
  19. package/dist/lib/title.js +6 -1
  20. package/dist/map.d.ts +2 -1
  21. package/dist/parser/commentAndExt.js +1 -1
  22. package/dist/parser/hrAndDoubleUnderscore.js +3 -2
  23. package/dist/parser/table.js +2 -1
  24. package/dist/src/arg.d.ts +1 -1
  25. package/dist/src/arg.js +1 -1
  26. package/dist/src/attributes.d.ts +4 -3
  27. package/dist/src/converter.d.ts +1 -1
  28. package/dist/src/converter.js +1 -1
  29. package/dist/src/converterRule.d.ts +1 -1
  30. package/dist/src/converterRule.js +1 -1
  31. package/dist/src/extLink.d.ts +1 -1
  32. package/dist/src/extLink.js +1 -1
  33. package/dist/src/index.js +54 -58
  34. package/dist/src/link/category.d.ts +1 -1
  35. package/dist/src/link/category.js +1 -1
  36. package/dist/src/link/galleryImage.js +1 -1
  37. package/dist/src/link/index.d.ts +1 -1
  38. package/dist/src/link/index.js +1 -1
  39. package/dist/src/link/redirectTarget.d.ts +1 -1
  40. package/dist/src/link/redirectTarget.js +1 -1
  41. package/dist/src/magicLink.d.ts +4 -3
  42. package/dist/src/magicLink.js +1 -1
  43. package/dist/src/multiLine/gallery.d.ts +4 -4
  44. package/dist/src/multiLine/gallery.js +13 -4
  45. package/dist/src/multiLine/imagemap.d.ts +5 -3
  46. package/dist/src/multiLine/imagemap.js +1 -1
  47. package/dist/src/nested.d.ts +1 -1
  48. package/dist/src/nested.js +1 -1
  49. package/dist/src/nowiki/list.js +6 -3
  50. package/dist/src/nowiki/listBase.d.ts +24 -0
  51. package/dist/src/nowiki/listBase.js +104 -0
  52. package/dist/src/paramLine.d.ts +1 -1
  53. package/dist/src/paramLine.js +1 -1
  54. package/dist/src/pre.d.ts +5 -3
  55. package/dist/src/redirect.d.ts +1 -1
  56. package/dist/src/redirect.js +1 -1
  57. package/dist/src/singleLine/charinsertLine.d.ts +1 -1
  58. package/dist/src/singleLine/charinsertLine.js +1 -1
  59. package/dist/src/table/index.d.ts +2 -2
  60. package/dist/src/table/index.js +1 -1
  61. package/dist/src/table/tr.d.ts +1 -1
  62. package/dist/src/table/tr.js +1 -1
  63. package/dist/src/tag/index.d.ts +7 -5
  64. package/dist/src/tag/index.js +9 -4
  65. package/dist/src/tagPair/ext.js +1 -1
  66. package/dist/src/transclude.d.ts +1 -1
  67. package/dist/src/transclude.js +1 -1
  68. package/dist/util/debug.js +7 -1
  69. package/i18n/en.json +1 -0
  70. package/i18n/zh-hans.json +1 -0
  71. package/i18n/zh-hant.json +1 -0
  72. package/package.json +2 -2
@@ -60,7 +60,7 @@ const getRuleFromTo = (text, type, config, accum) => {
60
60
  * language conversion rule
61
61
  *
62
62
  * 转换规则
63
- * @classdesc `{childNodes: [Token?, AtomToken?, Token]}`
63
+ * @classdesc `{childNodes: [Token] | [Token?, AtomToken, Token]}`
64
64
  */
65
65
  let ConverterRuleToken = (() => {
66
66
  let _classDecorators = [noEscape_1.noEscape];
@@ -5,7 +5,7 @@ import type { Config, LintError } from '../base';
5
5
  * external link
6
6
  *
7
7
  * 外链
8
- * @classdesc `{childNodes: [MagicLinkToken, ?Token]}`
8
+ * @classdesc `{childNodes: [MagicLinkToken, Token?]}`
9
9
  */
10
10
  export declare abstract class ExtLinkToken extends Token {
11
11
  #private;
@@ -48,7 +48,7 @@ const magicLink_1 = require("./magicLink");
48
48
  * external link
49
49
  *
50
50
  * 外链
51
- * @classdesc `{childNodes: [MagicLinkToken, ?Token]}`
51
+ * @classdesc `{childNodes: [MagicLinkToken, Token?]}`
52
52
  */
53
53
  let ExtLinkToken = (() => {
54
54
  let _classDecorators = [(0, padded_1.padded)('[')];
package/dist/src/index.js CHANGED
@@ -1,48 +1,4 @@
1
1
  "use strict";
2
- // PHP解析器的步骤:
3
- // -2. 替换签名和`{{subst:}}`,参见Parser::preSaveTransform;这在revision中不可能保留,可以跳过
4
- // -1. 移除特定字符`\0`和`\x7F`,参见Parser::parse
5
- // 0. 重定向,参见WikitextContentHandler::extractRedirectTargetAndText
6
- // 1. 注释/扩展标签('<'相关),参见Preprocessor_Hash::buildDomTreeArrayFromText和Sanitizer::decodeTagAttributes
7
- // 2. 模板/模板变量/标题,注意rightmost法则,以及`-{`和`[[`可以破坏`{{`或`{{{`语法,
8
- // 参见Preprocessor_Hash::buildDomTreeArrayFromText
9
- // 3. HTML标签(允许不匹配),参见Sanitizer::internalRemoveHtmlTags
10
- // 4. 表格,参见Parser::handleTables
11
- // 5. 水平线、状态开关和余下的标题,参见Parser::internalParse
12
- // 6. 内链,含文件和分类,参见Parser::handleInternalLinks2
13
- // 7. `'`,参见Parser::doQuotes
14
- // 8. 外链,参见Parser::handleExternalLinks
15
- // 9. ISBN、RFC和自由外链,参见Parser::handleMagicLinks
16
- // 10. 段落和列表,参见BlockLevelPass::execute
17
- // 11. 转换,参见LanguageConverter::recursiveConvertTopLevel
18
- // \0\d+.\x7F标记Token:
19
- // !: `{{!}}`专用
20
- // {: `{{(!}}`专用
21
- // }: `{{!)}}`专用
22
- // -: `{{!-}}`专用
23
- // +: `{{!!}}`专用
24
- // ~: `{{=}}`专用
25
- // a: AttributeToken
26
- // b: TableToken
27
- // c: CommentToke
28
- // d: ListToken
29
- // e: ExtToken
30
- // f: ImageParameterToken内的MagicLinkToken
31
- // g: TranslateToken或OnlyincludeToken
32
- // h: HeadingToken
33
- // i: RFC/PMID/ISBN
34
- // l: LinkToken
35
- // m: `{{server}}`、`{{fullurl:}}`、`{{canonicalurl:}}`或`{{filepath:}}`
36
- // n: NoIncludeToken、IncludeToken、TvarToken、DoubleUnderscoreToken或`{{#vardefine:}}`
37
- // o: RedirectToken
38
- // q: QuoteToken
39
- // r: HrToken
40
- // s: `{{{|subst:}}}`
41
- // t: ArgToken或TranscludeToken
42
- // u: `__toc__`
43
- // v: ConverterToken
44
- // w: ExtLinkToken或free-ext-link
45
- // x: HtmlToken
46
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
47
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
48
4
  };
@@ -55,7 +11,7 @@ const debug_1 = require("../util/debug");
55
11
  const index_1 = __importDefault(require("../index"));
56
12
  const element_1 = require("../lib/element");
57
13
  const text_1 = require("../lib/text");
58
- const lintSelectors = ['category', 'html-attr#id,ext-attr#id,table-attr#id'];
14
+ const lintSelectors = ['category', 'html-attr#id,ext-attr#id,table-attr#id', 'ext#indicator'];
59
15
  /**
60
16
  * base class for all tokens
61
17
  *
@@ -302,7 +258,7 @@ class Token extends element_1.AstElement {
302
258
  }
303
259
  const { parseList } = require('../parser/list');
304
260
  const { firstChild, type, name } = this, lines = firstChild.toString().split('\n'), state = { lastPrefix: '' };
305
- let i = type === 'root' || type === 'ext-inner' && name === 'poem' ? 0 : 1;
261
+ let i = type === 'root' || type === 'ext-inner' && (0, debug_1.isIsolated)(name) ? 0 : 1;
306
262
  for (; i < lines.length; i++) {
307
263
  lines[i] = parseList(lines[i], state, this.#config, this.#accum);
308
264
  }
@@ -386,18 +342,24 @@ class Token extends element_1.AstElement {
386
342
  const { lintConfig } = index_1.default, { computeEditInfo, fix: needFix, ignoreDisables, configurationComment } = lintConfig;
387
343
  let errors = super.lint(start, re);
388
344
  if (this.type === 'root') {
389
- const record = new Map(), r = 'no-duplicate', s = ['category', 'id'].map(key => lintConfig.getSeverity(r, key)), wikitext = this.toString(), selector = lintSelectors.filter((_, i) => s[i]).join();
390
- if (selector) {
345
+ const r = 'no-duplicate', s = ['category', 'id', 'indicator'].map(key => lintConfig.getSeverity(r, key)), msgs = ['category', 'id', 'name'], wikitext = this.toString();
346
+ for (let i = 0; i < s.length; i++) {
347
+ const severity = s[i];
348
+ if (!severity) {
349
+ continue;
350
+ }
351
+ const record = new Map(), selector = lintSelectors[i];
391
352
  for (const cat of this.querySelectorAll(selector)) {
392
353
  let key;
393
- if (cat.is('category')) {
354
+ if (i === 0) { // category
394
355
  key = cat.name;
395
356
  }
396
- else {
397
- const value = cat.getValue();
398
- if (value) {
399
- key = `#${value}`;
400
- }
357
+ else if (i === 1) { // id
358
+ key = cat.getValue().replace(/\s+/gu, '_');
359
+ }
360
+ else { // indicator
361
+ key = cat.getAttr('name')
362
+ ?.replace(/\s+/gu, '_');
401
363
  }
402
364
  if (key) {
403
365
  const thisCat = record.get(key);
@@ -410,11 +372,10 @@ class Token extends element_1.AstElement {
410
372
  }
411
373
  }
412
374
  for (const [key, value] of record) {
413
- if (value.size > 1 && !key.startsWith('#mw-customcollapsible-')) {
414
- const isCat = !key.startsWith('#'), msg = `duplicate-${isCat ? 'category' : 'id'}`, severity = s[isCat ? 0 : 1];
375
+ if (value.size > 1 && (i !== 1 || !key.startsWith('mw-customcollapsible-'))) {
415
376
  errors.push(...[...value].map(cat => {
416
- const e = (0, lint_1.generateForSelf)(cat, { start: cat.getAbsoluteIndex() }, r, msg, severity);
417
- if (computeEditInfo && isCat) {
377
+ const e = (0, lint_1.generateForSelf)(cat, { start: cat.getAbsoluteIndex() }, r, `duplicate-${msgs[i]}`, severity);
378
+ if (computeEditInfo && i === 0) {
418
379
  e.suggestions = [(0, lint_1.fixByRemove)(e)];
419
380
  }
420
381
  return e;
@@ -494,5 +455,40 @@ class Token extends element_1.AstElement {
494
455
  }
495
456
  });
496
457
  }
458
+ /**
459
+ * 构建列表
460
+ * @param recursive 是否递归
461
+ */
462
+ #buildLists(recursive) {
463
+ PRINT: for (let i = 0; i < this.length; i++) {
464
+ const child = this.childNodes[i];
465
+ if (child.is('list') || child.is('dd')) {
466
+ child.getRange();
467
+ }
468
+ else if (recursive && child.type !== 'text') {
469
+ child.#buildLists(true);
470
+ }
471
+ }
472
+ }
473
+ /** @private */
474
+ buildLists() {
475
+ PRINT: this.#buildLists(true);
476
+ }
477
+ /** @private */
478
+ concat(elements) {
479
+ PRINT: {
480
+ if (elements.length === 0) {
481
+ return;
482
+ }
483
+ const { childNodes, lastChild } = this, first = elements[0], last = elements.at(-1);
484
+ for (const element of elements) {
485
+ element.setAttribute('parentNode', this);
486
+ }
487
+ lastChild?.setAttribute('nextSibling', first);
488
+ first.setAttribute('previousSibling', lastChild);
489
+ last.setAttribute('nextSibling', undefined);
490
+ this.setAttribute('childNodes', [...childNodes, ...elements]);
491
+ }
492
+ }
497
493
  }
498
494
  exports.Token = Token;
@@ -5,7 +5,7 @@ import type { Token, AtomToken } from '../../internal';
5
5
  * category
6
6
  *
7
7
  * 分类
8
- * @classdesc `{childNodes: [AtomToken, ?Token]}`
8
+ * @classdesc `{childNodes: [AtomToken, Token?]}`
9
9
  */
10
10
  export declare abstract class CategoryToken extends LinkBaseToken {
11
11
  readonly childNodes: readonly [AtomToken] | readonly [AtomToken, Token];
@@ -6,7 +6,7 @@ const base_1 = require("./base");
6
6
  * category
7
7
  *
8
8
  * 分类
9
- * @classdesc `{childNodes: [AtomToken, ?Token]}`
9
+ * @classdesc `{childNodes: [AtomToken, Token?]}`
10
10
  */
11
11
  class CategoryToken extends base_1.LinkBaseToken {
12
12
  get type() {
@@ -92,7 +92,7 @@ let GalleryImageToken = (() => {
92
92
  /** @private */
93
93
  getTitle(temporary) {
94
94
  const imagemap = this.type === 'imagemap-image';
95
- return this.normalizeTitle(this.firstChild.toString(), imagemap ? 0 : 6, { halfParsed: true, temporary, decode: !imagemap, page: '' });
95
+ return this.normalizeTitle(this.firstChild[imagemap ? 'toString' : 'text'](), imagemap ? 0 : 6, { halfParsed: true, temporary, decode: !imagemap, page: '' });
96
96
  }
97
97
  /** 判定无效的图片 */
98
98
  #lint() {
@@ -6,7 +6,7 @@ import type { Token, AtomToken } from '../../internal';
6
6
  * internal link
7
7
  *
8
8
  * 内链
9
- * @classdesc `{childNodes: [AtomToken, ?Token]}`
9
+ * @classdesc `{childNodes: [AtomToken, Token?]}`
10
10
  */
11
11
  export declare abstract class LinkToken extends LinkBaseToken {
12
12
  readonly childNodes: readonly [AtomToken] | readonly [AtomToken, Token];
@@ -12,7 +12,7 @@ const base_1 = require("./base");
12
12
  * internal link
13
13
  *
14
14
  * 内链
15
- * @classdesc `{childNodes: [AtomToken, ?Token]}`
15
+ * @classdesc `{childNodes: [AtomToken, Token?]}`
16
16
  */
17
17
  class LinkToken extends base_1.LinkBaseToken {
18
18
  get type() {
@@ -7,7 +7,7 @@ import type { Token, AtomToken } from '../../internal';
7
7
  * target of a redirect
8
8
  *
9
9
  * 重定向目标
10
- * @classdesc `{childNodes: [AtomToken, ?NoincludeToken]}`
10
+ * @classdesc `{childNodes: [AtomToken, NoincludeToken?]}`
11
11
  */
12
12
  export declare abstract class RedirectTargetToken extends LinkBaseToken {
13
13
  readonly childNodes: readonly [AtomToken] | readonly [AtomToken, NoincludeToken];
@@ -12,7 +12,7 @@ const noinclude_1 = require("../nowiki/noinclude");
12
12
  * target of a redirect
13
13
  *
14
14
  * 重定向目标
15
- * @classdesc `{childNodes: [AtomToken, ?NoincludeToken]}`
15
+ * @classdesc `{childNodes: [AtomToken, NoincludeToken?]}`
16
16
  */
17
17
  class RedirectTargetToken extends base_1.LinkBaseToken {
18
18
  get type() {
@@ -3,17 +3,18 @@ import { Token } from './index';
3
3
  import type { LintError } from '../base';
4
4
  import type { AstText, CommentToken, IncludeToken, NoincludeToken, TranscludeToken } from '../internal';
5
5
  declare type ExtLinkTypes = 'free-ext-link' | 'ext-link-url' | 'magic-link';
6
+ declare type Child = CommentToken | IncludeToken | NoincludeToken | TranscludeToken;
6
7
  /**
7
8
  * free external link
8
9
  *
9
10
  * 自由外链
10
- * @classdesc `{childNodes: (AstText|CommentToken|IncludeToken|NoincludeToken)[]}`
11
+ * @classdesc `{childNodes: (AstText|CommentToken|IncludeToken|NoincludeToken|TranscludeToken)[]}`
11
12
  */
12
13
  export declare abstract class MagicLinkToken extends Token {
13
14
  #private;
14
- readonly childNodes: readonly (AstText | CommentToken | IncludeToken | NoincludeToken | TranscludeToken)[];
15
+ readonly childNodes: readonly (AstText | Child)[];
15
16
  abstract get firstChild(): AstText | TranscludeToken;
16
- abstract get lastChild(): AstText | CommentToken | IncludeToken | NoincludeToken | TranscludeToken;
17
+ abstract get lastChild(): AstText | Child;
17
18
  get type(): ExtLinkTypes;
18
19
  /**
19
20
  * text of the link
@@ -15,7 +15,7 @@ const spaceRegex = new RegExp(`${space}+`, 'gu');
15
15
  * free external link
16
16
  *
17
17
  * 自由外链
18
- * @classdesc `{childNodes: (AstText|CommentToken|IncludeToken|NoincludeToken)[]}`
18
+ * @classdesc `{childNodes: (AstText|CommentToken|IncludeToken|NoincludeToken|TranscludeToken)[]}`
19
19
  */
20
20
  class MagicLinkToken extends index_2.Token {
21
21
  #type;
@@ -3,7 +3,7 @@ import { GalleryImageToken } from '../link/galleryImage';
3
3
  import { CommentLineToken } from '../nowiki/commentLine';
4
4
  import type { Config, LintError } from '../../base';
5
5
  import type { AstText, Token } from '../../internal';
6
- declare type Child = GalleryImageToken | CommentLineToken | AstText;
6
+ declare type Child = GalleryImageToken | CommentLineToken;
7
7
  /**
8
8
  * `<gallery>`
9
9
  * @classdesc `{childNodes: (GalleryImageToken|CommentLineToken|AstText)[]}`
@@ -11,9 +11,9 @@ declare type Child = GalleryImageToken | CommentLineToken | AstText;
11
11
  export declare abstract class GalleryToken extends MultiLineToken {
12
12
  #private;
13
13
  readonly name: 'gallery';
14
- readonly childNodes: readonly Child[];
15
- abstract get firstChild(): Child | undefined;
16
- abstract get lastChild(): Child | undefined;
14
+ readonly childNodes: readonly (AstText | Child)[];
15
+ abstract get firstChild(): AstText | Child | undefined;
16
+ abstract get lastChild(): AstText | Child | undefined;
17
17
  /** @param inner 标签内部wikitext */
18
18
  constructor(inner?: string, config?: Config, accum?: Token[]);
19
19
  }
@@ -5,10 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.GalleryToken = void 0;
7
7
  const lint_1 = require("../../util/lint");
8
+ const string_1 = require("../../util/string");
9
+ const replace_1 = require("../../util/replace");
8
10
  const index_1 = __importDefault(require("../../index"));
9
11
  const index_2 = require("./index");
10
12
  const galleryImage_1 = require("../link/galleryImage");
11
13
  const commentLine_1 = require("../nowiki/commentLine");
14
+ const comment_1 = require("../nowiki/comment");
12
15
  /**
13
16
  * `<gallery>`
14
17
  * @classdesc `{childNodes: (GalleryImageToken|CommentLineToken|AstText)[]}`
@@ -18,7 +21,12 @@ class GalleryToken extends index_2.MultiLineToken {
18
21
  constructor(inner, config, accum = []) {
19
22
  super(undefined, config, accum, {});
20
23
  if (inner) {
21
- for (const line of inner.split('\n')) {
24
+ for (let line of inner.split('\n')) {
25
+ line = (0, replace_1.safeStringReplace)(line, '<!--', '-->', false, p => {
26
+ // @ts-expect-error abstract class
27
+ new comment_1.CommentToken(p, true, config, accum);
28
+ return `\0${accum.length}c\x7F`;
29
+ });
22
30
  const matches = /^([^|]+)(?:\|(.*))?/u.exec(line);
23
31
  if (!matches) {
24
32
  super.insertAt((line.trim()
@@ -28,7 +36,7 @@ class GalleryToken extends index_2.MultiLineToken {
28
36
  continue;
29
37
  }
30
38
  const [, file, alt] = matches;
31
- if (this.#checkFile(file)) { // eslint-disable-line unicorn/prefer-ternary
39
+ if (this.#checkFile(file, true)) { // eslint-disable-line unicorn/prefer-ternary
32
40
  // @ts-expect-error abstract class
33
41
  super.insertAt(new galleryImage_1.GalleryImageToken('gallery', file, alt, config, accum));
34
42
  }
@@ -43,9 +51,10 @@ class GalleryToken extends index_2.MultiLineToken {
43
51
  /**
44
52
  * 检查文件名是否有效
45
53
  * @param file 文件名
54
+ * @param parsing 是否在解析过程中
46
55
  */
47
- #checkFile(file) {
48
- return this.normalizeTitle(file, 6, { halfParsed: true, temporary: true, decode: true, page: '' }).valid;
56
+ #checkFile(file, parsing) {
57
+ return this.normalizeTitle(parsing ? (0, string_1.removeComment)(file) : file, 6, { halfParsed: true, temporary: true, decode: true, page: '' }).valid;
49
58
  }
50
59
  /** @private */
51
60
  lint(start = this.getAbsoluteIndex(), re) {
@@ -5,17 +5,19 @@ import { GalleryImageToken } from '../link/galleryImage';
5
5
  import { ImagemapLinkToken } from '../singleLine/imagemapLink';
6
6
  import type { LintError } from '../../base';
7
7
  import type { AstText, Token } from '../../internal';
8
+ declare type Child = GalleryImageToken | CommentLineToken | ImagemapLinkToken;
8
9
  /**
9
10
  * `<imagemap>`
10
- * @classdesc `{childNodes: [...CommentLineToken[], GalleryImageToken, ...(CommentLineToken|ImagemapLinkToken|AstText)[]]}`
11
+ * @classdesc `{childNodes: (GalleryImageToken|CommentLineToken|ImagemapLinkToken|AstText)[]]}`
11
12
  */
12
13
  export declare abstract class ImagemapToken extends MultiLineToken {
13
14
  readonly name: 'imagemap';
14
- readonly childNodes: readonly (GalleryImageToken | CommentLineToken | ImagemapLinkToken | AstText)[];
15
+ readonly childNodes: readonly (Child | AstText)[];
15
16
  abstract get firstChild(): GalleryImageToken | CommentLineToken | undefined;
16
- abstract get lastChild(): GalleryImageToken | CommentLineToken | ImagemapLinkToken | AstText | undefined;
17
+ abstract get lastChild(): Child | AstText | undefined;
17
18
  /** 图片 */
18
19
  get image(): GalleryImageToken | undefined;
19
20
  /** @param inner 标签内部wikitext */
20
21
  constructor(inner?: string, config?: Parser.Config, accum?: Token[]);
21
22
  }
23
+ export {};
@@ -14,7 +14,7 @@ const galleryImage_1 = require("../link/galleryImage");
14
14
  const imagemapLink_1 = require("../singleLine/imagemapLink");
15
15
  /**
16
16
  * `<imagemap>`
17
- * @classdesc `{childNodes: [...CommentLineToken[], GalleryImageToken, ...(CommentLineToken|ImagemapLinkToken|AstText)[]]}`
17
+ * @classdesc `{childNodes: (GalleryImageToken|CommentLineToken|ImagemapLinkToken|AstText)[]]}`
18
18
  */
19
19
  class ImagemapToken extends index_2.MultiLineToken {
20
20
  /** 图片 */
@@ -8,7 +8,7 @@ declare type Child = ExtToken | NoincludeToken | CommentToken | IncludeToken | A
8
8
  * extension tag that has a nested structure
9
9
  *
10
10
  * 嵌套式的扩展标签
11
- * @classdesc `{childNodes: (ExtToken|NoincludeToken|CommentToken)[]}`
11
+ * @classdesc `{childNodes: (ExtToken|NoincludeToken|CommentToken|IncludeToken|ArgToken|TranscludeToken)[]}`
12
12
  */
13
13
  export declare abstract class NestedToken extends Token {
14
14
  #private;
@@ -20,7 +20,7 @@ const childTypes = new Set(['comment', 'include', 'arg', 'template', 'magic-word
20
20
  * extension tag that has a nested structure
21
21
  *
22
22
  * 嵌套式的扩展标签
23
- * @classdesc `{childNodes: (ExtToken|NoincludeToken|CommentToken)[]}`
23
+ * @classdesc `{childNodes: (ExtToken|NoincludeToken|CommentToken|IncludeToken|ArgToken|TranscludeToken)[]}`
24
24
  */
25
25
  class NestedToken extends index_2.Token {
26
26
  #tags;
@@ -22,11 +22,14 @@ class ListToken extends listBase_1.ListBaseToken {
22
22
  LINT: {
23
23
  const rule = 'syntax-like', s = index_1.default.lintConfig.getSeverity(rule, 'redirect'), { innerText } = this;
24
24
  if (s && innerText === '#') {
25
- // eslint-disable-next-line prefer-const
26
25
  let { nextSibling } = this;
26
+ PRINT: if (nextSibling?.is('list-range')) {
27
+ nextSibling = nextSibling.firstChild;
28
+ }
27
29
  if (nextSibling?.type === 'text' && linkTypes.has(nextSibling.nextSibling?.type)) {
28
- /^redirect\s*(?::\s*)?$/iu; // eslint-disable-line @typescript-eslint/no-unused-expressions
29
- const re = new RegExp(String.raw `^(?:${this.getAttribute('config').redirection.join('|')})\s*(?::\s*)?$`, 'iu');
30
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
31
+ /^redirect[^\S\n]*(?::[^\S\n]*)?$/iu;
32
+ const re = new RegExp(String.raw `^(?:${this.getAttribute('config').redirection.join('|')})[^\S\n]*(?::[^\S\n]*)?$`, 'iu');
30
33
  if (re.test(`#${nextSibling.data}`)) {
31
34
  const e = (0, lint_1.generateForSelf)(nextSibling, { start: start + 1 }, rule, 'redirect-like', s);
32
35
  e.startIndex--;
@@ -1,5 +1,29 @@
1
+ import { AstText } from '../../lib/text';
2
+ import { Token } from '../index';
1
3
  import { NowikiBaseToken } from './base';
4
+ import type { DdToken, ListToken } from '../../internal';
5
+ export interface ListRangeToken extends Token {
6
+ readonly type: 'list-range';
7
+ readonly previousSibling: ListToken | DdToken;
8
+ readonly nextSibling: DdToken | AstText | undefined;
9
+ }
2
10
  /** `;:*#` */
3
11
  export declare abstract class ListBaseToken extends NowikiBaseToken {
4
12
  abstract get type(): 'dd' | 'list';
13
+ /** whether to contain `;` / 是否包含`;` */
14
+ get dt(): boolean;
15
+ /**
16
+ * number of indentation
17
+ *
18
+ * 缩进数
19
+ * @since v1.16.5
20
+ */
21
+ get indent(): number;
22
+ /**
23
+ * Get the range of the list
24
+ *
25
+ * 获取列表行的范围
26
+ * @throws `Error` if the token has no parent node
27
+ */
28
+ getRange(): ListRangeToken;
5
29
  }
@@ -1,8 +1,112 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ListBaseToken = void 0;
4
+ const debug_1 = require("../../util/debug");
5
+ const text_1 = require("../../lib/text");
6
+ const index_1 = require("../index");
4
7
  const base_1 = require("./base");
5
8
  /** `;:*#` */
6
9
  class ListBaseToken extends base_1.NowikiBaseToken {
10
+ /** whether to contain `;` / 是否包含`;` */
11
+ get dt() {
12
+ PRINT: return this.innerText.includes(';');
13
+ }
14
+ /**
15
+ * number of indentation
16
+ *
17
+ * 缩进数
18
+ * @since v1.16.5
19
+ */
20
+ get indent() {
21
+ PRINT: return this.innerText.split(':').length - 1;
22
+ }
23
+ /**
24
+ * Get the range of the list
25
+ *
26
+ * 获取列表行的范围
27
+ * @throws `Error` if the token has no parent node
28
+ */
29
+ getRange() {
30
+ PRINT: {
31
+ const { parentNode } = this;
32
+ if (!parentNode) {
33
+ throw new Error('There is no parent node!');
34
+ }
35
+ let { nextSibling } = this;
36
+ if (nextSibling?.is('list-range')) {
37
+ return nextSibling;
38
+ }
39
+ const { dt, type } = this;
40
+ let nDt = 0;
41
+ while (nextSibling && (nextSibling.type !== 'text' || !nextSibling.data.includes('\n'))) {
42
+ if (type === 'list') {
43
+ if (nextSibling.is('dd')) {
44
+ nDt -= nextSibling.indent;
45
+ if (dt && nDt < 0) {
46
+ break;
47
+ }
48
+ }
49
+ else if (nextSibling.is('list') && nextSibling.dt) {
50
+ nDt++;
51
+ }
52
+ }
53
+ else if (nextSibling.is('dd')) {
54
+ break;
55
+ }
56
+ ({ nextSibling } = nextSibling);
57
+ }
58
+ let start, end, contents;
59
+ if (nextSibling && nextSibling.type !== 'text') {
60
+ const { childNodes } = parentNode;
61
+ start = childNodes.indexOf(this) + 1;
62
+ end = childNodes.indexOf(nextSibling);
63
+ contents = childNodes.slice(start, end);
64
+ }
65
+ else {
66
+ if (type === 'list') {
67
+ while (this.previousSibling?.is('list')) {
68
+ this.setText(this.previousSibling.innerText + this.innerText);
69
+ this.previousSibling.removeInternal();
70
+ }
71
+ for (let i = 0; i < nDt; i++) {
72
+ const token = this.nextSibling;
73
+ this.setText(this.innerText + token.innerText);
74
+ token.removeInternal();
75
+ }
76
+ if (parentNode.is('list-range')) {
77
+ parentNode.previousSibling.setText(parentNode.previousSibling.innerText + this.innerText);
78
+ this.removeInternal();
79
+ return parentNode;
80
+ }
81
+ }
82
+ const { childNodes } = parentNode;
83
+ start = childNodes.indexOf(this) + 1;
84
+ if (nextSibling) {
85
+ const { data } = nextSibling, offset = data.indexOf('\n'), text = new text_1.AstText(data.slice(0, offset));
86
+ end = childNodes.indexOf(nextSibling);
87
+ contents = childNodes.slice(start, end);
88
+ const last = contents.at(-1);
89
+ if (last) {
90
+ last.setAttribute('nextSibling', text);
91
+ text.setAttribute('previousSibling', last);
92
+ }
93
+ contents.push(text);
94
+ nextSibling.setAttribute('data', data.slice(offset));
95
+ }
96
+ else {
97
+ end = childNodes.length;
98
+ contents = childNodes.slice(start);
99
+ }
100
+ }
101
+ const token = debug_1.Shadow.run(() => {
102
+ const t = new index_1.Token(undefined, this.getAttribute('config'));
103
+ t.type = 'list-range';
104
+ return t;
105
+ });
106
+ token.concat(contents); // eslint-disable-line unicorn/no-unused-builtin-method-return
107
+ (0, debug_1.setChildNodes)(parentNode, start, end - start, [token]);
108
+ return token;
109
+ }
110
+ }
7
111
  }
8
112
  exports.ListBaseToken = ListBaseToken;
@@ -6,7 +6,7 @@ import type { ParamTagToken, FuncTagToken } from '../internal';
6
6
  * parameter of certain extension tags
7
7
  *
8
8
  * 某些扩展标签的参数
9
- * @classdesc `{childNodes: [AtomToken] | [AtomToken, AtomToken]}`
9
+ * @classdesc `{childNodes: [AtomToken, AtomToken?]}`
10
10
  */
11
11
  export declare abstract class ParamLineToken extends Token {
12
12
  readonly name: string;
@@ -49,7 +49,7 @@ const skipTypes = new Set(['comment', 'include', 'noinclude']);
49
49
  * parameter of certain extension tags
50
50
  *
51
51
  * 某些扩展标签的参数
52
- * @classdesc `{childNodes: [AtomToken] | [AtomToken, AtomToken]}`
52
+ * @classdesc `{childNodes: [AtomToken, AtomToken?]}`
53
53
  */
54
54
  let ParamLineToken = (() => {
55
55
  let _classDecorators = [(0, gapped_1.gapped)()];
package/dist/src/pre.d.ts CHANGED
@@ -2,15 +2,16 @@ import { Token } from './index';
2
2
  import { NoincludeToken } from './nowiki/noinclude';
3
3
  import type { Config, LintError } from '../base';
4
4
  import type { AstText, AttributesToken, ExtToken, ConverterToken } from '../internal';
5
+ declare type Child = NoincludeToken | ConverterToken;
5
6
  /**
6
7
  * `<pre>`
7
8
  * @classdesc `{childNodes: (AstText|NoincludeToken|ConverterToken)[]}`
8
9
  */
9
10
  export declare abstract class PreToken extends Token {
10
11
  readonly name: 'pre';
11
- readonly childNodes: readonly (NoincludeToken | ConverterToken | AstText)[];
12
- abstract get firstChild(): NoincludeToken | ConverterToken | AstText | undefined;
13
- abstract get lastChild(): NoincludeToken | ConverterToken | AstText | undefined;
12
+ readonly childNodes: readonly (Child | AstText)[];
13
+ abstract get firstChild(): Child | AstText | undefined;
14
+ abstract get lastChild(): Child | AstText | undefined;
14
15
  abstract get nextSibling(): undefined;
15
16
  abstract get previousSibling(): AttributesToken | undefined;
16
17
  abstract get parentNode(): ExtToken | undefined;
@@ -18,3 +19,4 @@ export declare abstract class PreToken extends Token {
18
19
  /** @class */
19
20
  constructor(wikitext?: string, config?: Config, accum?: Token[]);
20
21
  }
22
+ export {};
@@ -6,7 +6,7 @@ import type { Config, LintError } from '../base';
6
6
  * redirect
7
7
  *
8
8
  * 重定向
9
- * @classdesc `{childNodes: [SyntaxToken, LinkToken]}`
9
+ * @classdesc `{childNodes: [SyntaxToken, RedirectTargetToken]}`
10
10
  */
11
11
  export declare abstract class RedirectToken extends Token {
12
12
  #private;
@@ -44,7 +44,7 @@ const redirectTarget_1 = require("./link/redirectTarget");
44
44
  * redirect
45
45
  *
46
46
  * 重定向
47
- * @classdesc `{childNodes: [SyntaxToken, LinkToken]}`
47
+ * @classdesc `{childNodes: [SyntaxToken, RedirectTargetToken]}`
48
48
  */
49
49
  let RedirectToken = (() => {
50
50
  let _classDecorators = [(0, hidden_1.hiddenToken)(false, false), noEscape_1.noEscape];