wikiparser-node 1.28.1 → 1.29.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 (87) hide show
  1. package/README.md +0 -2
  2. package/bundle/bundle-es8.min.js +26 -26
  3. package/bundle/bundle-lsp.min.js +30 -30
  4. package/bundle/bundle.min.js +24 -24
  5. package/data/ext/ThirdPartyNotices.txt +33 -0
  6. package/data/ext/mapframe.json +489 -2
  7. package/dist/addon/magicWords.js +132 -0
  8. package/dist/addon/table.js +4 -4
  9. package/dist/addon/token.js +37 -126
  10. package/dist/addon/transclude.js +24 -30
  11. package/dist/base.d.mts +4 -2
  12. package/dist/base.d.ts +4 -2
  13. package/dist/base.js +1 -0
  14. package/dist/base.mjs +2 -1
  15. package/dist/bin/config.js +1 -1
  16. package/dist/index.d.ts +2 -1
  17. package/dist/index.js +27 -5
  18. package/dist/lib/document.d.ts +23 -7
  19. package/dist/lib/document.js +22 -38
  20. package/dist/lib/element.js +1 -1
  21. package/dist/lib/lintConfig.js +2 -0
  22. package/dist/lib/lsp.d.ts +1 -12
  23. package/dist/lib/lsp.js +120 -155
  24. package/dist/lib/node.js +25 -25
  25. package/dist/lib/range.js +2 -2
  26. package/dist/lib/text.js +7 -14
  27. package/dist/lib/title.d.ts +3 -1
  28. package/dist/lib/title.js +54 -33
  29. package/dist/mixin/elementLike.d.ts +1 -1
  30. package/dist/mixin/elementLike.js +14 -9
  31. package/dist/parser/commentAndExt.js +30 -26
  32. package/dist/parser/links.js +4 -3
  33. package/dist/parser/redirect.js +1 -1
  34. package/dist/parser/selector.js +7 -9
  35. package/dist/src/arg.js +4 -6
  36. package/dist/src/atom.d.ts +1 -1
  37. package/dist/src/atom.js +0 -2
  38. package/dist/src/attribute.js +40 -10
  39. package/dist/src/attributes.d.ts +1 -0
  40. package/dist/src/attributes.js +9 -2
  41. package/dist/src/converter.js +6 -3
  42. package/dist/src/converterFlags.js +2 -1
  43. package/dist/src/converterRule.d.ts +8 -8
  44. package/dist/src/converterRule.js +37 -14
  45. package/dist/src/extLink.js +3 -4
  46. package/dist/src/heading.js +1 -2
  47. package/dist/src/hidden.js +2 -1
  48. package/dist/src/imageParameter.d.ts +9 -1
  49. package/dist/src/imageParameter.js +312 -233
  50. package/dist/src/index.d.ts +8 -0
  51. package/dist/src/index.js +31 -37
  52. package/dist/src/link/base.js +7 -9
  53. package/dist/src/link/file.js +9 -10
  54. package/dist/src/link/galleryImage.js +1 -1
  55. package/dist/src/link/redirectTarget.js +1 -1
  56. package/dist/src/magicLink.js +1 -2
  57. package/dist/src/multiLine/gallery.js +2 -2
  58. package/dist/src/multiLine/imagemap.js +3 -4
  59. package/dist/src/multiLine/paramTag.js +2 -2
  60. package/dist/src/nowiki/doubleUnderscore.js +1 -3
  61. package/dist/src/nowiki/index.js +60 -4
  62. package/dist/src/onlyinclude.js +2 -1
  63. package/dist/src/parameter.js +4 -6
  64. package/dist/src/redirect.js +2 -2
  65. package/dist/src/table/base.js +1 -2
  66. package/dist/src/table/index.js +4 -7
  67. package/dist/src/table/td.d.ts +2 -3
  68. package/dist/src/table/td.js +6 -6
  69. package/dist/src/table/trBase.js +1 -1
  70. package/dist/src/tag/html.js +4 -5
  71. package/dist/src/tag/tvar.js +3 -3
  72. package/dist/src/tagPair/ext.js +2 -2
  73. package/dist/src/tagPair/include.js +2 -2
  74. package/dist/src/tagPair/translate.js +2 -2
  75. package/dist/src/transclude.js +5 -5
  76. package/dist/util/constants.js +4 -1
  77. package/dist/util/debug.js +1 -1
  78. package/dist/util/html.js +15 -14
  79. package/dist/util/search.js +16 -0
  80. package/dist/util/sharable.js +27 -3
  81. package/dist/util/sharable.mjs +28 -4
  82. package/extensions/dist/base.js +1 -1
  83. package/i18n/en.json +2 -0
  84. package/i18n/zh-hans.json +2 -0
  85. package/i18n/zh-hant.json +2 -0
  86. package/package.json +7 -5
  87. package/data/ext/maplink.json +0 -4
package/dist/lib/lsp.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.LanguageService = exports.isAttr = exports.tasks = void 0;
6
+ exports.LanguageService = exports.tasks = void 0;
7
7
  const common_1 = require("@bhsd/common");
8
8
  const cm_util_1 = require("@bhsd/cm-util");
9
9
  const base_1 = require("../base");
@@ -11,9 +11,6 @@ const sharable_1 = require("../util/sharable");
11
11
  const lint_1 = require("../util/lint");
12
12
  const string_1 = require("../util/string");
13
13
  const index_1 = __importDefault(require("../index"));
14
- /* NOT FOR BROWSER */
15
- const constants_1 = require("../util/constants");
16
- /* NOT FOR BROWSER END */
17
14
  /* NOT FOR BROWSER ONLY */
18
15
  const fs_1 = __importDefault(require("fs"));
19
16
  const path_1 = __importDefault(require("path"));
@@ -21,11 +18,9 @@ const util_1 = __importDefault(require("util"));
21
18
  const child_process_1 = require("child_process");
22
19
  const crypto_1 = require("crypto");
23
20
  const stylelint_util_1 = require("@bhsd/stylelint-util");
21
+ const search_1 = __importDefault(require("../util/search"));
22
+ const constants_1 = require("../util/constants");
24
23
  const document_1 = require("./document");
25
- /** @see https://www.npmjs.com/package/stylelint-config-recommended */
26
- const cssRules = { 'block-no-empty': null }, jsonSelector = document_1.jsonTags.map(s => `ext#${s}`).join(), mathTags = ['math', 'chem', 'ce'], mathSelector = mathTags.map(s => `ext#${s}`).join(), scores = new Map();
27
- let colors;
28
- /* NOT FOR BROWSER ONLY END */
29
24
  exports.tasks = new WeakMap();
30
25
  const refTags = new Set(['ref']), referencesTags = new Set(['ref', 'references']), nameAttrs = new Set(['name', 'follow']), groupAttrs = new Set(['group']), renameTypes = new Set([
31
26
  'arg-name',
@@ -57,7 +52,6 @@ const isAttr = ({ type, parentNode, length, firstChild }, style) => type === 'at
57
52
  && (!style
58
53
  || parentNode.name === 'style'
59
54
  && Boolean(document_1.cssLSP));
60
- exports.isAttr = isAttr;
61
55
  /**
62
56
  * Check if a token is an HTML attribute.
63
57
  * @param token
@@ -234,6 +228,9 @@ const getFixAll = (root, rule) => {
234
228
  ];
235
229
  };
236
230
  /* NOT FOR BROWSER ONLY */
231
+ /** @see https://www.npmjs.com/package/stylelint-config-recommended */
232
+ const cssRules = { 'block-no-empty': null }, sources = { 'invalid-css': 'css', 'invalid-math': 'texvc' }, jsonSelector = document_1.jsonTags.map(s => `ext#${s}`).join(), scores = new Map();
233
+ let colors;
237
234
  /**
238
235
  * Correct the position of an error.
239
236
  * @param height
@@ -252,21 +249,20 @@ const adjustPos = (height, width, line, column) => {
252
249
  }
253
250
  return [line, column];
254
251
  };
255
- /**
256
- * Get the position of a Stylelint error.
257
- * @param rect bounding client rect of the token
258
- * @param bottom bottom of the style block
259
- * @param lineOrCode line number or code string
260
- * @param columnOrOffset column number or offset in the code string
261
- */
262
- const getStylelintPos = (rect, bottom, lineOrCode, columnOrOffset) => {
252
+ function getStylelintPos(rect, bottom, lineOrCode, columnOrOffset) {
253
+ if (Array.isArray(columnOrOffset)) {
254
+ return {
255
+ start: getStylelintPos(rect, bottom, lineOrCode, columnOrOffset[0]),
256
+ end: getStylelintPos(rect, bottom, lineOrCode, columnOrOffset[1]),
257
+ };
258
+ }
263
259
  const { top, left, height, width } = rect, start = bottom - height - 1;
264
260
  if (typeof lineOrCode === 'number') {
265
261
  return (0, lint_1.getEndPos)(top, left, ...adjustPos(height, width, lineOrCode - start, columnOrOffset));
266
262
  }
267
263
  const lines = lineOrCode.slice(0, columnOrOffset).split(/\r?\n/u);
268
264
  return getStylelintPos(rect, bottom, lines.length, lines.at(-1).length);
269
- };
265
+ }
270
266
  /**
271
267
  * Convert LilyPond errors to VSCode diagnostics.
272
268
  * @param root root token
@@ -315,10 +311,11 @@ class LanguageService {
315
311
  config;
316
312
  /** @private */
317
313
  data;
314
+ /* NOT FOR BROWSER ONLY */
315
+ /** @private */
318
316
  lilypond;
319
317
  #lilypondData;
320
318
  #mathData;
321
- #mathSet;
322
319
  /* NOT FOR BROWSER ONLY END */
323
320
  /** @param uri 任务标识 */
324
321
  constructor(uri) {
@@ -327,7 +324,6 @@ class LanguageService {
327
324
  const dataDir = path_1.default.join('..', '..', 'data'), extDir = path_1.default.join(dataDir, 'ext');
328
325
  this.#lilypondData = require(path_1.default.join(extDir, 'score'));
329
326
  this.#mathData = require(path_1.default.join(extDir, 'math'));
330
- this.#mathSet = new Set(this.#mathData);
331
327
  /* NOT FOR BROWSER ONLY END */
332
328
  Object.defineProperties(this, {
333
329
  config: { enumerable: false },
@@ -455,8 +451,7 @@ class LanguageService {
455
451
  })();
456
452
  const re = await colors;
457
453
  /* NOT FOR BROWSER ONLY END */
458
- return root.querySelectorAll('attr-value,parameter-value,arg-default').reverse()
459
- .flatMap(token => {
454
+ return root.querySelectorAll('attr-value,parameter-value,arg-default').reverse().flatMap(token => {
460
455
  const { type, childNodes,
461
456
  /* NOT FOR BROWSER ONLY */
462
457
  parentNode, } = token;
@@ -464,7 +459,7 @@ class LanguageService {
464
459
  return [];
465
460
  /* NOT FOR BROWSER ONLY */
466
461
  }
467
- else if ((0, exports.isAttr)(token, true)) {
462
+ else if (isAttr(token, true)) {
468
463
  const textDoc = new document_1.EmbeddedCSSDocument(root, token);
469
464
  return document_1.cssLSP.findDocumentColors(textDoc, textDoc.styleSheet);
470
465
  /* NOT FOR BROWSER ONLY END */
@@ -472,8 +467,7 @@ class LanguageService {
472
467
  /* NOT FOR BROWSER ONLY */
473
468
  const isStyle = re && type === 'attr-value' && parentNode.name === 'style';
474
469
  /* NOT FOR BROWSER ONLY END */
475
- return childNodes.filter((child) => child.type === 'text').reverse()
476
- .flatMap(child => {
470
+ return childNodes.filter((child) => child.type === 'text').reverse().flatMap(child => {
477
471
  const { data } = child, parts = (0, common_1.splitColors)(data, hsl).filter(([, , , isColor]) => isColor);
478
472
  /* NOT FOR BROWSER ONLY */
479
473
  if (isStyle) {
@@ -523,21 +517,23 @@ class LanguageService {
523
517
  this.config ??= index_1.default.getConfig();
524
518
  const { nsid, ext, html, parserFunction: [insensitive, sensitive, ...other], doubleUnderscore, protocol, img, } = this.config, tags = new Set([ext, html].flat(2));
525
519
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
526
- /(?:<\/?(\w*)|(\{{2,4}|\[\[)\s*([^|{}<>[\]\s][^|{}<>[\]#]*)?|(__(?:(?!__)[\p{L}\p{N}_])*)|(?<!\[)\[([a-z:/]*)|\[\[\s*(?:file|image)\s*:[^[\]{}<>]+\|([^[\]{}<>|=]*)|<(\w+)(?:\s(?:[^<>{}|=\s]+(?:\s*=\s*(?:[^\s"']\S*|(["']).*?\8))?(?=\s))*)?\s(\w*))$/iu;
520
+ /(?:<(\/?\w*)|(\{{2,4}|\[\[)\s*([^|{}<>[\]\s][^|{}<>[\]#]*)?|(_(?:_(?:(?!__|_{2})[\p{L}\p{N}_])*)?)|(_(?:_(?:(?!__|_{2})[\p{L}\p{N}_])*)?)|(?<!\[)\[([a-z:/]*)|\[\[\s*(?:file|image)\s*:[^[\]{}<>]+\|([^[\]{}<>|=]*)|<(\w+)(?:\s(?:[^<>{}|=\s]+(?:\s*=\s*(?:[^\s"']\S*|(["']).*?\9))?(?=\s))*)?\s(\w*))$/iu;
527
521
  const re = new RegExp('(?:' // eslint-disable-line prefer-template
528
- + String.raw `<(\/?\w*)` // tag
522
+ + String.raw `<(\/?\w*)` // tag ($1)
523
+ + '|'
524
+ + String.raw `(\{{2,4}|\[\[)\s*([^|{}<>[\]\s][^|{}<>[\]#]*)?` // braces and brackets ($2, $3)
529
525
  + '|'
530
- + String.raw `(\{{2,4}|\[\[)\s*([^|{}<>[\]\s][^|{}<>[\]#]*)?` // braces and brackets
526
+ + String.raw `(_(?:_(?:(?!__|_{2})[\p{L}\p{N}_])*)?)` // behavior switch ($4)
531
527
  + '|'
532
- + String.raw `(__(?:(?!__)[\p{L}\p{N}_])*)` // behavior switch
528
+ + String.raw `(_(?:_(?:(?!__|_{2})[\p{L}\p{N}_])*)?)` // Japanese behavior switch ($5)
533
529
  + '|'
534
- + String.raw `(?<!\[)\[([a-z:/]*)` // protocol
530
+ + String.raw `(?<!\[)\[([a-z:/]*)` // protocol ($6)
535
531
  + '|'
536
- + String.raw `\[\[\s*(?:${Object.entries(nsid).filter(([, v]) => v === 6).map(([k]) => k).join('|')})\s*:[^[\]{}<>]+\|([^[\]{}<>|=]*)` // image parameter
532
+ + String.raw `\[\[\s*(?:${Object.entries(nsid).filter(([, v]) => v === 6).map(([k]) => k).join('|')})\s*:[^[\]{}<>]+\|([^[\]{}<>|=]*)` // image parameter ($7)
537
533
  + '|'
538
- // attribute key
539
- + String.raw `<(\w+)(?:\s(?:[^<>{}|=\s]+(?:\s*=\s*(?:[^\s"']\S*|(["']).*?\8))?(?=\s))*)?\s(\w*)`
540
- + ')$', 'iu');
534
+ // attribute key ($8, $10)
535
+ + String.raw `<(\w+)(?:\s(?:[^<>{}|=\s]+(?:\s*=\s*(?:[^\s"']\S*|(["']).*?\9))?(?=\s))*)?\s(\w*)`
536
+ + ')$', 'iu'), allSwitches = doubleUnderscore.slice(0, 2).flat();
541
537
  this.#completionConfig = [
542
538
  {
543
539
  re,
@@ -549,9 +545,8 @@ class LanguageService {
549
545
  Array.isArray(sensitive) ? /* istanbul ignore next */ sensitive : Object.keys(sensitive),
550
546
  other,
551
547
  ].flat(2),
552
- switches: doubleUnderscore.slice(0, 2).flat()
553
- .filter(cm_util_1.isUnderscore)
554
- .map(w => `__${w}__`),
548
+ switches: allSwitches.filter(cm_util_1.isUnderscore).map(w => `__${w}__`),
549
+ jaSwitches: allSwitches.filter(w => !(0, cm_util_1.isUnderscore)(w)),
555
550
  protocols: protocol.split('|'),
556
551
  params: Object.keys(img)
557
552
  .filter(k => k.endsWith('$1') || !k.includes('$1'))
@@ -570,17 +565,20 @@ class LanguageService {
570
565
  * @param position position / 位置
571
566
  */
572
567
  async provideCompletionItems(text, position) {
573
- const { re, allTags, functions, switches, protocols, params, tags, ext } = this.#prepareCompletionConfig(), { line, character } = position, curLine = text.split(/\r?\n/u, line + 1)[line], mt = re.exec(curLine?.slice(0, character) ?? ''), [, , iAlias = {}, sAlias = {}] = this.config.doubleUnderscore;
568
+ const { re, allTags, functions, switches, jaSwitches, protocols, params, tags, ext, } = this.#prepareCompletionConfig(), { line, character } = position, curLine = text.split(/\r?\n/u, line + 1)[line], mt = re.exec(curLine?.slice(0, character) ?? ''), [, , iAlias = {}, sAlias = {}] = this.config.doubleUnderscore;
574
569
  if (mt?.[1] !== undefined) { // tag
575
570
  const closing = mt[1].startsWith('/');
576
571
  return getCompletion(allTags, 'Class', mt[1].slice(closing ? 1 : 0), position, closing && !curLine?.slice(character).trim().startsWith('>') ? '>' : '');
577
572
  }
578
- else if (mt?.[4]) { // behavior switch
579
- return getCompletion(switches, 'Constant', mt[4], position, '', name => {
573
+ else if (mt?.[4] || mt?.[5] && jaSwitches.length > 0) { // behavior switch
574
+ const isJa = mt[5] !== undefined;
575
+ return getCompletion(isJa ? jaSwitches : switches, 'Constant', mt[isJa ? 5 : 4], position, '', name => {
580
576
  if (!this.data) {
581
577
  return undefined;
582
578
  }
583
- name = name.slice(2, -2);
579
+ else if (!isJa) {
580
+ name = name.slice(2, -2);
581
+ }
584
582
  if (name in iAlias) {
585
583
  name = iAlias[name];
586
584
  }
@@ -590,8 +588,8 @@ class LanguageService {
590
588
  return this.#getBehaviorSwitch(name.toLowerCase());
591
589
  });
592
590
  }
593
- else if (mt?.[5] !== undefined) { // protocol
594
- return getCompletion(protocols, 'Reference', mt[5], position);
591
+ else if (mt?.[6] !== undefined) { // protocol
592
+ return getCompletion(protocols, 'Reference', mt[6], position);
595
593
  }
596
594
  const root = await this.#queue(text);
597
595
  let cur;
@@ -644,12 +642,12 @@ class LanguageService {
644
642
  ];
645
643
  }
646
644
  let type, parentNode;
647
- if (mt?.[7] === undefined) {
645
+ if (mt?.[8] === undefined) {
648
646
  cur = root.elementFromPoint(character, line);
649
647
  ({ type, parentNode } = cur);
650
648
  }
651
- if (mt?.[6] !== undefined || type === 'image-parameter') { // image parameter
652
- const index = root.indexFromPos(line, character), match = mt?.[6]?.trimStart()
649
+ if (mt?.[7] !== undefined || type === 'image-parameter') { // image parameter
650
+ const index = root.indexFromPos(line, character), match = mt?.[7]?.trimStart()
653
651
  ?? this.#text.slice(cur.getAbsoluteIndex(), index).trimStart(), equal = this.#text[index] === '=';
654
652
  return [
655
653
  ...getCompletion(params, 'Property', match, position)
@@ -659,8 +657,8 @@ class LanguageService {
659
657
  .map(width => width.text()), 'Unit', match, position),
660
658
  ];
661
659
  }
662
- else if (mt?.[7] !== undefined || type === 'attr-key') { // attribute key
663
- const tag = mt?.[7]?.toLowerCase() ?? parentNode.tag, key = mt?.[9]
660
+ else if (mt?.[8] !== undefined || type === 'attr-key') { // attribute key
661
+ const tag = mt?.[8]?.toLowerCase() ?? parentNode.tag, key = mt?.[10]
664
662
  ?? cur.toString().slice(0, character - root.posFromIndex(cur.getAbsoluteIndex()).left);
665
663
  if (!tags.has(tag)) {
666
664
  return undefined;
@@ -703,7 +701,7 @@ class LanguageService {
703
701
  : undefined;
704
702
  /* NOT FOR BROWSER ONLY */
705
703
  }
706
- else if ((0, exports.isAttr)(cur, true)) {
704
+ else if (isAttr(cur, true)) {
707
705
  const textDoc = new document_1.EmbeddedCSSDocument(root, cur);
708
706
  return document_1.cssLSP.doComplete(textDoc, position, textDoc.styleSheet).items.map((item) => ({
709
707
  ...item,
@@ -738,7 +736,7 @@ class LanguageService {
738
736
  ];
739
737
  }
740
738
  }
741
- else if (type === 'ext-inner' && mathTags.includes(cur.name)) {
739
+ else if (type === 'ext-inner' && constants_1.mathTags.has(cur.name)) {
742
740
  const word = /(?<!\\)\\[a-z]+$/iu.exec(curLine.slice(0, character))?.[0];
743
741
  if (word) {
744
742
  const data = this.#mathData;
@@ -748,7 +746,7 @@ class LanguageService {
748
746
  }
749
747
  /* NOT FOR BROWSER ONLY END */
750
748
  }
751
- else if ((0, exports.isAttr)(cur) && isHtmlAttr(parentNode)) {
749
+ else if (isAttr(cur) && isHtmlAttr(parentNode)) {
752
750
  const data = (0, lint_1.provideValues)(parentNode.tag, parentNode.name);
753
751
  if (data.length === 0) {
754
752
  return undefined;
@@ -780,8 +778,7 @@ class LanguageService {
780
778
  severity: severity === 'error' ? 1 : 2,
781
779
  source:
782
780
  /* eslint-disable @stylistic/operator-linebreak */
783
- rule === 'invalid-css' ?
784
- 'css' :
781
+ sources[rule] ??
785
782
  'WikiLint',
786
783
  code: code ??
787
784
  /* eslint-enable @stylistic/operator-linebreak */
@@ -795,48 +792,47 @@ class LanguageService {
795
792
  /* eslint-disable @stylistic/operator-linebreak */
796
793
  cssDiagnostics = await document_1.stylelint ?
797
794
  await (async () => {
798
- const tokens = this.findStyleTokens();
799
- if (tokens.length === 0) {
800
- return [];
801
- }
802
- const code = tokens.map(({ type, tag, lastChild }, i) => `${type === 'ext-attr' ? 'div' : tag}#${i}{\n${(0, common_1.sanitizeInlineStyle)(lastChild.toString())}\n}`).join('\n'), cssErrors = await (0, stylelint_util_1.styleLint)((await document_1.stylelint), code, cssRules);
803
- if (cssErrors.length === 0) {
804
- return [];
805
- }
806
- const rects = tokens.map(({ lastChild }) => lastChild.getBoundingClientRect());
807
- let acc = 0;
808
- const bottoms = rects.map(({ height }) => {
809
- acc += height + 2;
810
- return acc;
811
- });
812
- return cssErrors.map(({ rule, text: msg, severity, line, column, endLine = line, endColumn = column, fix, }) => {
813
- const i = bottoms.findIndex(bottom => bottom >= line);
814
- return {
815
- range: {
816
- start: getStylelintPos(rects[i], bottoms[i], line, column - 1),
817
- end: getStylelintPos(rects[i], bottoms[i], endLine, endColumn - 1),
818
- },
819
- severity: severity === 'error' ? 1 : 2,
820
- source: 'Stylelint',
821
- code: rule,
822
- message: msg.slice(0, msg.lastIndexOf('(') - 1),
823
- ...fix
824
- ? {
825
- data: [
826
- {
827
- range: {
828
- start: getStylelintPos(rects[i], bottoms[i], code, fix.range[0]),
829
- end: getStylelintPos(rects[i], bottoms[i], code, fix.range[1]),
795
+ NPM: { // eslint-disable-line no-unused-labels
796
+ const tokens = this.findStyleTokens();
797
+ if (tokens.length === 0) {
798
+ return [];
799
+ }
800
+ const code = tokens.map(({ type, tag, lastChild }, i) => `${type === 'ext-attr' ? 'div' : tag}#${i}{\n${(0, common_1.sanitizeInlineStyle)(lastChild.toString())}\n}`).join('\n'), cssErrors = await (0, stylelint_util_1.styleLint)((await document_1.stylelint), code, cssRules);
801
+ if (cssErrors.length === 0) {
802
+ return [];
803
+ }
804
+ const rects = tokens.map(({ lastChild }) => lastChild.getBoundingClientRect());
805
+ let acc = 0;
806
+ const bottoms = rects.map(({ height }) => {
807
+ acc += height + 2;
808
+ return acc;
809
+ });
810
+ return cssErrors.map(({ rule, text: msg, severity, line, column, endLine = line, endColumn = column, fix, }) => {
811
+ const i = (0, search_1.default)(bottoms, line, (bottom, needle) => bottom - needle);
812
+ return {
813
+ range: {
814
+ start: getStylelintPos(rects[i], bottoms[i], line, column - 1),
815
+ end: getStylelintPos(rects[i], bottoms[i], endLine, endColumn - 1),
816
+ },
817
+ severity: severity === 'error' ? 1 : 2,
818
+ source: 'Stylelint',
819
+ code: rule,
820
+ message: msg.slice(0, msg.lastIndexOf('(') - 1),
821
+ ...fix
822
+ ? {
823
+ data: [
824
+ {
825
+ range: getStylelintPos(rects[i], bottoms[i], code, fix.range),
826
+ newText: fix.text,
827
+ title: `Fix: ${rule}`,
828
+ fix: true,
830
829
  },
831
- newText: fix.text,
832
- title: `Fix: ${rule}`,
833
- fix: true,
834
- },
835
- ],
836
- }
837
- : {},
838
- };
839
- });
830
+ ],
831
+ }
832
+ : {},
833
+ };
834
+ });
835
+ }
840
836
  })() :
841
837
  [], jsonDiagnostics = document_1.jsonLSP ?
842
838
  await Promise.all(root.querySelectorAll(jsonSelector).map(async ({ name, lastChild, selfClosing }) => {
@@ -898,42 +894,6 @@ class LanguageService {
898
894
  }));
899
895
  }
900
896
  }
901
- const MathJax = await (0, document_1.loadMathJax)(this.mathjax), data = this.#mathSet, mathDiagnostics = root.querySelectorAll(mathSelector)
902
- .map(token => {
903
- const { selfClosing, innerText, lastChild, name } = token;
904
- if (selfClosing) {
905
- return [];
906
- }
907
- const hasCe = name === 'math' && token.hasAttr('chem'), mathErrors = [...innerText.matchAll(/(?<!\\)\\[a-z]+/giu)]
908
- .filter(([macro]) => !(hasCe && macro === String.raw `\ce` || data.has(macro)))
909
- .map(({ 0: macro, index }) => {
910
- const aIndex = lastChild.getAbsoluteIndex() + index;
911
- return {
912
- range: createRange(root, aIndex, aIndex + macro.length),
913
- severity: 2,
914
- source: 'MathJax',
915
- code: 'UnknownMacro',
916
- message: `Unknown macro "${macro}"`,
917
- };
918
- });
919
- if (MathJax) {
920
- try {
921
- MathJax.tex2mml(name === 'math' ? innerText : String.raw `\ce{${innerText}}`);
922
- }
923
- catch (e) {
924
- if (e && typeof e === 'object' && 'id' in e && 'message' in e) {
925
- mathErrors.push({
926
- range: createNodeRange(lastChild),
927
- severity: 2,
928
- source: 'MathJax',
929
- code: e.id,
930
- message: e.message,
931
- });
932
- }
933
- }
934
- }
935
- return mathErrors;
936
- });
937
897
  /* NOT FOR BROWSER ONLY END */
938
898
  return [
939
899
  diagnostics,
@@ -941,7 +901,6 @@ class LanguageService {
941
901
  jsonDiagnostics,
942
902
  /* NOT FOR BROWSER ONLY */
943
903
  lilypondDiagnostics,
944
- mathDiagnostics,
945
904
  ].flat(2);
946
905
  }
947
906
  /**
@@ -1019,7 +978,7 @@ class LanguageService {
1019
978
  if (!selfClosing) {
1020
979
  const foldingRanges = document_1.jsonLSP.getFoldingRanges(new document_1.EmbeddedJSONDocument(root, lastChild));
1021
980
  if (foldingRanges.length > 0) {
1022
- ranges.push(...foldingRanges);
981
+ Array.prototype.push.apply(ranges, foldingRanges);
1023
982
  }
1024
983
  }
1025
984
  }
@@ -1037,7 +996,7 @@ class LanguageService {
1037
996
  this.config ??= index_1.default.getConfig();
1038
997
  const { articlePath, protocol } = this.config, absolute = articlePath?.includes('//'), protocolRegex = getLinkRegex(protocol);
1039
998
  return (await this.#queue(text))
1040
- .querySelectorAll(`magic-link,ext-link-url,free-ext-link,attr-value,image-parameter#link${absolute ? ',link-target,template-name,invoke-module,magic-word#filepath,magic-word#widget' : ''}`)
999
+ .querySelectorAll(`magic-link,ext-link-url,free-ext-link,attr-value${absolute ? ',link-target,template-name,invoke-module,magic-word#filepath,magic-word#widget' : ''},image-parameter#link,image-parameter#manualthumb`)
1041
1000
  .reverse()
1042
1001
  .map((token) => {
1043
1002
  let name;
@@ -1045,11 +1004,16 @@ class LanguageService {
1045
1004
  ({ name } = token);
1046
1005
  token = token.childNodes[1].lastChild; // eslint-disable-line no-param-reassign
1047
1006
  }
1007
+ else if (token.is('image-parameter')) {
1008
+ ({ name } = token);
1009
+ }
1048
1010
  const { type, parentNode, firstChild, lastChild, childNodes, length } = token, { tag } = parentNode;
1049
1011
  name ??= parentNode.name;
1050
1012
  if (!(type !== 'attr-value'
1013
+ || name === 'cite' && ['blockquote', 'del', 'ins', 'q'].includes(tag)
1051
1014
  || name === 'src' && ['templatestyles', 'img'].includes(tag)
1052
- || name === 'cite' && ['blockquote', 'del', 'ins', 'q'].includes(tag))
1015
+ || name === 'templatename' && tag === 'rss'
1016
+ || name === 'file' && tag === 'phonos')
1053
1017
  || !isPlain(token)) {
1054
1018
  return false;
1055
1019
  }
@@ -1069,34 +1033,34 @@ class LanguageService {
1069
1033
  else if (type === 'link-target' && (parentNode.is('link')
1070
1034
  || parentNode.is('redirect-target')
1071
1035
  || parentNode.is('category'))) {
1072
- if (target.startsWith('/')) {
1036
+ if (/^(?:\.\.)?\//u.test(target)) {
1073
1037
  return false;
1074
1038
  }
1075
1039
  target = parentNode.link.getUrl(articlePath);
1076
1040
  }
1077
- else if (type === 'template-name') {
1041
+ else if (type === 'link-target' || type === 'template-name') {
1078
1042
  target = parentNode.getAttribute('title').getUrl(articlePath);
1079
1043
  }
1080
- else if (['link-target', 'invoke-module', 'parameter-value'].includes(type)
1081
- || type === 'attr-value' && name === 'src' && tag === 'templatestyles'
1082
- || type === 'image-parameter' && !protocolRegex.test(target)) {
1044
+ else if (['invoke-module', 'parameter-value'].includes(type)
1045
+ || type === 'attr-value' && (name === 'src' && tag === 'templatestyles'
1046
+ || name === 'templatename' && tag === 'rss'
1047
+ || name === 'file' && tag === 'phonos')
1048
+ || type === 'image-parameter' && (name === 'manualthumb' || !protocolRegex.test(target))) {
1083
1049
  if (!absolute || target.startsWith('/')) {
1084
1050
  return false;
1085
1051
  }
1086
- let ns = 0;
1087
- switch (type) {
1088
- case 'attr-value':
1089
- ns = 10;
1090
- break;
1091
- case 'invoke-module':
1092
- ns = 828;
1093
- break;
1094
- case 'parameter-value':
1095
- ns = name === 'filepath' ? 6 : 274;
1096
- // no default
1052
+ else if (type === 'image-parameter' && name === 'manualthumb'
1053
+ || type === 'parameter-value' && name === 'filepath'
1054
+ || type === 'attr-value' && tag === 'phonos') {
1055
+ target = `File:${target}`;
1056
+ }
1057
+ else if (type === 'parameter-value') {
1058
+ target = `Widget:${target}`;
1059
+ }
1060
+ else if (type === 'invoke-module') {
1061
+ target = `Module:${target}`;
1097
1062
  }
1098
- const title = index_1.default
1099
- .normalizeTitle(target, ns, false, this.config, { temporary: true });
1063
+ const title = index_1.default.normalizeTitle(target, type === 'attr-value' ? 10 : 0, false, this.config, { temporary: true });
1100
1064
  if (!title.valid) {
1101
1065
  return false;
1102
1066
  }
@@ -1132,7 +1096,8 @@ class LanguageService {
1132
1096
  * @param position position / 位置
1133
1097
  */
1134
1098
  async provideReferences(text, position) {
1135
- const root = await this.#queue(text), { offsetNode, offset } = caretPositionFromWord(root, this.#text, position), element = offsetNode.type === 'text' ? offsetNode.parentNode : offsetNode, node = offset === 0 && (element.type === 'ext-attr-dirty' || element.type === 'html-attr-dirty')
1099
+ const root = await this.#queue(text), { offsetNode, offset } = caretPositionFromWord(root, this.#text, position), element = offsetNode.type === 'text' ? offsetNode.parentNode : offsetNode, node = offset === 0
1100
+ && (element.is('ext-attr-dirty') || element.is('html-attr-dirty'))
1136
1101
  ? element.parentNode.parentNode
1137
1102
  : element, { type } = node, refName = getRefName(node), refGroup = getRefGroup(node);
1138
1103
  if (!refName && !refGroup && !referenceTypes.has(type)) {
@@ -1275,7 +1240,7 @@ class LanguageService {
1275
1240
  }
1276
1241
  /* NOT FOR BROWSER ONLY */
1277
1242
  }
1278
- else if ((0, exports.isAttr)(offsetNode, true)) {
1243
+ else if (isAttr(offsetNode, true)) {
1279
1244
  const textDoc = new document_1.EmbeddedCSSDocument(root, offsetNode);
1280
1245
  return document_1.cssLSP.doHover(textDoc, position, textDoc.styleSheet) ?? undefined;
1281
1246
  }
@@ -1398,7 +1363,7 @@ class LanguageService {
1398
1363
  }
1399
1364
  /** @private */
1400
1365
  findStyleTokens() {
1401
- return this.#done.querySelectorAll(cssSelector).filter(({ lastChild }) => (0, exports.isAttr)(lastChild));
1366
+ return this.#done.querySelectorAll(cssSelector).filter(({ lastChild }) => isAttr(lastChild));
1402
1367
  }
1403
1368
  /**
1404
1369
  * Provide refactoring actions
package/dist/lib/node.js CHANGED
@@ -39,6 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
40
  exports.AstNode = void 0;
41
41
  /* eslint-disable @typescript-eslint/no-base-to-string */
42
+ const search_1 = __importDefault(require("../util/search"));
42
43
  const lint_1 = require("../util/lint");
43
44
  const debug_1 = require("../util/debug");
44
45
  const cached_1 = require("../mixin/cached");
@@ -291,7 +292,7 @@ let AstNode = (() => {
291
292
  const { length } = String(this);
292
293
  index += index < 0 ? length : 0;
293
294
  if (index >= 0 && index <= length) {
294
- const lines = this.getLines(), top = lines.findIndex(([, , end]) => index <= end);
295
+ const lines = this.getLines(), top = (0, search_1.default)(lines, index, ([, , end], needle) => end - needle);
295
296
  return { top, left: index - lines[top][1] };
296
297
  }
297
298
  return undefined;
@@ -315,30 +316,28 @@ let AstNode = (() => {
315
316
  * @param j rank of the child node / 子节点序号
316
317
  */
317
318
  getRelativeIndex(j) {
318
- LINT: { // eslint-disable-line no-unused-labels
319
- if (j === undefined) {
320
- const { parentNode } = this;
321
- return parentNode
322
- ? parentNode.getRelativeIndex(parentNode.childNodes.indexOf(this))
323
- : 0;
324
- }
325
- /* NOT FOR BROWSER */
326
- this.verifyChild(j, 1);
327
- /* NOT FOR BROWSER END */
328
- return (0, lint_1.cache)(this.#rIndex[j], () => {
329
- const { childNodes } = this, n = j + (j < 0 ? childNodes.length : 0);
330
- let acc = this.getAttribute('padding');
331
- for (let i = 0; i < n; i++) {
332
- if (index_1.default.viewOnly) {
333
- this.#rIndex[i] = [debug_1.Shadow.rev, acc];
334
- }
335
- acc += childNodes[i].toString().length + this.getGaps(i);
336
- }
337
- return acc;
338
- }, value => {
339
- this.#rIndex[j] = value;
340
- });
319
+ if (j === undefined) {
320
+ const { parentNode } = this;
321
+ return parentNode
322
+ ? parentNode.getRelativeIndex(parentNode.childNodes.indexOf(this))
323
+ : 0;
341
324
  }
325
+ /* NOT FOR BROWSER */
326
+ this.verifyChild(j, 1);
327
+ /* NOT FOR BROWSER END */
328
+ return (0, lint_1.cache)(this.#rIndex[j], () => {
329
+ const { childNodes } = this, n = j + (j < 0 ? childNodes.length : 0);
330
+ let acc = this.getAttribute('padding');
331
+ for (let i = 0; i < n; i++) {
332
+ if (index_1.default.viewOnly) {
333
+ this.#rIndex[i] = [debug_1.Shadow.rev, acc];
334
+ }
335
+ acc += childNodes[i].toString().length + this.getGaps(i);
336
+ }
337
+ return acc;
338
+ }, value => {
339
+ this.#rIndex[j] = value;
340
+ });
342
341
  }
343
342
  /**
344
343
  * Get the absolute character index of the current node
@@ -346,7 +345,8 @@ let AstNode = (() => {
346
345
  * 获取当前节点的绝对位置
347
346
  */
348
347
  getAbsoluteIndex() {
349
- LINT: return (0, lint_1.cache)(// eslint-disable-line no-unused-labels
348
+ // 也用于Prism-Wiki
349
+ return (0, lint_1.cache)(// eslint-disable-line no-unused-labels
350
350
  this.#aIndex, () => {
351
351
  const { parentNode } = this;
352
352
  return parentNode ? parentNode.getAbsoluteIndex() + this.getRelativeIndex() : 0;
package/dist/lib/range.js CHANGED
@@ -618,7 +618,7 @@ let AstRange = (() => {
618
618
  * @param elements nodes to be inserted / 插入节点
619
619
  */
620
620
  append(...elements) {
621
- this.after(...elements);
621
+ this.#after(elements);
622
622
  const { endContainer } = this;
623
623
  if (endContainer.type === 'text') {
624
624
  this.#endContainer = endContainer.parentNode;
@@ -633,7 +633,7 @@ let AstRange = (() => {
633
633
  * @param elements nodes to be inserted / 插入节点
634
634
  */
635
635
  prepend(...elements) {
636
- this.before(...elements);
636
+ AstRange.prototype.before.apply(this, elements);
637
637
  const { startContainer } = this;
638
638
  if (startContainer.type === 'text') {
639
639
  this.#startContainer = startContainer.parentNode;