wikiparser-node 1.42.0 → 1.44.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/README.md +45 -19
  2. package/bundle/bundle-es8.min.js +40 -31
  3. package/bundle/bundle-lsp.min.js +35 -26
  4. package/bundle/bundle.min.js +22 -22
  5. package/config/default.json +31 -0
  6. package/config/moegirl.json +39 -1
  7. package/dist/addon/attribute.js +4 -6
  8. package/dist/addon/link.js +3 -2
  9. package/dist/addon/transclude.js +16 -26
  10. package/dist/base.d.mts +4 -4
  11. package/dist/base.d.ts +4 -4
  12. package/dist/base.js +1 -0
  13. package/dist/base.mjs +1 -0
  14. package/dist/bin/config.js +6 -5
  15. package/dist/extensions/typings.d.ts +1 -1
  16. package/dist/index.js +8 -5
  17. package/dist/lib/document.d.ts +17 -14
  18. package/dist/lib/document.js +5 -5
  19. package/dist/lib/lintConfig.js +4 -1
  20. package/dist/lib/ranges.js +2 -2
  21. package/dist/lib/title.d.ts +4 -1
  22. package/dist/lib/title.js +5 -1
  23. package/dist/mixin/attributesParent.js +1 -1
  24. package/dist/parser/converter.js +1 -1
  25. package/dist/render/expand.js +4 -2
  26. package/dist/render/extension.js +30 -24
  27. package/dist/render/magicWords.js +25 -132
  28. package/dist/render/math.js +31 -0
  29. package/dist/render/syntaxhighlight.js +3 -0
  30. package/dist/src/arg.js +1 -2
  31. package/dist/src/atom.js +1 -1
  32. package/dist/src/attributes.d.ts +1 -0
  33. package/dist/src/attributes.js +27 -3
  34. package/dist/src/converterFlags.js +10 -5
  35. package/dist/src/converterRule.js +5 -7
  36. package/dist/src/heading.js +1 -2
  37. package/dist/src/imageParameter.d.ts +4 -3
  38. package/dist/src/imageParameter.js +16 -9
  39. package/dist/src/index.js +1 -1
  40. package/dist/src/link/base.js +1 -1
  41. package/dist/src/link/file.d.ts +5 -4
  42. package/dist/src/link/file.js +14 -12
  43. package/dist/src/magicLink.js +1 -2
  44. package/dist/src/nowiki/index.d.ts +1 -0
  45. package/dist/src/nowiki/index.js +40 -28
  46. package/dist/src/onlyinclude.js +1 -2
  47. package/dist/src/parameter.js +1 -2
  48. package/dist/src/table/index.js +1 -2
  49. package/dist/src/table/td.js +4 -6
  50. package/dist/src/tagPair/ext.d.ts +1 -0
  51. package/dist/src/tagPair/ext.js +36 -3
  52. package/dist/src/transclude.js +5 -3
  53. package/dist/util/search.js +24 -6
  54. package/dist/util/string.js +7 -1
  55. package/extensions/dist/base.js +1 -1
  56. package/extensions/dist/codejar.js +1 -1
  57. package/i18n/en.json +7 -0
  58. package/i18n/zh-hans.json +7 -0
  59. package/i18n/zh-hant.json +7 -0
  60. package/package.json +64 -21
@@ -1,9 +1,15 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.renderExt = void 0;
6
+ exports.renderExt = exports.packedModes = void 0;
4
7
  const constants_1 = require("../util/constants");
5
8
  const string_1 = require("../util/string");
6
9
  const sharable_1 = require("../util/sharable");
10
+ const index_1 = __importDefault(require("../index"));
11
+ exports.packedModes = new Set(['packed', 'packed-hover', 'packed-overlay']);
12
+ const galleryModes = new Set([...exports.packedModes, 'nolines', 'slideshow']);
7
13
  /** @ignore */
8
14
  const getCiteNoteId = (i, refName) => `cite_note${refName ? `-${(0, string_1.sanitizeAttr)(refName, true)}` : ''}-${i}`, getCiteRefId = (i, count, refName) => `cite_ref-${refName ? `${(0, string_1.sanitizeAttr)(refName, true)}_${i}-${count - 1}` : i}`, updateRef = (ref, content, dir) => {
9
15
  if (!ref.content) {
@@ -41,14 +47,12 @@ const renderExt = (token, opt) => {
41
47
  .trim()}${padding}</div>`;
42
48
  }
43
49
  case 'gallery': {
44
- const caption = firstChild.getAttrToken('caption'), perrow = parseInt(firstChild.getAttr('perrow') || ''), { classList } = firstChild, mode = firstChild.getAttr('mode')?.toLowerCase(), nolines = mode === 'nolines', padding = nolines ? 9 : 43;
45
- classList.add('gallery');
46
- if (nolines) {
47
- classList.add('mw-gallery-nolines');
48
- }
49
- else if (!mode || mode === 'traditional') {
50
- classList.add('mw-gallery-traditional');
50
+ const caption = firstChild.getAttrToken('caption'), perrow = parseInt(firstChild.getAttr('perrow') || ''), { classList } = firstChild, mode = firstChild.getAttr('mode')?.toLowerCase(), padding = mode === 'nolines' ? 9 : 43;
51
+ if (mode === 'slideshow' && firstChild.hasAttr('showthumbnails')) {
52
+ firstChild.setAttr('data-showthumbnails', '1');
51
53
  }
54
+ classList.add('gallery');
55
+ classList.add(`mw-gallery-${galleryModes.has(mode) ? mode : 'traditional'}`);
52
56
  if (perrow > 0) {
53
57
  firstChild.setAttr('style', `max-width: ${(lastChild.widths + padding) * perrow}px;${firstChild.getAttr('style') || ''}`);
54
58
  }
@@ -121,7 +125,7 @@ const renderExt = (token, opt) => {
121
125
  * 是否添加id属性
122
126
  * @param i 行号
123
127
  */
124
- g = (i) => begin && `<span id="${begin}${i}">`;
128
+ g = (i) => begin && `<span id="${(0, string_1.sanitizeId)(begin)}${i}">`;
125
129
  let mt = re.exec(html), i = 1, lastIndex = 0, output = g(i) + f(1) + (lineReplace?.replaceAll('$1', String(start)) ?? '');
126
130
  while (mt) {
127
131
  if (mt[0] === '\n') {
@@ -160,33 +164,28 @@ const renderExt = (token, opt) => {
160
164
  if (!refs) {
161
165
  return '';
162
166
  }
163
- const follow = firstChild.getAttr('follow') || '';
164
- if (/^\d+$/u.test(follow)) {
165
- return '';
167
+ const linted = firstChild.lintRef() || token.lintRef();
168
+ if (linted) {
169
+ return `<span class="error mw-ext-cite-error">Cite error: ${(0, string_1.sanitize)(index_1.default.msg(linted))}</span>`;
166
170
  }
167
171
  let refName = firstChild.getAttr('name') || '';
168
172
  if (!/\D/u.test(refName)) {
169
173
  refName = '';
170
174
  }
171
- else if (refName && follow) {
172
- return '';
173
- }
174
175
  let dir = firstChild.getAttr('dir')?.toLowerCase();
175
176
  if (dir !== 'ltr' && dir !== 'rtl') {
176
177
  dir = undefined;
177
178
  }
178
179
  const text = token.innerText?.trim(), references = token.closest('ext#references');
179
180
  if (references) {
180
- const { referencesGroup } = refs.get(references.getAttr('group') || '');
181
- if (refName && text) {
182
- const ref = referencesGroup.find(({ name: n }) => n === refName);
183
- if (ref) {
184
- updateRef(ref, lastChild, dir);
185
- }
181
+ const ref = refs.get(references.getAttr('group') || '').referencesGroup
182
+ .find(({ name: n }) => n === refName);
183
+ if (ref) {
184
+ updateRef(ref, lastChild, dir);
186
185
  }
187
186
  return '';
188
187
  }
189
- else if (!refName && !text || text && /<references\b[^>]*>/iu.test(text)) {
188
+ else if (text && /<references\b[^>]*>/iu.test(text)) {
190
189
  return '';
191
190
  }
192
191
  else if (text && /<ref\b[^>]*>/iu.test(text)) {
@@ -202,7 +201,7 @@ const renderExt = (token, opt) => {
202
201
  if (!refs.has(group)) {
203
202
  refs.set(group, { referencesGroup: [], follows: [] });
204
203
  }
205
- const { referencesGroup, follows } = refs.get(group);
204
+ const { referencesGroup, follows } = refs.get(group), follow = firstChild.getAttr('follow') || '';
206
205
  if (follow) {
207
206
  const ref = referencesGroup.find(({ name: n }) => n === follow);
208
207
  if (ref) {
@@ -260,7 +259,7 @@ const renderExt = (token, opt) => {
260
259
  if (referencesGroup.length === 0 && follows.length === 0) {
261
260
  return '';
262
261
  }
263
- let ol = `<ol class="references"${group && ` data-mw-group="${group}"`}>`;
262
+ let ol = `<ol class="references"${group && ` data-mw-group="${(0, string_1.sanitizeId)(group)}"`}>`;
264
263
  for (const { content } of follows) {
265
264
  ol += `\n<p><span class="reference-text">${content.toHtmlInternal()}</span>\n</p>`;
266
265
  }
@@ -276,6 +275,13 @@ const renderExt = (token, opt) => {
276
275
  ? ol
277
276
  : `<div class="mw-references-wrap${referencesGroup.length > 10 ? ' mw-references-columns' : ''}">${ol}</div>`;
278
277
  }
278
+ case 'math':
279
+ case 'chem':
280
+ case 'ce': {
281
+ const { texToSvg } = require('./math');
282
+ const id = firstChild.getAttr('id');
283
+ return `<span class="mwe-math-element mwe-math-element-${firstChild.getAttr('display') === 'block' ? 'block' : 'inline'}"${id ? ` id="${(0, string_1.sanitizeId)(id)}"` : ''}>${texToSvg?.(lastChild.texvcCheck()) ?? ''}</span>`;
284
+ }
279
285
  default:
280
286
  return '';
281
287
  }
@@ -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.expandMagicWord = exports.expandedMagicWords = void 0;
6
+ exports.expandMagicWord = void 0;
7
7
  /* eslint-disable jsdoc/require-jsdoc */
8
8
  const path_1 = require("path");
9
9
  const string_1 = require("../util/string");
@@ -11,132 +11,6 @@ const constants_1 = require("../util/constants");
11
11
  const html_1 = require("../util/html");
12
12
  const index_1 = __importDefault(require("../index"));
13
13
  const index_2 = require("../src/index");
14
- const magicWords = [
15
- 'currentmonth',
16
- 'currentmonth1',
17
- 'currentmonthname',
18
- 'currentmonthnamegen',
19
- 'currentmonthabbrev',
20
- 'currentday',
21
- 'currentday2',
22
- 'currentdayname',
23
- 'currentyear',
24
- 'currenttime',
25
- 'currenthour',
26
- 'currentweek',
27
- 'currentdow',
28
- 'currenttimestamp',
29
- 'localmonth',
30
- 'localmonth1',
31
- 'localmonthname',
32
- 'localmonthnamegen',
33
- 'localmonthabbrev',
34
- 'localday',
35
- 'localday2',
36
- 'localdayname',
37
- 'localyear',
38
- 'localtime',
39
- 'localhour',
40
- 'localweek',
41
- 'localdow',
42
- 'localtimestamp',
43
- 'articlepath',
44
- 'server',
45
- 'servername',
46
- 'directionmark',
47
- 'contentlanguage',
48
- 'pagelanguage',
49
- 'userlanguage',
50
- 'revisionsize',
51
- 'numberofarticles',
52
- 'numberoffiles',
53
- 'numberofusers',
54
- 'numberofactiveusers',
55
- 'numberofpages',
56
- 'numberofadmins',
57
- 'numberofedits',
58
- 'numberingroup',
59
- 'pagesincategory',
60
- 'pagesize',
61
- 'ns',
62
- 'nse',
63
- 'urlencode',
64
- 'lcfirst',
65
- 'ucfirst',
66
- 'lc',
67
- 'uc',
68
- 'localurl',
69
- 'localurle',
70
- 'fullurl',
71
- 'fullurle',
72
- 'canonicalurl',
73
- 'canonicalurle',
74
- 'gender',
75
- 'formal',
76
- 'displaytitle',
77
- 'defaultsort',
78
- 'revisionuser',
79
- 'translation',
80
- 'revisionid',
81
- 'revisionday',
82
- 'revisionday2',
83
- 'revisionmonth',
84
- 'revisionmonth1',
85
- 'revisionyear',
86
- 'revisiontimestamp',
87
- 'namespace',
88
- 'namespacee',
89
- 'namespacenumber',
90
- 'talkspace',
91
- 'talkspacee',
92
- 'subjectspace',
93
- 'subjectspacee',
94
- 'pagename',
95
- 'pagenamee',
96
- 'fullpagename',
97
- 'fullpagenamee',
98
- 'subpagename',
99
- 'subpagenamee',
100
- 'rootpagename',
101
- 'rootpagenamee',
102
- 'basepagename',
103
- 'basepagenamee',
104
- 'talkpagename',
105
- 'talkpagenamee',
106
- 'subjectpagename',
107
- 'subjectpagenamee',
108
- 'language',
109
- 'dir',
110
- 'padleft',
111
- 'padright',
112
- 'anchorencode',
113
- 'special',
114
- 'speciale',
115
- 'pageid',
116
- 'contentmodel',
117
- 'tag',
118
- 'rel2abs',
119
- 'titleparts',
120
- 'len',
121
- 'pos',
122
- 'rpos',
123
- 'sub',
124
- 'count',
125
- 'replace',
126
- 'explode',
127
- 'urldecode',
128
- 'if',
129
- 'ifeq',
130
- 'ifexist',
131
- 'iferror',
132
- 'switch',
133
- 'plural',
134
- 'expr',
135
- '!',
136
- '=',
137
- 'filepath',
138
- ];
139
- exports.expandedMagicWords = new Set(magicWords);
140
14
  function urlFunction(config, args, local) {
141
15
  const [value, query] = args, fallback = (local ? '' : []);
142
16
  if (value.includes('\0')) {
@@ -297,7 +171,15 @@ const parseUrl = ({ server = '', articlePath = '' }) => {
297
171
  }, isError = (s) => /<(?:strong|span|p|div)\s+(?:[^\s>]+\s+)*?class="\s*(?:[^"\s>]+\s+)*?error(?:\s[^">]*)?"/u.test(s), splitArg = (arg) => {
298
172
  const i = arg.indexOf('=');
299
173
  return i !== -1 && [arg.slice(0, i).trim(), arg.slice(i + 1).trim()];
300
- }, isKnown = (s) => !/\0\d+[tm]\x7F/u.test(s);
174
+ }, isKnown = (s) => !/\0\d+[tm]\x7F/u.test(s), expr = (s) => {
175
+ try {
176
+ const { evaluateExpr } = require('mediawiki-expr');
177
+ return evaluateExpr(s);
178
+ }
179
+ catch {
180
+ throw new Error('Magic words "#expr" and "#ifexpr" require NPM package mediawiki-expr');
181
+ }
182
+ };
301
183
  /**
302
184
  * 展开魔术字
303
185
  * @param name 魔术字名称
@@ -682,11 +564,12 @@ const expandMagicWord = (name, args, page = '', config = index_1.default.getConf
682
564
  ? ''
683
565
  : isKnown(arg0) && isKnown(args[1]) && (args[cmp(arg0, args[1], true) ? 2 : 3] ?? '');
684
566
  case 'if':
685
- case 'iferror':
686
567
  if (args.length === 1) {
687
568
  return '';
688
569
  }
689
- return (name === 'if' ? strip : isError)((0, string_1.decodeHtml)(arg0)) ? args[1] : isKnown(arg0) && (args[2] ?? '');
570
+ return strip((0, string_1.decodeHtml)(arg0)) ? args[1] : isKnown(arg0) && (args[2] ?? '');
571
+ case 'iferror':
572
+ return isError((0, string_1.decodeHtml)(arg0)) ? args[1] ?? '' : isKnown(arg0) && (args[2] ?? arg0);
690
573
  case 'ifexist': {
691
574
  if (args.length === 1) {
692
575
  return '';
@@ -751,7 +634,17 @@ const expandMagicWord = (name, args, page = '', config = index_1.default.getConf
751
634
  return args[n === 1 || n === -1 ? 1 : 2] ?? '';
752
635
  }
753
636
  case 'expr':
754
- return !Number.isNaN(Number(arg0)) && arg0;
637
+ return arg0 && isKnown(arg0) && String(expr(arg0));
638
+ case 'ifexpr': {
639
+ if (!isKnown(arg0)) {
640
+ return false;
641
+ }
642
+ const evaluated = arg0 && expr(arg0);
643
+ if (evaluated && typeof evaluated === 'string') {
644
+ return evaluated;
645
+ }
646
+ return evaluated ? args[1] ?? '' : args[2] ?? '';
647
+ }
755
648
  case '!':
756
649
  return '|';
757
650
  case '=':
@@ -772,7 +665,7 @@ const expandMagicWord = (name, args, page = '', config = index_1.default.getConf
772
665
  if (height) {
773
666
  query.set('height', height);
774
667
  }
775
- return localurl(config, [redirect, query.toString()]);
668
+ return localurl(config, [redirect, String(query)]);
776
669
  }
777
670
  default:
778
671
  throw new RangeError(`Unsupported magic word: ${name}`);
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.texToSvg = void 0;
4
+ const string_1 = require("../util/string");
5
+ const document_1 = require("../lib/document");
6
+ exports.texToSvg = (() => {
7
+ const texvcjs = (0, document_1.loadTexvcjs)();
8
+ if (!texvcjs) {
9
+ return undefined;
10
+ }
11
+ try {
12
+ const katex = require('katex');
13
+ require('katex/contrib/mhchem');
14
+ return ([result, , tex]) => {
15
+ if (result.status === '+') {
16
+ tex = result.output;
17
+ try {
18
+ return (0, string_1.newline)(katex.renderToString(tex, {
19
+ throwOnError: false,
20
+ macros: { '\\mbox': String.raw `\text{#1}` },
21
+ }));
22
+ }
23
+ catch { }
24
+ }
25
+ return `<strong class="error texerror">Failed to parse: ${tex.replaceAll(/\s/gu, ' ')}</strong>`;
26
+ };
27
+ }
28
+ catch {
29
+ return undefined;
30
+ }
31
+ })();
@@ -397,6 +397,9 @@ const loadLanguage = (lang) => {
397
397
  const { default: registerWiki } = require('prism-wiki');
398
398
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
399
399
  registerWiki(exports.Prism, index_1.default);
400
+ (0, exports.loadLanguage)('json');
401
+ (0, exports.loadLanguage)('latex');
402
+ (0, exports.loadLanguage)('lilypond');
400
403
  return lang;
401
404
  }
402
405
  catch { }
package/dist/src/arg.js CHANGED
@@ -265,8 +265,7 @@ let ArgToken = (() => {
265
265
  * @param name new argument name / 新参数名
266
266
  */
267
267
  setName(name) {
268
- const { childNodes } = index_1.default.parseWithRef(name, this, 2);
269
- this.firstChild.safeReplaceChildren(childNodes);
268
+ this.firstChild.safeReplaceChildren(index_1.default.parseWithRef(name, this, 2).childNodes);
270
269
  }
271
270
  /**
272
271
  * Set the default value
package/dist/src/atom.js CHANGED
@@ -79,7 +79,7 @@ let AtomToken = (() => {
79
79
  /* NOT FOR BROWSER */
80
80
  /* c8 ignore next 3 */
81
81
  if (!atomTypes.includes(value)) {
82
- throw new RangeError(`"${value}" is not a valid type for AtomToken!`);
82
+ throw new RangeError(`${JSON.stringify(value)} is not a valid type for AtomToken!`);
83
83
  }
84
84
  /* NOT FOR BROWSER END */
85
85
  this.#type = value;
@@ -1,3 +1,4 @@
1
+ import { BoundingRect } from '../lib/rect';
1
2
  import { Token } from './index';
2
3
  import { AtomToken } from './atom';
3
4
  import { AttributeToken } from './attribute';
@@ -270,9 +270,24 @@ let AttributesToken = (() => {
270
270
  return parentNode?.type === 'html' && parentNode.closing && this.text().trim() !== '';
271
271
  }
272
272
  /** @private */
273
+ lintRef(rect, severity) {
274
+ LINT: {
275
+ const followAttr = this.getAttrToken('follow'), follow = followAttr?.getValue(), name = this.getAttr('name'), rule = 'invalid-ref';
276
+ if (follow && !/\D/u.test(follow)) {
277
+ const msg = 'int-name';
278
+ return rect ? (0, lint_1.generateForChild)(followAttr, rect, rule, msg, severity) : msg;
279
+ }
280
+ else if (follow && (this.hasAttr('details') || name && /\D/u.test(name))) {
281
+ const msg = 'ref-follow';
282
+ return rect ? (0, lint_1.generateForSelf)(this, rect, rule, msg, severity) : msg;
283
+ }
284
+ return '';
285
+ }
286
+ }
287
+ /** @private */
273
288
  lint(start = this.getAbsoluteIndex(), re) {
274
289
  LINT: {
275
- const errors = super.lint(start, re), { parentNode, childNodes, type, name: tag } = this, attrs = new Map(), duplicated = new Set(), rect = new rect_1.BoundingRect(this, start), rules = ['no-ignored', 'required-attr', 'no-duplicate'], { lintConfig } = index_1.default, { computeEditInfo, fix } = lintConfig, s = ['closingTag', 'invalidAttributes', 'nonWordAttributes']
290
+ const errors = super.lint(start, re), { parentNode, childNodes, type, name: tag } = this, attrs = new Map(), duplicated = new Set(), rect = new rect_1.BoundingRect(this, start), rules = ['no-ignored', 'required-attr', 'invalid-ref', 'no-duplicate'], { lintConfig } = index_1.default, { computeEditInfo, fix } = lintConfig, s = ['closingTag', 'invalidAttributes', 'nonWordAttributes']
276
291
  .map(k => lintConfig.getSeverity(rules[0], k));
277
292
  if (s[0] && this.#lint()) {
278
293
  const e = (0, lint_1.generateForSelf)(this, rect, rules[0], 'attributes-of-closing-tag', s[0]);
@@ -318,12 +333,21 @@ let AttributesToken = (() => {
318
333
  }
319
334
  }
320
335
  }
321
- const severity = lintConfig.getSeverity(rules[2], 'attribute');
336
+ if (tag === 'ref') {
337
+ const severity = lintConfig.getSeverity(rules[2]);
338
+ if (severity) {
339
+ const e = this.lintRef(rect, severity);
340
+ if (e) {
341
+ errors.push(e);
342
+ }
343
+ }
344
+ }
345
+ const severity = lintConfig.getSeverity(rules[3], 'attribute');
322
346
  if (severity && duplicated.size > 0) {
323
347
  for (const key of duplicated) {
324
348
  const pairs = attrs.get(key).map(attr => [attr, attr.getValue()]);
325
349
  Array.prototype.push.apply(errors, pairs.map(([attr, value], i) => {
326
- const e = (0, lint_1.generateForChild)(attr, rect, rules[2], index_1.default.msg('duplicate-attribute', key), severity);
350
+ const e = (0, lint_1.generateForChild)(attr, rect, rules[3], index_1.default.msg('duplicate-attribute', key), severity);
327
351
  if (computeEditInfo || fix) {
328
352
  const remove = (0, lint_1.fixByRemove)(e);
329
353
  if (!value || pairs.slice(0, i).some(([, v]) => v === value)) {
@@ -39,6 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
40
  exports.ConverterFlagsToken = void 0;
41
41
  const lint_1 = require("../util/lint");
42
+ const string_1 = require("../util/string");
42
43
  const rect_1 = require("../lib/rect");
43
44
  const gapped_1 = require("../mixin/gapped");
44
45
  const noEscape_1 = require("../mixin/noEscape");
@@ -128,27 +129,31 @@ let ConverterFlagsToken = (() => {
128
129
  getUnknownFlags() {
129
130
  return new Set(this.#flags.filter(flag => /\{{3}[^{}]+\}{3}/u.test(flag)));
130
131
  }
132
+ /** 从解析设置中获取语言变体 */
133
+ #getVariants() {
134
+ return new Set((0, string_1.toLowerCase)(this.getAttribute('config').variants));
135
+ }
131
136
  /**
132
137
  * Get language coversion flags that specify a language variant
133
138
  *
134
139
  * 获取指定语言变体的转换标记
135
140
  */
136
141
  getVariantFlags() {
137
- const variants = new Set(this.getAttribute('config').variants);
138
- return new Set(this.#flags.filter(flag => variants.has(flag)));
142
+ const variants = this.#getVariants();
143
+ return new Set((0, string_1.toLowerCase)(this.#flags).filter(flag => variants.has(flag)));
139
144
  }
140
145
  /** @private */
141
146
  isInvalidFlag(flag, variant, unknown) {
142
147
  /* PRINT ONLY */
143
148
  PRINT: if (typeof flag === 'object') {
144
- const variants = new Set(this.getAttribute('config').variants);
149
+ const variants = this.#getVariants();
145
150
  flag = flag.text().trim();
146
- variant = this.#flags.some(f => variants.has(f)) ? variants : new Set();
151
+ variant = this.#flags.some(f => variants.has(f.toLowerCase())) ? variants : new Set();
147
152
  unknown = this.getUnknownFlags();
148
153
  }
149
154
  /* PRINT ONLY END */
150
155
  return Boolean(flag)
151
- && !variant.has(flag)
156
+ && !variant.has(flag.toLowerCase())
152
157
  && !unknown.has(flag)
153
158
  && (variant.size > 0 || !definedFlags.has(flag));
154
159
  }
@@ -93,7 +93,7 @@ let ConverterRuleToken = (() => {
93
93
  /* PRINT ONLY */
94
94
  /** language variant / 语言变体 */
95
95
  get variant() {
96
- LSP: return this.childNodes[this.length - 2]?.text().trim().toLowerCase() ?? '';
96
+ LSP: return this.childNodes[this.length - 2]?.text().trim() ?? '';
97
97
  }
98
98
  /* PRINT ONLY END */
99
99
  /* NOT FOR BROWSER */
@@ -149,7 +149,7 @@ let ConverterRuleToken = (() => {
149
149
  });
150
150
  __runInitializers(this, _instanceExtraInitializers);
151
151
  const i = rule.indexOf(':'), j = rule.slice(0, i).indexOf('=>'), v = j === -1 ? rule.slice(0, i) : rule.slice(j + 2, i);
152
- if (hasColon && config.variants.includes(v.trim().toLowerCase())) {
152
+ if (hasColon && config.variants.includes(v.trim())) {
153
153
  super.insertAt(new atom_1.AtomToken(v, 'converter-rule-variant', config, accum));
154
154
  super.insertAt(getRuleFromTo(rule.slice(i + 1), 'to', config, accum));
155
155
  if (j !== -1) {
@@ -259,8 +259,7 @@ let ConverterRuleToken = (() => {
259
259
  * @param to target of language conversion / 转换目标
260
260
  */
261
261
  setTo(to) {
262
- const { childNodes } = index_1.default.parseWithRef(to, this);
263
- this.lastChild.safeReplaceChildren(childNodes);
262
+ this.lastChild.safeReplaceChildren(index_1.default.parseWithRef(to, this).childNodes);
264
263
  }
265
264
  /**
266
265
  * Set the language variant
@@ -288,11 +287,10 @@ let ConverterRuleToken = (() => {
288
287
  if (!variant) {
289
288
  throw new Error('Please specify the language variant first!');
290
289
  }
291
- const { childNodes } = index_1.default.parseWithRef(from, this);
292
- if (!unidirectional) {
290
+ else if (!unidirectional) {
293
291
  super.insertAt(debug_1.Shadow.run(() => getRuleFromTo(undefined, 'from', this.getAttribute('config'))), 0);
294
292
  }
295
- this.firstChild.safeReplaceChildren(childNodes);
293
+ this.firstChild.safeReplaceChildren(index_1.default.parseWithRef(from, this).childNodes);
296
294
  }
297
295
  /**
298
296
  * Make the language conversion unidirectional
@@ -104,8 +104,7 @@ let HeadingToken = (() => {
104
104
  if (text.length > 1 && text.startsWith('=') && text.endsWith('=')) {
105
105
  throw new Error('Please use HeadingToken.setLevel method to change the level of the heading!');
106
106
  }
107
- const { childNodes } = index_1.default.parseWithRef(text, this);
108
- this.firstChild.safeReplaceChildren(childNodes);
107
+ this.firstChild.safeReplaceChildren(index_1.default.parseWithRef(text, this).childNodes);
109
108
  }
110
109
  /**
111
110
  * id attribute
@@ -1,7 +1,8 @@
1
1
  import { Token } from './index';
2
- import type { LintError, Config, TokenTypes } from '../base';
2
+ import type { LintError, Config } from '../base';
3
3
  import type { Title } from '../lib/title';
4
4
  import type { AtomToken, FileToken, AstNodes, AstText } from '../internal';
5
+ export type GalleryImageTypes = 'gallery-image' | 'imagemap-image';
5
6
  /**
6
7
  * image parameter
7
8
  *
@@ -49,9 +50,9 @@ export declare abstract class ImageParameterToken extends Token {
49
50
  /**
50
51
  * @param str 图片参数
51
52
  * @param extension 文件扩展名
52
- * @param type 父节点类型
53
+ * @param type 图库节点类型
53
54
  */
54
- constructor(str: string, extension: string | undefined, type: TokenTypes | undefined, config: Config, accum?: Token[]);
55
+ constructor(str: string, extension: string | undefined, type: GalleryImageTypes | undefined, config: Config, accum?: Token[]);
55
56
  /**
56
57
  * Get the parameter value
57
58
  *
@@ -69,7 +69,7 @@ const getUrl = (link) => {
69
69
  }
70
70
  return new URL(link).href;
71
71
  };
72
- function validate(key, val, config, extOrType, halfParsed) {
72
+ function validate(key, val, config, extOrType, halfParsed, accum) {
73
73
  val = (0, string_1.removeComment)(val).trim();
74
74
  let value = val.replace(key === 'link' ? /\0\d+[tq]\x7F/gu : /\0\d+t\x7F/gu, '').trim();
75
75
  switch (key) {
@@ -77,6 +77,7 @@ function validate(key, val, config, extOrType, halfParsed) {
77
77
  return !value && Boolean(val) || /^(?:\d+x?|\d*x\d+)(?:\s*px)?$/u.test(value);
78
78
  case 'link': {
79
79
  const isGalleryImage = extOrType === 'gallery-image';
80
+ let nowiki = true;
80
81
  if (!value) {
81
82
  return val;
82
83
  }
@@ -85,8 +86,9 @@ function validate(key, val, config, extOrType, halfParsed) {
85
86
  }
86
87
  else if (value.startsWith('[[') && value.endsWith(']]')) {
87
88
  value = value.slice(2, -2);
89
+ nowiki = false;
88
90
  }
89
- const title = index_1.default.normalizeTitle(value, 0, false, config, { halfParsed, decode: true, selfLink: true, page: '' });
91
+ const title = index_1.default.normalizeTitle(value, 0, false, config, { halfParsed, decode: true, selfLink: true, page: '', nowiki }, accum);
90
92
  return title.valid ? title : isGalleryImage;
91
93
  }
92
94
  case 'lang':
@@ -147,12 +149,12 @@ let ImageParameterToken = (() => {
147
149
  }
148
150
  const value = super.text().trim();
149
151
  return debug_1.Shadow.run(() => {
150
- const config = this.getAttribute('config'), token = new index_2.Token(value, config);
152
+ const config = this.getAttribute('config'), accum = [], token = new index_2.Token(value, config, accum);
151
153
  token.parseOnce(0, this.getAttribute('include')).parseOnce();
152
154
  if (/^\0\d+m\x7F/u.test(token.firstChild.toString())) {
153
155
  return value;
154
156
  }
155
- const link = validate('link', value, config, this.parentNode?.type);
157
+ const link = validate('link', value, config, this.parentNode?.type, undefined, accum);
156
158
  return link === true ? undefined : link;
157
159
  }, index_1.default);
158
160
  }
@@ -226,7 +228,7 @@ let ImageParameterToken = (() => {
226
228
  /**
227
229
  * @param str 图片参数
228
230
  * @param extension 文件扩展名
229
- * @param type 父节点类型
231
+ * @param type 图库节点类型
230
232
  */
231
233
  constructor(str, extension, type, config, accum) {
232
234
  let mt;
@@ -235,7 +237,7 @@ let ImageParameterToken = (() => {
235
237
  mt = regex.exec(str);
236
238
  return mt
237
239
  && (mt.length !== 4
238
- || validate(key, mt[2], config, key === 'link' ? type : extension, true) !== false);
240
+ || validate(key, mt[2], config, key === 'link' ? type : extension, true, accum) !== false);
239
241
  });
240
242
  // @ts-expect-error mt already assigned
241
243
  if (param && mt) {
@@ -373,7 +375,13 @@ let ImageParameterToken = (() => {
373
375
  * 获取参数值
374
376
  */
375
377
  getValue() {
376
- LINT: return this.name === 'invalid' ? this.text() : this.#isVoid() || super.text();
378
+ LINT: {
379
+ const { name, childNodes } = this;
380
+ if (name === 'link') {
381
+ return (0, string_1.text)(childNodes.map(child => child.is('ext') && child.name === 'nowiki' ? child.innerText ?? '' : child));
382
+ }
383
+ return name === 'invalid' ? this.text() : this.#isVoid() || super.text();
384
+ }
377
385
  }
378
386
  /** @private */
379
387
  print() {
@@ -421,8 +429,7 @@ let ImageParameterToken = (() => {
421
429
  this.typeError('setValue', type);
422
430
  }
423
431
  else if (value !== true) {
424
- const { childNodes } = index_1.default.parseWithRef(value, this, name === 'caption' ? undefined : 5);
425
- this.safeReplaceChildren(childNodes);
432
+ this.safeReplaceChildren(index_1.default.parseWithRef(value, this, name === 'caption' ? undefined : 5).childNodes);
426
433
  }
427
434
  }
428
435
  /**
package/dist/src/index.js CHANGED
@@ -183,7 +183,7 @@ let Token = (() => {
183
183
  ];
184
184
  /* c8 ignore next 3 */
185
185
  if (!plainTypes.includes(value)) {
186
- throw new RangeError(`"${value}" is not a valid type for ${this.constructor.name}!`);
186
+ throw new RangeError(`${JSON.stringify(value)} is not a valid type for ${this.constructor.name}!`);
187
187
  }
188
188
  /* NOT FOR BROWSER END */
189
189
  this.#type = value;