wikilint 2.30.0 → 2.32.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 (60) hide show
  1. package/bin/cli.js +1 -1
  2. package/dist/base.d.mts +13 -7
  3. package/dist/base.d.ts +13 -7
  4. package/dist/base.js +1 -1
  5. package/dist/base.mjs +2 -2
  6. package/dist/bin/cli.js +2 -2
  7. package/dist/bin/config.js +1 -1
  8. package/dist/index.d.ts +2 -1
  9. package/dist/index.js +24 -58
  10. package/dist/internal.d.ts +1 -0
  11. package/dist/lib/document.d.ts +9 -7
  12. package/dist/lib/document.js +90 -65
  13. package/dist/lib/element.d.ts +1 -7
  14. package/dist/lib/element.js +6 -29
  15. package/dist/lib/lintConfig.js +6 -2
  16. package/dist/lib/lsp.js +114 -56
  17. package/dist/lib/node.js +1 -1
  18. package/dist/mixin/elementLike.js +2 -4
  19. package/dist/parser/commentAndExt.js +4 -4
  20. package/dist/parser/hrAndDoubleUnderscore.js +9 -8
  21. package/dist/src/arg.js +7 -0
  22. package/dist/src/attribute.js +20 -18
  23. package/dist/src/attributes.d.ts +5 -0
  24. package/dist/src/attributes.js +4 -3
  25. package/dist/src/converterFlags.js +2 -2
  26. package/dist/src/converterRule.js +89 -38
  27. package/dist/src/extLink.js +1 -1
  28. package/dist/src/hidden.js +2 -1
  29. package/dist/src/imageParameter.d.ts +0 -1
  30. package/dist/src/imageParameter.js +198 -145
  31. package/dist/src/index.js +8 -11
  32. package/dist/src/link/base.js +2 -6
  33. package/dist/src/link/file.js +4 -3
  34. package/dist/src/link/galleryImage.js +1 -1
  35. package/dist/src/link/index.js +1 -1
  36. package/dist/src/nowiki/index.js +34 -31
  37. package/dist/src/nowiki/list.js +1 -3
  38. package/dist/src/nowiki/quote.d.ts +2 -2
  39. package/dist/src/nowiki/quote.js +3 -3
  40. package/dist/src/table/base.js +5 -3
  41. package/dist/src/table/index.d.ts +0 -5
  42. package/dist/src/table/index.js +4 -10
  43. package/dist/src/tag/html.js +2 -3
  44. package/dist/src/tag/index.js +6 -14
  45. package/dist/src/tag/tvar.js +2 -1
  46. package/dist/src/tagPair/ext.js +1 -1
  47. package/dist/src/tagPair/translate.d.ts +1 -0
  48. package/dist/src/transclude.js +7 -10
  49. package/dist/util/constants.js +7 -3
  50. package/dist/util/debug.js +42 -4
  51. package/dist/util/diff.js +17 -15
  52. package/dist/{parser → util}/selector.js +9 -3
  53. package/dist/util/sharable.d.mts +4 -1
  54. package/dist/util/sharable.js +7 -7
  55. package/dist/util/sharable.mjs +7 -7
  56. package/dist/util/string.js +15 -11
  57. package/i18n/en.json +1 -0
  58. package/i18n/zh-hans.json +30 -29
  59. package/i18n/zh-hant.json +31 -30
  60. package/package.json +18 -14
package/dist/src/index.js CHANGED
@@ -26,9 +26,9 @@
26
26
  // b: TableToken
27
27
  // c: CommentToke
28
28
  // d: ListToken
29
- // e: ExtToken或OnlyincludeToken
29
+ // e: ExtToken
30
30
  // f: ImageParameterToken内的MagicLinkToken
31
- // g: TranslateToken
31
+ // g: TranslateToken或OnlyincludeToken
32
32
  // h: HeadingToken
33
33
  // i: RFC/PMID/ISBN
34
34
  // l: LinkToken
@@ -109,7 +109,7 @@ class Token extends element_1.AstElement {
109
109
  }
110
110
  /** @private */
111
111
  parseOnce(n = this.#stage, include = false, tidy) {
112
- if (n < this.#stage || this.length === 0 || !this.isPlain()) {
112
+ if (n < this.#stage || this.length !== 1 || !this.isPlain()) {
113
113
  return this;
114
114
  }
115
115
  else if (this.#stage >= constants_1.MAX_STAGE) {
@@ -168,13 +168,13 @@ class Token extends element_1.AstElement {
168
168
  buildFromStr(str, type) {
169
169
  const nodes = str.split(/[\0\x7F]/u).map((s, i) => {
170
170
  if (i % 2 === 0) {
171
- return new text_1.AstText(s);
171
+ return s && new text_1.AstText(s);
172
172
  }
173
173
  else if (isNaN(s.slice(-1))) {
174
174
  return this.#accum[Number(s.slice(0, -1))];
175
175
  }
176
176
  throw new Error(`Failed to build! Unrecognized token: ${s}`);
177
- });
177
+ }).filter(node => node !== '');
178
178
  if (type === constants_1.BuildMethod.String) {
179
179
  return nodes.map(String).join('');
180
180
  }
@@ -189,7 +189,6 @@ class Token extends element_1.AstElement {
189
189
  const { length, firstChild } = this, str = firstChild?.toString();
190
190
  if (length === 1 && firstChild.type === 'text' && str.includes('\0')) {
191
191
  (0, debug_1.setChildNodes)(this, 0, 1, this.buildFromStr(str));
192
- this.normalize();
193
192
  if (this.type === 'root') {
194
193
  for (const token of this.#accum) {
195
194
  token?.build(); // eslint-disable-line @typescript-eslint/no-unnecessary-condition
@@ -373,15 +372,13 @@ class Token extends element_1.AstElement {
373
372
  }
374
373
  /** @private */
375
374
  inTableAttrs() {
376
- return this.closest('table-attrs,ext')?.type === 'table-attrs' && (this.closest('table-attrs,arg,magic-word,template')?.is('table-attrs')
375
+ return this.isInside('table-attrs') && (this.closest('table-attrs,arg,parameter')?.is('table-attrs')
377
376
  ? 2
378
377
  : 1);
379
378
  }
380
379
  /** @private */
381
380
  inHtmlAttrs() {
382
- return this.closest('html-attrs,ext')?.is('html-attrs')
383
- ? 2
384
- : this.inTableAttrs();
381
+ return this.isInside('html-attrs') ? 2 : this.inTableAttrs();
385
382
  }
386
383
  /** @private */
387
384
  lint(start = this.getAbsoluteIndex(), re) {
@@ -464,7 +461,7 @@ class Token extends element_1.AstElement {
464
461
  }
465
462
  if (needFix && errors.some(({ fix }) => fix)) {
466
463
  // 倒序修复,跳过嵌套的修复
467
- const fixable = errors.map(({ fix }) => fix).filter(Boolean).sort(({ range: [aFrom, aTo] }, { range: [bFrom, bTo] }) => aTo === bTo ? bFrom - aFrom : bTo - aTo);
464
+ const fixable = errors.map(({ fix }) => fix).filter(fix => fix !== undefined).sort(({ range: [aFrom, aTo] }, { range: [bFrom, bTo] }) => aTo === bTo ? bFrom - aFrom : bTo - aTo);
468
465
  let i = Infinity, output = wikitext;
469
466
  for (const { range: [from, to], text: t } of fixable) {
470
467
  if (to <= i) {
@@ -40,17 +40,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
40
40
  exports.LinkBaseToken = void 0;
41
41
  const lint_1 = require("../../util/lint");
42
42
  const constants_1 = require("../../util/constants");
43
+ const debug_1 = require("../../util/debug");
43
44
  const rect_1 = require("../../lib/rect");
44
45
  const padded_1 = require("../../mixin/padded");
45
46
  const noEscape_1 = require("../../mixin/noEscape");
46
47
  const index_1 = __importDefault(require("../../index"));
47
48
  const index_2 = require("../index");
48
49
  const atom_1 = require("../atom");
49
- /**
50
- * 是否为普通内链
51
- * @param type 节点类型
52
- */
53
- const isLink = (type) => type === 'redirect-target' || type === 'link';
54
50
  /**
55
51
  * internal link
56
52
  *
@@ -166,7 +162,7 @@ let LinkBaseToken = (() => {
166
162
  }
167
163
  rule = 'no-ignored';
168
164
  s = lintConfig.getSeverity(rule, 'fragment');
169
- if (s && fragment !== undefined && !isLink(type)) {
165
+ if (s && fragment !== undefined && !(0, debug_1.isLink)(type)) {
170
166
  const e = (0, lint_1.generateForChild)(target, rect, rule, 'useless-fragment', s);
171
167
  if (computeEditInfo || fix) {
172
168
  const j = target.childNodes.findIndex(c => c.type === 'text' && c.data.includes('#')), textNode = target.childNodes[j];
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.FileToken = void 0;
7
7
  const lint_1 = require("../../util/lint");
8
+ const constants_1 = require("../../util/constants");
8
9
  const rect_1 = require("../../lib/rect");
9
10
  const index_1 = __importDefault(require("../../index"));
10
11
  const base_1 = require("./base");
@@ -82,8 +83,8 @@ class FileToken extends base_1.LinkBaseToken {
82
83
  const errors = super.lint(start, re), args = filterArgs(this.getAllArgs(), argTypes), keys = [...new Set(args.map(({ name }) => name))], frameKeys = keys.filter(key => frame.has(key)), horizAlignKeys = keys.filter(key => horizAlign.has(key)), vertAlignKeys = keys.filter(key => vertAlign.has(key)), [fr] = frameKeys, unscaled = fr === 'framed' || fr === 'manualthumb', rect = new rect_1.BoundingRect(this, start), { lintConfig } = index_1.default, { computeEditInfo, fix } = lintConfig, { ns, extension, } = this.getAttribute('title'), { firstChild } = this;
83
84
  let rule = 'nested-link', s = lintConfig.getSeverity(rule, 'file');
84
85
  if (s
85
- && imageParameter_1.extensions.has(extension)
86
- && this.closest('ext-link-text')
86
+ && constants_1.extensions.has(extension)
87
+ && this.isInside('ext-link-text')
87
88
  && this.getValue('link')?.trim() !== '') {
88
89
  const e = (0, lint_1.generateForSelf)(this, rect, rule, 'link-in-extlink', s);
89
90
  if (computeEditInfo || fix) {
@@ -157,7 +158,7 @@ class FileToken extends base_1.LinkBaseToken {
157
158
  ];
158
159
  }
159
160
  if (relevantArgs.length > 1) {
160
- let severity = !isCaption || !extension || imageParameter_1.extensions.has(extension);
161
+ let severity = !isCaption || !extension || constants_1.extensions.has(extension);
161
162
  if (isCaption && severity) {
162
163
  const plainArgs = filterArgs(relevantArgs, transclusion);
163
164
  severity = plainArgs.length > 1 && ((arg) => plainArgs.includes(arg));
@@ -84,7 +84,7 @@ let GalleryImageToken = (() => {
84
84
  }
85
85
  accum.splice(length, 1);
86
86
  }
87
- super(link, token?.toString(), config, accum);
87
+ super(link, token?.firstChild.toString(), config, accum);
88
88
  this.setAttribute('bracket', false);
89
89
  this.privateType = `${type}-image`;
90
90
  }
@@ -28,7 +28,7 @@ class LinkToken extends base_1.LinkBaseToken {
28
28
  lint(start = this.getAbsoluteIndex(), re) {
29
29
  LINT: {
30
30
  const errors = super.lint(start, re), rule = 'nested-link', { lintConfig } = index_1.default, s = lintConfig.getSeverity(rule);
31
- if (s && this.closest('ext-link-text')) {
31
+ if (s && this.isInside('ext-link-text')) {
32
32
  const e = (0, lint_1.generateForSelf)(this, { start }, rule, 'link-in-extlink', s);
33
33
  if (lintConfig.computeEditInfo || lintConfig.fix) {
34
34
  e.fix = (0, lint_1.fixBy)(e, 'delink', this.innerText);
@@ -58,38 +58,41 @@ class NowikiToken extends base_1.NowikiBaseToken {
58
58
  NPM: {
59
59
  rule = 'invalid-math';
60
60
  s = lintConfig.getSeverity(rule);
61
- if (s && document_1.texvcjs && constants_1.mathTags.has(name)) {
62
- const isChem = name !== 'math', display = previousSibling?.getAttr('display') ?? 'block';
63
- let tex = innerText, n = 0;
64
- if (isChem) {
65
- tex = String.raw `\ce{${tex}}`;
66
- n = 4;
67
- }
68
- switch (display) {
69
- case 'block':
70
- tex = String.raw `{\displaystyle ${tex}}`;
71
- n += 15;
72
- break;
73
- case 'inline':
74
- tex = String.raw `{\textstyle ${tex}}`;
75
- n += 12;
76
- break;
77
- case 'linebreak':
78
- tex = String.raw `\[ ${tex} \]`;
79
- n += 3;
80
- // no default
81
- }
82
- const result = document_1.texvcjs.check(tex, {
83
- usemhchem: isChem || Boolean(previousSibling?.hasAttr('chem')),
84
- });
85
- if (result.status !== '+') {
86
- const e = (0, lint_1.generateForSelf)(this, { start }, rule, 'chem-required', s);
87
- if (result.status !== 'C') {
88
- const { error: { message, location } } = result, [endIndex, endLine, endCol] = updateLocation(e, location.end, n);
89
- [e.startIndex, e.startLine, e.startCol] = updateLocation(e, location.start, n);
90
- Object.assign(e, { endIndex, endLine, endCol, message });
61
+ if (s && constants_1.mathTags.has(name)) {
62
+ const texvcjs = (0, document_1.loadTexvcjs)();
63
+ if (texvcjs) {
64
+ const isChem = name !== 'math', display = previousSibling?.getAttr('display') ?? 'block';
65
+ let tex = innerText, n = 0;
66
+ if (isChem) {
67
+ tex = String.raw `\ce{${tex}}`;
68
+ n = 4;
69
+ }
70
+ switch (display) {
71
+ case 'block':
72
+ tex = String.raw `{\displaystyle ${tex}}`;
73
+ n += 15;
74
+ break;
75
+ case 'inline':
76
+ tex = String.raw `{\textstyle ${tex}}`;
77
+ n += 12;
78
+ break;
79
+ case 'linebreak':
80
+ tex = String.raw `\[ ${tex} \]`;
81
+ n += 3;
82
+ // no default
83
+ }
84
+ const result = texvcjs.check(tex, {
85
+ usemhchem: isChem || Boolean(previousSibling?.hasAttr('chem')),
86
+ });
87
+ if (result.status !== '+') {
88
+ const e = (0, lint_1.generateForSelf)(this, { start }, rule, 'chem-required', s);
89
+ if (result.status !== 'C') {
90
+ const { message, location } = result.error, [endIndex, endLine, endCol] = updateLocation(e, location.end, n);
91
+ [e.startIndex, e.startLine, e.startCol] = updateLocation(e, location.start, n);
92
+ Object.assign(e, { endIndex, endLine, endCol, message });
93
+ }
94
+ errors.push(e);
91
95
  }
92
- errors.push(e);
93
96
  }
94
97
  }
95
98
  }
@@ -21,10 +21,8 @@ class ListToken extends listBase_1.ListBaseToken {
21
21
  LINT: {
22
22
  const rule = 'syntax-like', s = index_1.default.lintConfig.getSeverity(rule, 'redirect'), { innerText } = this;
23
23
  if (s && innerText === '#') {
24
+ // eslint-disable-next-line prefer-const
24
25
  let { nextSibling } = this;
25
- if (nextSibling?.type === 'list-range') {
26
- nextSibling = nextSibling.firstChild;
27
- }
28
26
  if (nextSibling?.type === 'text' && linkTypes.has(nextSibling.nextSibling?.type)) {
29
27
  /^redirect\s*(?::\s*)?$/iu; // eslint-disable-line @typescript-eslint/no-unused-expressions
30
28
  const re = new RegExp(String.raw `^(?:${this.getAttribute('config').redirection.join('|')})\s*(?::\s*)?$`, 'iu');
@@ -10,9 +10,9 @@ import type { Token } from '../../internal';
10
10
  export declare abstract class QuoteToken extends NowikiBaseToken {
11
11
  #private;
12
12
  get type(): 'quote';
13
- /** 是否粗体 */
13
+ /** whether to be bold / 是否粗体 */
14
14
  get bold(): boolean;
15
- /** 是否斜体 */
15
+ /** whether to be italic / 是否斜体 */
16
16
  get italic(): boolean;
17
17
  /**
18
18
  * whether to be closing quotes
@@ -18,11 +18,11 @@ class QuoteToken extends base_1.NowikiBaseToken {
18
18
  get type() {
19
19
  return 'quote';
20
20
  }
21
- /** 是否粗体 */
21
+ /** whether to be bold / 是否粗体 */
22
22
  get bold() {
23
23
  return this.innerText.length !== 2;
24
24
  }
25
- /** 是否斜体 */
25
+ /** whether to be italic / 是否斜体 */
26
26
  get italic() {
27
27
  return this.innerText.length !== 3;
28
28
  }
@@ -74,7 +74,7 @@ class QuoteToken extends base_1.NowikiBaseToken {
74
74
  errors.push(eNew);
75
75
  }
76
76
  }
77
- if (s && bold && this.closest('heading-title,ext')?.type === 'heading-title') {
77
+ if (s && bold && this.isInside('heading-title')) {
78
78
  const e = (0, lint_1.generateForSelf)(this, rect, rules[1], 'bold-in-header', s);
79
79
  if (computeEditInfo) {
80
80
  e.suggestions = [(0, lint_1.fixByRemove)(e)];
@@ -38,6 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  };
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
40
  exports.TableBaseToken = void 0;
41
+ const debug_1 = require("../../util/debug");
41
42
  const attributesParent_1 = require("../../mixin/attributesParent");
42
43
  const index_1 = __importDefault(require("../../index"));
43
44
  const index_2 = require("../index");
@@ -49,10 +50,11 @@ const attributes_1 = require("../attributes");
49
50
  */
50
51
  const escapeTable = (syntax) => {
51
52
  const wikitext = syntax.childNodes.map(child => child.type === 'text'
52
- ? child.data.replace(/\|\|/gu, '{{!!}}')
53
- .replace(/\|/gu, '{{!}}')
53
+ ? child.data.replace(/\|{1,2}/gu, ({ length }) => `{{${'!'.repeat(length)}}}`)
54
54
  : child.toString()).join(''), { childNodes } = index_1.default.parseWithRef(wikitext, syntax, 2);
55
- syntax.safeReplaceChildren(childNodes);
55
+ debug_1.Shadow.run(() => {
56
+ syntax.safeReplaceChildren(childNodes);
57
+ });
56
58
  };
57
59
  /**
58
60
  * table row that contains the newline at the beginning but not at the end
@@ -4,11 +4,6 @@ import type { Config, LintError } from '../../base';
4
4
  import type { AttributesToken, TdToken, TrToken, Token } from '../../internal';
5
5
  import type { TableCoords } from './trBase';
6
6
  export type TableTokens = TableToken | TrToken | TdToken;
7
- /**
8
- * 是否是行尾
9
- * @param {Token} cell 表格单元格
10
- */
11
- export declare const isRowEnd: ({ type }: Token) => boolean;
12
7
  /** @extends {Array<TableCoords[]>} */
13
8
  export declare class Layout extends Array<TableCoords[]> {
14
9
  abstract static from(arr: TableCoords[][]): Layout;
@@ -37,7 +37,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.TableToken = exports.Layout = exports.isRowEnd = void 0;
40
+ exports.TableToken = exports.Layout = void 0;
41
41
  const lint_1 = require("../../util/lint");
42
42
  const debug_1 = require("../../util/debug");
43
43
  const rect_1 = require("../../lib/rect");
@@ -47,16 +47,10 @@ const trBase_1 = require("./trBase");
47
47
  const syntax_1 = require("../syntax");
48
48
  /**
49
49
  * 生成一个指定长度的空数组
50
- * @param n 数组长度
50
+ * @param length 数组长度
51
51
  * @param callback 回调函数
52
52
  */
53
- const emptyArray = (n, callback) => new Array(n).fill(undefined).map((_, i) => callback(i));
54
- /**
55
- * 是否是行尾
56
- * @param {Token} cell 表格单元格
57
- */
58
- const isRowEnd = ({ type }) => type === 'tr' || type === 'table-syntax';
59
- exports.isRowEnd = isRowEnd;
53
+ const emptyArray = (length, callback) => Array.from({ length }, (_, i) => callback(i));
60
54
  /** @extends {Array<TableCoords[]>} */
61
55
  class Layout extends Array {
62
56
  }
@@ -176,7 +170,7 @@ let TableToken = (() => {
176
170
  k += colspan;
177
171
  }
178
172
  }
179
- else if ((0, exports.isRowEnd)(cell)) {
173
+ else if ((0, debug_1.isRowEnd)(cell)) {
180
174
  break;
181
175
  }
182
176
  }
@@ -146,8 +146,7 @@ let HtmlToken = (() => {
146
146
  }
147
147
  rule = 'bold-header';
148
148
  s = lintConfig.getSeverity(rule, name);
149
- if (s && (name === 'b' || name === 'strong')
150
- && this.closest('heading-title,ext')?.type === 'heading-title') {
149
+ if (s && (name === 'b' || name === 'strong') && this.isInside('heading-title')) {
151
150
  const e = (0, lint_1.generateForSelf)(this, rect, rule, 'bold-in-header', s);
152
151
  if (computeEditInfo) {
153
152
  e.suggestions = [(0, lint_1.fixByRemove)(e)];
@@ -200,7 +199,7 @@ let HtmlToken = (() => {
200
199
  if (childNodes?.slice(0, childNodes.indexOf(this)).some(tag => tag.is('html') && tag.name === name && !tag.findMatchingTag())) {
201
200
  error.suggestions = [(0, lint_1.fixByClose)(start + 1, '/')];
202
201
  }
203
- if (this.closest('heading-title')) {
202
+ if (this.isInside('heading-title')) {
204
203
  error.rule = 'format-leakage';
205
204
  s = lintConfig.getSeverity('format-leakage', name);
206
205
  }
@@ -1,20 +1,16 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.TagToken = void 0;
7
4
  const lint_1 = require("../../util/lint");
8
5
  const debug_1 = require("../../util/debug");
9
- const index_1 = __importDefault(require("../../index"));
10
- const index_2 = require("../index");
6
+ const index_1 = require("../index");
11
7
  /**
12
8
  * HTML tag
13
9
  *
14
10
  * HTML标签
15
11
  * @classdesc `{childNodes: [AttributesToken]}`
16
12
  */
17
- class TagToken extends index_2.Token {
13
+ class TagToken extends index_1.Token {
18
14
  #closing;
19
15
  #tag;
20
16
  #match;
@@ -86,16 +82,12 @@ class TagToken extends index_2.Token {
86
82
  if (top === this) {
87
83
  return token;
88
84
  }
89
- if (index_1.default.viewOnly) {
90
- top.#match = [rev, token];
91
- token.#match = [rev, top];
92
- }
85
+ top.#match = [rev, token];
86
+ token.#match = [rev, top];
93
87
  }
94
88
  }
95
- if (index_1.default.viewOnly) {
96
- for (const token of stack) {
97
- token.#match = [rev, undefined];
98
- }
89
+ for (const token of stack) {
90
+ token.#match = [rev, undefined];
99
91
  }
100
92
  return undefined;
101
93
  }, value => {
@@ -36,6 +36,7 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
37
  exports.TvarToken = void 0;
38
38
  const hidden_1 = require("../../mixin/hidden");
39
+ const noEscape_1 = require("../../mixin/noEscape");
39
40
  const index_1 = require("./index");
40
41
  const syntax_1 = require("../syntax");
41
42
  /**
@@ -43,7 +44,7 @@ const syntax_1 = require("../syntax");
43
44
  * @classdesc `{childNodes: [SyntaxToken]}`
44
45
  */
45
46
  let TvarToken = (() => {
46
- let _classDecorators = [(0, hidden_1.hiddenToken)()];
47
+ let _classDecorators = [(0, hidden_1.hiddenToken)(), noEscape_1.noEscape];
47
48
  let _classDescriptor;
48
49
  let _classExtraInitializers = [];
49
50
  let _classThis;
@@ -200,7 +200,7 @@ let ExtToken = (() => {
200
200
  }
201
201
  rule = 'nested-link';
202
202
  s = lintConfig.getSeverity(rule, 'ref');
203
- if (s && this.closest('link,ext-link-text')) {
203
+ if (s && this.closest('link-text,ext-link-text')) {
204
204
  errors.push((0, lint_1.generateForSelf)(this, rect, rule, 'ref-in-link', s));
205
205
  }
206
206
  }
@@ -13,6 +13,7 @@ export declare abstract class TranslateToken extends TagPairToken {
13
13
  readonly childNodes: readonly [SyntaxToken, Token];
14
14
  abstract get firstChild(): SyntaxToken;
15
15
  abstract get lastChild(): Token;
16
+ abstract get innerText(): string;
16
17
  get type(): 'translate';
17
18
  /**
18
19
  * @param attr 标签属性
@@ -114,7 +114,7 @@ let TranscludeToken = (() => {
114
114
  title = title.replace(`\0${heading}h\x7F`, accum[heading].toString().replace(/^\n/u, ''));
115
115
  }
116
116
  super(undefined, config, accum, {});
117
- const { parserFunction: [insensitive, sensitive], variable, functionHook } = config, argSubst = /^(?:\s|\0\d+[cn]\x7F)*\0\d+s\x7F/u.exec(title)?.[0];
117
+ const { parserFunction, variable, functionHook } = config, argSubst = /^(?:\s|\0\d+[cn]\x7F)*\0\d+s\x7F/u.exec(title)?.[0];
118
118
  if (argSubst) {
119
119
  this.setAttribute('modifier', argSubst);
120
120
  title = title.slice(argSubst.length);
@@ -129,14 +129,11 @@ let TranscludeToken = (() => {
129
129
  if (isFunction || parts.length === 0 && !this.#raw) {
130
130
  const magicWord = isFunction ? title.slice(0, colon) : title, arg = isFunction && title.slice(colon + 1), cleaned = (0, string_1.removeComment)(magicWord), name = isFunction
131
131
  ? cleaned.slice(cleaned.search(/\S/u)) + (fullWidth ? ':' : '')
132
- : cleaned.trim(), lcName = name.toLowerCase(), isOldSchema = Array.isArray(sensitive), isSensitive = isOldSchema
133
- ? sensitive.includes(name)
134
- : Object.prototype.hasOwnProperty.call(sensitive, name), canonicalName = !isOldSchema && isSensitive
135
- ? sensitive[name]
136
- : Object.prototype.hasOwnProperty.call(insensitive, lcName) && insensitive[lcName], isFunc = isOldSchema && isSensitive
137
- || !('functionHook' in config) || functionHook.includes(canonicalName), isVar = isOldSchema && isSensitive || variable.includes(canonicalName);
132
+ : cleaned.trim(),
133
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
134
+ [, isSensitive, canonicalName] = (0, debug_1.getMagicWordInfo)(name, parserFunction), isFunc = !('functionHook' in config) || functionHook.includes(canonicalName), isVar = variable.includes(canonicalName);
138
135
  if (isFunction ? canonicalName && isFunc : isVar) {
139
- this.setAttribute('name', canonicalName || lcName.replace(/^#|:$/u, ''));
136
+ this.setAttribute('name', canonicalName);
140
137
  this.#type = 'magic-word';
141
138
  if (fullWidth) {
142
139
  this.#colon = ':';
@@ -217,7 +214,7 @@ let TranscludeToken = (() => {
217
214
  }
218
215
  /** 获取模板或模块名 */
219
216
  #getTitle() {
220
- const isTemplate = this.type === 'template', title = this.normalizeTitle((isTemplate ? '' : 'Module:') + this.childNodes[isTemplate ? 0 : 1].text(), 10, { temporary: true, ...!isTemplate && { page: '' } });
217
+ const isTemplate = this.type === 'template', title = this.normalizeTitle((isTemplate ? '' : 'Module:') + (0, string_1.removeComment)(this.childNodes[isTemplate ? 0 : 1].text()), 10, { temporary: true, ...!isTemplate && { page: '' } });
221
218
  return title;
222
219
  }
223
220
  /** @private */
@@ -434,7 +431,7 @@ let TranscludeToken = (() => {
434
431
  if (length === 0) {
435
432
  queue.splice(i, 1);
436
433
  }
437
- else if (length > 1 || first.type !== 'magic-word') {
434
+ else if (length > 1 || !first.is('magic-word')) {
438
435
  i++;
439
436
  }
440
437
  else {
@@ -1,13 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mathTags = exports.enMsg = exports.BuildMethod = exports.MAX_STAGE = void 0;
3
+ exports.mathTags = exports.extensions = exports.galleryParams = exports.enMsg = exports.BuildMethod = exports.MAX_STAGE = void 0;
4
4
  exports.MAX_STAGE = 11;
5
5
  var BuildMethod;
6
6
  (function (BuildMethod) {
7
7
  BuildMethod[BuildMethod["String"] = 0] = "String";
8
8
  BuildMethod[BuildMethod["Text"] = 1] = "Text";
9
9
  })(BuildMethod || (exports.BuildMethod = BuildMethod = {}));
10
- // eslint-disable-next-line n/no-missing-require
11
- exports.enMsg = (() => require('../../i18n/en.json'))();
10
+ exports.enMsg = (() => {
11
+ // eslint-disable-next-line n/no-missing-require
12
+ LSP: return require('../../i18n/en.json');
13
+ })();
14
+ exports.galleryParams = new Set(['alt', 'link', 'lang', 'page', 'caption']);
15
+ exports.extensions = new Set(['tiff', 'tif', 'png', 'gif', 'jpg', 'jpeg', 'webp', 'xcf', 'pdf', 'svg', 'djvu']);
12
16
  /* NOT FOR BROWSER ONLY */
13
17
  exports.mathTags = new Set(['math', 'chem', 'ce']);
@@ -1,26 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mixin = exports.setChildNodes = exports.isToken = exports.Shadow = void 0;
3
+ exports.mixin = exports.getMagicWordInfo = exports.setChildNodes = exports.isLink = exports.isRowEnd = exports.isToken = exports.Shadow = void 0;
4
4
  exports.Shadow = {
5
5
  running: false,
6
6
  /** @private */
7
- run(callback) {
7
+ run(callback, Parser) {
8
8
  const { running } = this;
9
9
  this.running = true;
10
+ /** restore state before exit */
11
+ const finish = () => {
12
+ this.running = running;
13
+ };
10
14
  try {
11
15
  const { Token: AnyToken } = require('../src/index');
12
16
  const result = callback();
13
17
  if (result instanceof AnyToken && !result.getAttribute('built')) {
14
18
  result.afterBuild();
15
19
  }
16
- this.running = running;
20
+ finish();
17
21
  return result;
18
22
  }
19
23
  catch (e) /* istanbul ignore next */ {
20
- this.running = running;
24
+ finish();
21
25
  throw e;
22
26
  }
23
27
  },
28
+ /** @private */
29
+ internal(callback, Parser) {
30
+ const result = callback();
31
+ return result;
32
+ },
24
33
  rev: 0,
25
34
  };
26
35
  /**
@@ -29,6 +38,19 @@ exports.Shadow = {
29
38
  */
30
39
  const isToken = (type) => (node) => node.type === type;
31
40
  exports.isToken = isToken;
41
+ /**
42
+ * 是否是行尾
43
+ * @param token 节点
44
+ * @param token.type 节点类型
45
+ */
46
+ const isRowEnd = ({ type }) => type === 'tr' || type === 'table-syntax';
47
+ exports.isRowEnd = isRowEnd;
48
+ /**
49
+ * 是否为普通内链
50
+ * @param type 节点类型
51
+ */
52
+ const isLink = (type) => type === 'redirect-target' || type === 'link';
53
+ exports.isLink = isLink;
32
54
  /**
33
55
  * 更新chldNodes
34
56
  * @param parent 父节点
@@ -59,6 +81,22 @@ const setChildNodes = (parent, position, deleteCount, inserted = []) => {
59
81
  return removed;
60
82
  };
61
83
  exports.setChildNodes = setChildNodes;
84
+ /**
85
+ * 获取魔术字的信息
86
+ * @param name 魔术字
87
+ * @param parserFunction 解析设置中的parserFunction属性
88
+ */
89
+ const getMagicWordInfo = (name, parserFunction) => {
90
+ const lcName = name.toLowerCase(), [insensitive, sensitive] = parserFunction, isSensitive = Object.prototype.hasOwnProperty.call(sensitive, name);
91
+ return [
92
+ lcName,
93
+ isSensitive,
94
+ isSensitive
95
+ ? sensitive[name]
96
+ : Object.prototype.hasOwnProperty.call(insensitive, lcName) && insensitive[lcName],
97
+ ];
98
+ };
99
+ exports.getMagicWordInfo = getMagicWordInfo;
62
100
  /* NOT FOR BROWSER ONLY */
63
101
  /**
64
102
  * 同步混入的类名