wikiparser-node 1.18.2 → 1.18.4

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 (76) hide show
  1. package/README.md +6 -1
  2. package/bundle/bundle-es7.min.js +29 -28
  3. package/bundle/bundle-lsp.min.js +31 -30
  4. package/bundle/bundle.min.js +30 -29
  5. package/config/minimum.json +7 -0
  6. package/dist/addon/token.js +37 -28
  7. package/dist/addon/transclude.js +1 -3
  8. package/dist/base.d.mts +4 -0
  9. package/dist/base.d.ts +4 -0
  10. package/dist/base.js +1 -0
  11. package/dist/base.mjs +2 -1
  12. package/dist/bin/config.js +3 -2
  13. package/dist/index.d.ts +14 -1
  14. package/dist/index.js +72 -72
  15. package/dist/lib/element.d.ts +6 -0
  16. package/dist/lib/element.js +543 -466
  17. package/dist/lib/lsp.d.ts +1 -0
  18. package/dist/lib/lsp.js +20 -15
  19. package/dist/lib/redirectMap.d.ts +7 -0
  20. package/dist/lib/redirectMap.js +31 -0
  21. package/dist/lib/text.d.ts +2 -2
  22. package/dist/lib/text.js +385 -325
  23. package/dist/lib/title.d.ts +23 -4
  24. package/dist/lib/title.js +17 -5
  25. package/dist/mixin/noEscape.d.ts +4 -0
  26. package/dist/mixin/noEscape.js +22 -0
  27. package/dist/mixin/readOnly.d.ts +4 -0
  28. package/dist/mixin/readOnly.js +26 -0
  29. package/dist/parser/braces.js +79 -37
  30. package/dist/parser/commentAndExt.js +5 -16
  31. package/dist/parser/links.js +1 -1
  32. package/dist/parser/quotes.js +1 -1
  33. package/dist/parser/redirect.js +1 -3
  34. package/dist/src/arg.js +253 -202
  35. package/dist/src/attribute.d.ts +0 -5
  36. package/dist/src/attribute.js +4 -8
  37. package/dist/src/converter.js +213 -162
  38. package/dist/src/gallery.js +1 -2
  39. package/dist/src/heading.js +5 -6
  40. package/dist/src/imageParameter.js +16 -16
  41. package/dist/src/imagemap.js +3 -2
  42. package/dist/src/index.d.ts +1 -1
  43. package/dist/src/index.js +722 -694
  44. package/dist/src/link/base.js +292 -241
  45. package/dist/src/link/file.js +13 -17
  46. package/dist/src/link/galleryImage.js +1 -1
  47. package/dist/src/link/redirectTarget.js +1 -2
  48. package/dist/src/magicLink.d.ts +0 -6
  49. package/dist/src/magicLink.js +5 -15
  50. package/dist/src/nested.js +7 -7
  51. package/dist/src/nowiki/base.js +2 -1
  52. package/dist/src/nowiki/index.js +4 -3
  53. package/dist/src/onlyinclude.js +95 -44
  54. package/dist/src/parameter.d.ts +0 -6
  55. package/dist/src/parameter.js +1 -13
  56. package/dist/src/redirect.js +6 -6
  57. package/dist/src/syntax.d.ts +4 -1
  58. package/dist/src/syntax.js +4 -1
  59. package/dist/src/table/base.d.ts +0 -5
  60. package/dist/src/table/base.js +2 -9
  61. package/dist/src/table/index.d.ts +1 -0
  62. package/dist/src/table/index.js +7 -4
  63. package/dist/src/table/td.d.ts +1 -0
  64. package/dist/src/table/td.js +2 -3
  65. package/dist/src/table/trBase.js +31 -14
  66. package/dist/src/tagPair/index.js +2 -1
  67. package/dist/src/transclude.js +713 -657
  68. package/dist/util/debug.js +10 -3
  69. package/dist/util/diff.js +1 -1
  70. package/dist/util/string.js +4 -5
  71. package/extensions/dist/base.js +8 -6
  72. package/extensions/dist/lint.js +1 -1
  73. package/extensions/es7/base.js +8 -6
  74. package/extensions/es7/lint.js +1 -1
  75. package/extensions/ui.css +1 -1
  76. package/package.json +3 -3
package/dist/lib/lsp.d.ts CHANGED
@@ -20,6 +20,7 @@ export declare const isAttr: ({ type, parentNode, length, firstChild }: Token, s
20
20
  /** VSCode-style language service */
21
21
  export declare class LanguageService implements LanguageServiceBase {
22
22
  #private;
23
+ /** @since v1.17.1 */
23
24
  include: boolean;
24
25
  lilypond: string;
25
26
  /** @param uri 任务标识 */
package/dist/lib/lsp.js CHANGED
@@ -19,13 +19,13 @@ const util_1 = __importDefault(require("util"));
19
19
  const child_process_1 = require("child_process");
20
20
  const crypto_1 = require("crypto");
21
21
  const stylelint_1 = require("@bhsd/common/dist/stylelint");
22
- const config_1 = __importDefault(require("../bin/config"));
23
22
  const document_1 = require("./document");
24
23
  /** @see https://www.npmjs.com/package/stylelint-config-recommended */
25
24
  const cssRules = {
26
25
  'block-no-empty': null,
27
26
  'property-no-unknown': null,
28
27
  }, jsonSelector = document_1.jsonTags.map(s => `ext-inner#${s}`).join(), scores = new Map();
28
+ let colors;
29
29
  /* NOT FOR BROWSER ONLY END */
30
30
  exports.tasks = new WeakMap();
31
31
  const refTags = new Set(['ref']), referencesTags = new Set(['ref', 'references']), nameAttrs = new Set(['name', 'extends', 'follow']), groupAttrs = new Set(['group']), renameTypes = new Set([
@@ -43,6 +43,8 @@ const refTags = new Set(['ref']), referencesTags = new Set(['ref', 'references']
43
43
  'magic-word-name',
44
44
  ...renameTypes,
45
45
  ]), plainTypes = new Set(['text', 'comment', 'noinclude', 'include']), cssSelector = ['ext', 'html', 'table'].map(s => `${s}-attr#style`).join();
46
+ /^(?:http:\/\/|\/\/)/iu; // eslint-disable-line @typescript-eslint/no-unused-expressions
47
+ const getLinkRegex = (0, common_1.getRegex)(protocol => new RegExp(`^(?:${protocol}|//)`, 'iu'));
46
48
  /**
47
49
  * Check if a token is a plain attribute.
48
50
  * @param token
@@ -276,6 +278,7 @@ class LanguageService {
276
278
  #config;
277
279
  #include;
278
280
  #completionConfig;
281
+ /** @since v1.17.1 */
279
282
  include = true;
280
283
  /** @private */
281
284
  config;
@@ -409,11 +412,14 @@ class LanguageService {
409
412
  async provideDocumentColors(rgba, text, hsl = true) {
410
413
  const root = await this.#queue(text);
411
414
  /* NOT FOR BROWSER ONLY */
412
- let colors;
415
+ /* eslint-disable require-atomic-updates */
413
416
  try {
414
- colors = new RegExp(String.raw `\b${Object.keys((await import('color-name')).default).join('|')}\b`, 'giu');
417
+ colors ??= new RegExp(String.raw `\b${Object.keys((await import('color-name')).default).join('|')}\b`, 'giu');
415
418
  }
416
- catch { }
419
+ catch {
420
+ colors = false;
421
+ }
422
+ /* eslint-enable require-atomic-updates */
417
423
  /* NOT FOR BROWSER ONLY END */
418
424
  return root.querySelectorAll('attr-value,parameter-value,arg-default').reverse()
419
425
  .flatMap(token => {
@@ -642,7 +648,7 @@ class LanguageService {
642
648
  if (t === 'magic-word' && n !== 'invoke') {
643
649
  return undefined;
644
650
  }
645
- const key = this.#text.slice(cur.getAbsoluteIndex(), root.indexFromPos(line, character)).trimStart(), [module, func] = t === 'magic-word' ? transclusion.getModule() : [];
651
+ const key = this.#text.slice(cur.getAbsoluteIndex(), root.indexFromPos(line, character)).trimStart(), [mod, func] = t === 'magic-word' ? transclusion.getModule() : [];
646
652
  return key
647
653
  ? getCompletion(root.querySelectorAll('parameter').filter(token => {
648
654
  if (token === parentNode
@@ -655,7 +661,7 @@ class LanguageService {
655
661
  return true;
656
662
  }
657
663
  const [m, f] = token.parentNode.getModule();
658
- return m === module && f === func;
664
+ return m === mod && f === func;
659
665
  }).map(({ name }) => name), 'Variable', key, position, type === 'parameter-value' ? '=' : '')
660
666
  : undefined;
661
667
  /* NOT FOR BROWSER ONLY */
@@ -898,8 +904,7 @@ class LanguageService {
898
904
  */
899
905
  async provideLinks(text) {
900
906
  this.config ??= index_1.default.getConfig();
901
- /^(?:http:\/\/|\/\/)/iu; // eslint-disable-line @typescript-eslint/no-unused-expressions
902
- const { articlePath, protocol } = this.config, absolute = articlePath?.includes('//'), protocolRegex = new RegExp(`^(?:${protocol}|//)`, 'iu');
907
+ const { articlePath, protocol } = this.config, absolute = articlePath?.includes('//'), protocolRegex = getLinkRegex(protocol);
903
908
  return (await this.#queue(text))
904
909
  .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' : ''}`)
905
910
  .reverse()
@@ -959,8 +964,8 @@ class LanguageService {
959
964
  ns = name === 'filepath' ? 6 : 274;
960
965
  // no default
961
966
  }
962
- const title = index_1.default.normalizeTitle(target, ns, false, this.config, true);
963
- /* istanbul ignore if */
967
+ const title = index_1.default
968
+ .normalizeTitle(target, ns, false, this.config, { temporary: true });
964
969
  if (!title.valid) {
965
970
  return false;
966
971
  }
@@ -1116,13 +1121,13 @@ class LanguageService {
1116
1121
  }
1117
1122
  else if (type === 'magic-word-name') {
1118
1123
  info = this.#getParserFunction(parentNode.name);
1119
- f = offsetNode.toString(true).trim();
1124
+ f = offsetNode.text().trim();
1120
1125
  colon = parentNode.getAttribute('colon');
1121
1126
  }
1122
1127
  else if (offsetNode.is('magic-word') && !offsetNode.modifier && length === 1
1123
1128
  && (offset > 0 || root.posFromIndex(offsetNode.getAbsoluteIndex()).left === position.character)) {
1124
1129
  info = this.#getParserFunction(name);
1125
- f = offsetNode.firstChild.toString(true).trim();
1130
+ f = offsetNode.firstChild.text().trim();
1126
1131
  colon = offsetNode.getAttribute('colon');
1127
1132
  }
1128
1133
  else if ((offsetNode.is('magic-word') || offsetNode.is('template'))
@@ -1209,7 +1214,7 @@ class LanguageService {
1209
1214
  }
1210
1215
  const n = childNodes.length - 1, candidates = info.signatures.filter(params => (params.length >= n || params[params.length - 1]?.rest)
1211
1216
  && params.every(({ label, const: c }, i) => {
1212
- const p = c && i < n && childNodes[i + 1]?.toString(true).trim();
1217
+ const p = c && i < n && childNodes[i + 1]?.text().trim();
1213
1218
  return !p || label.toLowerCase().includes(p.toLowerCase());
1214
1219
  }));
1215
1220
  if (candidates.length === 0) {
@@ -1222,7 +1227,7 @@ class LanguageService {
1222
1227
  break;
1223
1228
  }
1224
1229
  }
1225
- const f = firstChild.toString(true).trim(), colon = lastChild.getAttribute('colon');
1230
+ const f = firstChild.text().trim(), colon = lastChild.getAttribute('colon');
1226
1231
  return {
1227
1232
  signatures: candidates.map((params) => ({
1228
1233
  label: `{{${f}${params.length === 0 ? '' : colon}${params.map(({ label }) => label).join('|')}}}`,
@@ -1337,7 +1342,7 @@ class LanguageService {
1337
1342
  this.config = index_1.default.getConfig(config);
1338
1343
  }
1339
1344
  catch {
1340
- this.config = index_1.default.getConfig(await (0, config_1.default)(site, `${mt[0]}/w`));
1345
+ this.config = await index_1.default.fetchConfig(site, `${mt[0]}/w`);
1341
1346
  }
1342
1347
  Object.assign(this.config, { articlePath: `${mt[0]}/wiki/` });
1343
1348
  }
@@ -0,0 +1,7 @@
1
+ /** 重定向列表 */
2
+ export declare class RedirectMap extends Map<string, string> {
3
+ #private;
4
+ /** @ignore */
5
+ constructor(entries?: Iterable<[string, string]> | Record<string, string>, redirect?: boolean);
6
+ set(key: string, value: string): this;
7
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RedirectMap = void 0;
4
+ const constants_1 = require("../util/constants");
5
+ /**
6
+ * 快速规范化页面标题
7
+ * @param title 标题
8
+ */
9
+ const normalizeTitle = (title) => {
10
+ const Parser = require('../index');
11
+ return String(Parser.normalizeTitle(title, 0, false, undefined, { temporary: true }));
12
+ };
13
+ /** 重定向列表 */
14
+ class RedirectMap extends Map {
15
+ #redirect;
16
+ /** @ignore */
17
+ constructor(entries, redirect = true) {
18
+ super();
19
+ this.#redirect = redirect;
20
+ if (entries) {
21
+ for (const [k, v] of Symbol.iterator in entries ? entries : Object.entries(entries)) {
22
+ this.set(k, v);
23
+ }
24
+ }
25
+ }
26
+ set(key, value) {
27
+ return super.set(normalizeTitle(key), this.#redirect ? normalizeTitle(value) : value);
28
+ }
29
+ }
30
+ exports.RedirectMap = RedirectMap;
31
+ constants_1.classes['RedirectMap'] = __filename;
@@ -69,9 +69,9 @@ export declare class AstText extends AstNode {
69
69
  */
70
70
  splitText(offset: number): AstText;
71
71
  /**
72
- * Escape `=`
72
+ * Escape `=` and `|`
73
73
  *
74
- * 转义 `=`
74
+ * 转义 `=` 和 `|`
75
75
  */
76
76
  escape(): void;
77
77
  /**