wikiparser-node 1.31.0 → 1.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 (90) hide show
  1. package/README.md +1 -0
  2. package/bundle/bundle-es8.min.js +29 -30
  3. package/bundle/bundle-lsp.min.js +29 -29
  4. package/bundle/bundle.min.js +23 -23
  5. package/dist/addon/attribute.js +166 -0
  6. package/dist/addon/link.js +92 -0
  7. package/dist/addon/table.js +12 -3
  8. package/dist/addon/token.js +5 -303
  9. package/dist/addon/transclude.js +9 -6
  10. package/dist/base.d.mts +9 -1
  11. package/dist/base.d.ts +9 -1
  12. package/dist/bin/config.js +1 -1
  13. package/dist/index.d.ts +24 -5
  14. package/dist/index.js +69 -89
  15. package/dist/internal.d.ts +4 -0
  16. package/dist/lib/document.d.ts +9 -7
  17. package/dist/lib/document.js +91 -66
  18. package/dist/lib/element.d.ts +7 -7
  19. package/dist/lib/element.js +48 -50
  20. package/dist/lib/lintConfig.js +1 -1
  21. package/dist/lib/lsp.js +120 -56
  22. package/dist/lib/node.js +20 -14
  23. package/dist/lib/text.js +2 -2
  24. package/dist/lib/title.d.ts +11 -0
  25. package/dist/lib/title.js +37 -13
  26. package/dist/mixin/elementLike.js +2 -3
  27. package/dist/mixin/syntax.js +13 -7
  28. package/dist/parser/commentAndExt.js +3 -3
  29. package/dist/parser/selector.js +16 -41
  30. package/dist/render/expand.js +216 -0
  31. package/dist/render/extension.js +141 -0
  32. package/dist/render/html.js +91 -0
  33. package/dist/{addon → render}/magicWords.js +35 -1
  34. package/dist/render/syntaxhighlight.js +415 -0
  35. package/dist/src/arg.js +1 -1
  36. package/dist/src/attribute.d.ts +5 -0
  37. package/dist/src/attribute.js +58 -103
  38. package/dist/src/attributes.d.ts +5 -0
  39. package/dist/src/attributes.js +15 -50
  40. package/dist/src/converter.js +4 -2
  41. package/dist/src/converterFlags.js +8 -6
  42. package/dist/src/converterRule.js +19 -15
  43. package/dist/src/extLink.js +1 -1
  44. package/dist/src/heading.d.ts +1 -1
  45. package/dist/src/heading.js +5 -3
  46. package/dist/src/imageParameter.d.ts +0 -1
  47. package/dist/src/imageParameter.js +33 -24
  48. package/dist/src/index.d.ts +5 -5
  49. package/dist/src/index.js +33 -21
  50. package/dist/src/link/base.js +16 -34
  51. package/dist/src/link/category.d.ts +7 -0
  52. package/dist/src/link/category.js +101 -37
  53. package/dist/src/link/file.js +19 -6
  54. package/dist/src/link/galleryImage.js +1 -2
  55. package/dist/src/link/index.d.ts +1 -1
  56. package/dist/src/link/index.js +10 -31
  57. package/dist/src/multiLine/index.js +1 -1
  58. package/dist/src/nowiki/comment.js +1 -1
  59. package/dist/src/nowiki/doubleUnderscore.js +4 -2
  60. package/dist/src/nowiki/index.js +34 -31
  61. package/dist/src/nowiki/listBase.d.ts +2 -1
  62. package/dist/src/nowiki/listBase.js +22 -8
  63. package/dist/src/nowiki/quote.d.ts +1 -1
  64. package/dist/src/nowiki/quote.js +1 -1
  65. package/dist/src/onlyinclude.js +1 -1
  66. package/dist/src/parameter.js +1 -1
  67. package/dist/src/redirect.js +1 -1
  68. package/dist/src/table/base.js +4 -2
  69. package/dist/src/table/index.d.ts +0 -5
  70. package/dist/src/table/index.js +6 -15
  71. package/dist/src/table/td.js +9 -5
  72. package/dist/src/tag/index.js +1 -1
  73. package/dist/src/tagPair/ext.js +14 -38
  74. package/dist/src/tagPair/index.js +6 -4
  75. package/dist/src/tagPair/translate.js +2 -2
  76. package/dist/src/transclude.d.ts +0 -6
  77. package/dist/src/transclude.js +16 -33
  78. package/dist/util/constants.js +5 -1
  79. package/dist/util/debug.js +72 -5
  80. package/dist/util/diff.js +17 -15
  81. package/dist/util/html.js +4 -3
  82. package/dist/util/selector.js +37 -0
  83. package/dist/util/sharable.d.mts +4 -1
  84. package/dist/util/sharable.js +7 -7
  85. package/dist/util/sharable.mjs +7 -7
  86. package/dist/util/string.js +31 -12
  87. package/extensions/dist/base.js +1 -1
  88. package/i18n/zh-hans.json +29 -29
  89. package/i18n/zh-hant.json +30 -30
  90. package/package.json +16 -13
@@ -39,6 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
40
  exports.FileToken = void 0;
41
41
  const lint_1 = require("../../util/lint");
42
+ const constants_1 = require("../../util/constants");
42
43
  const rect_1 = require("../../lib/rect");
43
44
  const index_1 = __importDefault(require("../../index"));
44
45
  const base_1 = require("./base");
@@ -46,7 +47,6 @@ const imageParameter_1 = require("../imageParameter");
46
47
  /* NOT FOR BROWSER */
47
48
  const string_1 = require("../../util/string");
48
49
  const debug_1 = require("../../util/debug");
49
- const constants_1 = require("../../util/constants");
50
50
  const title_1 = require("../../lib/title");
51
51
  const cached_1 = require("../../mixin/cached");
52
52
  const frame = new Map([
@@ -85,6 +85,13 @@ const explode = (str) => {
85
85
  * @param types token types to be filtered
86
86
  */
87
87
  const filterArgs = (args, types) => args.filter(({ childNodes }) => !childNodes.some(node => node.text().trim() && types.has(node.type)));
88
+ /* NOT FOR BROWSER */
89
+ /**
90
+ * check if a string is an integer
91
+ * @param n string to be checked
92
+ */
93
+ const isInteger = (n) => Boolean(n && !/\D/u.test(n));
94
+ /* NOT FOR BROWSER END */
88
95
  /**
89
96
  * image
90
97
  *
@@ -187,7 +194,7 @@ let FileToken = (() => {
187
194
  interwiki, } = this.getAttribute('title'), { firstChild } = this;
188
195
  let rule = 'nested-link', s = lintConfig.getSeverity(rule, 'file');
189
196
  if (s
190
- && imageParameter_1.extensions.has(extension)
197
+ && constants_1.extensions.has(extension)
191
198
  && this.isInside('ext-link-text')
192
199
  && this.getValue('link')?.trim() !== '') {
193
200
  const e = (0, lint_1.generateForSelf)(this, rect, rule, 'link-in-extlink', s);
@@ -263,7 +270,7 @@ let FileToken = (() => {
263
270
  ];
264
271
  }
265
272
  if (relevantArgs.length > 1) {
266
- let severity = !isCaption || !extension || imageParameter_1.extensions.has(extension);
273
+ let severity = !isCaption || !extension || constants_1.extensions.has(extension);
267
274
  if (isCaption && severity) {
268
275
  const plainArgs = filterArgs(relevantArgs, transclusion);
269
276
  severity = plainArgs.length > 1 && ((arg) => plainArgs.includes(arg));
@@ -480,15 +487,21 @@ let FileToken = (() => {
480
487
  }
481
488
  /** @private */
482
489
  toHtmlInternal(opt) {
483
- /** @ignore */
484
- const isInteger = (n) => Boolean(n && !/\D/u.test(n));
485
490
  const { link, width, height, type } = this, file = this.getAttribute('title'), fr = this.getFrame(), manual = fr instanceof title_1.Title, visibleCaption = manual || fr === 'thumbnail' || fr === 'framed' || type === 'gallery-image', caption = this.getArg('caption')?.toHtmlInternal({
486
491
  ...opt,
487
492
  nowrap: true,
488
493
  }) ?? '', titleFromCaption = visibleCaption && type !== 'gallery-image' ? '' : (0, string_1.sanitizeAlt)(caption), hasLink = manual || link !== file, title = titleFromCaption || (hasLink && typeof link !== 'string' ? link.getTitleAttr() : ''), titleAttr = title && ` title="${title}"`, alt = (0, string_1.sanitizeAlt)(this.getArg('alt')?.toHtmlInternal({
489
494
  ...opt,
490
495
  nowrap: true,
491
- })) ?? titleFromCaption, horiz = this.getHorizAlign() ?? '', vert = this.getVertAlign() ?? '', className = `${horiz ? `mw-halign-${horiz}` : vert && `mw-valign-${vert}`}${this.getValue('border') ? ' mw-image-border' : ''} ${(0, string_1.sanitizeAlt)(this.getValue('class')) ?? ''}`.trim(), classAttr = className && ` class="${className}"`, img = `<img${alt && ` alt="${alt}"`} src="${(manual ? fr : file).getUrl()}" decoding="async" class="mw-file-element"${isInteger(width) ? ` width="${width}"` : ''}${isInteger(height) ? ` height="${height}"` : ''}>`;
496
+ })) ?? titleFromCaption, horiz = this.getHorizAlign() ?? '', vert = this.getVertAlign() ?? '', className = `${horiz ? `mw-halign-${horiz}` : vert && `mw-valign-${vert}`}${this.getValue('border') ? ' mw-image-border' : ''} ${(0, string_1.sanitizeAlt)(this.getValue('class')) ?? ''}`.trim(), classAttr = className && ` class="${className}"`, hasWidth = isInteger(width), hasHeight = isInteger(height);
497
+ let src;
498
+ try {
499
+ src = manual ? fr.getFileUrl() : file.getFileUrl(hasWidth && Number(width), hasHeight && Number(height));
500
+ }
501
+ catch {
502
+ return '';
503
+ }
504
+ const img = `<img${alt && ` alt="${alt}"`} src="${src}" decoding="async" class="mw-file-element"${hasWidth ? ` width="${width}"` : ''}${hasHeight ? ` height="${height}"` : ''}>`;
492
505
  let href = '';
493
506
  if (link) {
494
507
  try {
@@ -47,7 +47,6 @@ const file_1 = require("./file");
47
47
  /* NOT FOR BROWSER */
48
48
  const debug_1 = require("../../util/debug");
49
49
  const singleLine_1 = require("../../mixin/singleLine");
50
- const imageParameter_1 = require("../imageParameter");
51
50
  /**
52
51
  * gallery image
53
52
  *
@@ -148,7 +147,7 @@ let GalleryImageToken = (() => {
148
147
  insertAt(child, i) {
149
148
  if (this.type === 'gallery-image'
150
149
  && child.is('image-parameter')
151
- && !imageParameter_1.galleryParams.has(child.name)) {
150
+ && !constants_1.galleryParams.has(child.name)) {
152
151
  child.setAttribute('name', 'invalid');
153
152
  }
154
153
  return super.insertAt(child, i);
@@ -36,7 +36,7 @@ export declare abstract class LinkToken extends LinkBaseToken {
36
36
  * @param fragment URI fragment / 片段标识符
37
37
  * @throws `RangeError` 空的片段标识符
38
38
  */
39
- asSelfLink(fragment?: string | undefined): void;
39
+ asSelfLink(fragment?: string): void;
40
40
  /**
41
41
  * Automatically generate the link text after the pipe
42
42
  *
@@ -10,7 +10,6 @@ const index_1 = __importDefault(require("../../index"));
10
10
  const base_1 = require("./base");
11
11
  /* NOT FOR BROWSER */
12
12
  const constants_1 = require("../../util/constants");
13
- const string_1 = require("../../util/string");
14
13
  /* NOT FOR BROWSER END */
15
14
  /**
16
15
  * internal link
@@ -59,6 +58,7 @@ class LinkToken extends base_1.LinkBaseToken {
59
58
  }
60
59
  }
61
60
  /* NOT FOR BROWSER */
61
+ /* istanbul ignore next */
62
62
  /**
63
63
  * Set the interlanguage link
64
64
  *
@@ -68,13 +68,10 @@ class LinkToken extends base_1.LinkBaseToken {
68
68
  * @throws `SyntaxError` 仅有片段标识符
69
69
  */
70
70
  setLangLink(lang, link) {
71
- link = link.trim();
72
- /* istanbul ignore if */
73
- if (link.startsWith('#')) {
74
- throw new SyntaxError('An interlanguage link cannot be fragment only!');
75
- }
76
- super.setTarget(lang + (link.startsWith(':') ? '' : ':') + link);
71
+ require('../../addon/link');
72
+ this.setLangLink(lang, link);
77
73
  }
74
+ /* istanbul ignore next */
78
75
  /**
79
76
  * Convert to a self link
80
77
  *
@@ -82,13 +79,11 @@ class LinkToken extends base_1.LinkBaseToken {
82
79
  * @param fragment URI fragment / 片段标识符
83
80
  * @throws `RangeError` 空的片段标识符
84
81
  */
85
- asSelfLink(fragment = this.fragment) {
86
- /* istanbul ignore if */
87
- if (!fragment?.trim()) {
88
- throw new RangeError('LinkToken.asSelfLink method must specify a non-empty fragment!');
89
- }
90
- this.setTarget(`#${(0, string_1.encode)(fragment)}`);
82
+ asSelfLink(fragment) {
83
+ require('../../addon/link');
84
+ this.asSelfLink(fragment);
91
85
  }
86
+ /* istanbul ignore next */
92
87
  /**
93
88
  * Automatically generate the link text after the pipe
94
89
  *
@@ -96,24 +91,8 @@ class LinkToken extends base_1.LinkBaseToken {
96
91
  * @throws `Error` 带有"#"或"%"时不可用
97
92
  */
98
93
  pipeTrick() {
99
- const linkText = this.firstChild.text();
100
- /* istanbul ignore if */
101
- if (linkText.includes('#') || linkText.includes('%')) {
102
- throw new Error('Pipe trick cannot be used with "#" or "%"!');
103
- }
104
- const m1 = /^:?(?:[ \w\x80-\xFF-]+:)?([^(]+?) ?\(.+\)$/u.exec(linkText);
105
- if (m1) {
106
- this.setLinkText(m1[1]);
107
- return;
108
- }
109
- const m2 = /^:?(?:[ \w\x80-\xFF-]+:)?([^(]+?) ?(.+)$/u.exec(linkText);
110
- if (m2) {
111
- this.setLinkText(m2[1]);
112
- return;
113
- }
114
- const m3 = /^:?(?:[ \w\x80-\xFF-]+:)?(.*?)(?: ?(?<!\()\(.+\))?(?:(?:, |,|، ).|$)/u
115
- .exec(linkText);
116
- this.setLinkText(m3[1]);
94
+ require('../../addon/link');
95
+ this.pipeTrick();
117
96
  }
118
97
  }
119
98
  exports.LinkToken = LinkToken;
@@ -29,7 +29,7 @@ class MultiLineToken extends index_1.Token {
29
29
  }
30
30
  /** @private */
31
31
  print() {
32
- return super.print({ sep: '\n' });
32
+ PRINT: return super.print({ sep: '\n' });
33
33
  }
34
34
  }
35
35
  exports.MultiLineToken = MultiLineToken;
@@ -116,7 +116,7 @@ let CommentToken = (() => {
116
116
  }
117
117
  /** @private */
118
118
  print() {
119
- return super.print({ pre: '&lt;!--', post: this.closed ? '--&gt;' : '' });
119
+ PRINT: return super.print({ pre: '&lt;!--', post: this.closed ? '--&gt;' : '' });
120
120
  }
121
121
  /* NOT FOR BROWSER */
122
122
  cloneNode() {
@@ -91,8 +91,10 @@ let DoubleUnderscoreToken = (() => {
91
91
  }
92
92
  /** @private */
93
93
  print() {
94
- const underscore = this.#fullWidth ? '__' : '__';
95
- return super.print({ pre: underscore, post: underscore });
94
+ PRINT: {
95
+ const underscore = this.#fullWidth ? '__' : '__';
96
+ return super.print({ pre: underscore, post: underscore });
97
+ }
96
98
  }
97
99
  /* NOT FOR BROWSER */
98
100
  cloneNode() {
@@ -60,38 +60,41 @@ class NowikiToken extends base_1.NowikiBaseToken {
60
60
  NPM: {
61
61
  rule = 'invalid-math';
62
62
  s = lintConfig.getSeverity(rule);
63
- if (s && document_1.texvcjs && constants_1.mathTags.has(name)) {
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 = document_1.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 });
63
+ if (s && constants_1.mathTags.has(name)) {
64
+ const texvcjs = (0, document_1.loadTexvcjs)();
65
+ if (texvcjs) {
66
+ const isChem = name !== 'math', display = previousSibling?.getAttr('display') ?? 'block';
67
+ let tex = innerText, n = 0;
68
+ if (isChem) {
69
+ tex = String.raw `\ce{${tex}}`;
70
+ n = 4;
71
+ }
72
+ switch (display) {
73
+ case 'block':
74
+ tex = String.raw `{\displaystyle ${tex}}`;
75
+ n += 15;
76
+ break;
77
+ case 'inline':
78
+ tex = String.raw `{\textstyle ${tex}}`;
79
+ n += 12;
80
+ break;
81
+ case 'linebreak':
82
+ tex = String.raw `\[ ${tex} \]`;
83
+ n += 3;
84
+ // no default
85
+ }
86
+ const result = texvcjs.check(tex, {
87
+ usemhchem: isChem || Boolean(previousSibling?.hasAttr('chem')),
88
+ });
89
+ if (result.status !== '+') {
90
+ const e = (0, lint_1.generateForSelf)(this, { start }, rule, 'chem-required', s);
91
+ if (result.status !== 'C') {
92
+ const { message, location } = result.error, [endIndex, endLine, endCol] = updateLocation(e, location.end, n);
93
+ [e.startIndex, e.startLine, e.startCol] = updateLocation(e, location.start, n);
94
+ Object.assign(e, { endIndex, endLine, endCol, message });
95
+ }
96
+ errors.push(e);
93
97
  }
94
- errors.push(e);
95
98
  }
96
99
  }
97
100
  }
@@ -1,7 +1,8 @@
1
1
  import { NowikiBaseToken } from './base';
2
2
  import type { AST } from '../../base';
3
+ import { AstText } from '../../lib/text';
3
4
  import { Token } from '../index';
4
- import type { DdToken, ListToken, AstText } from '../../internal';
5
+ import type { DdToken, ListToken } from '../../internal';
5
6
  export interface ListRangeToken extends Token {
6
7
  readonly type: 'list-range';
7
8
  readonly previousSibling: ListToken | DdToken;
@@ -5,6 +5,7 @@ const base_1 = require("./base");
5
5
  /* NOT FOR BROWSER */
6
6
  const constants_1 = require("../../util/constants");
7
7
  const debug_1 = require("../../util/debug");
8
+ const text_1 = require("../../lib/text");
8
9
  const index_1 = require("../index");
9
10
  /* NOT FOR BROWSER END */
10
11
  /** `;:*#` */
@@ -90,10 +91,12 @@ class ListBaseToken extends base_1.NowikiBaseToken {
90
91
  }
91
92
  ({ nextSibling } = nextSibling);
92
93
  }
93
- const range = this.createRange();
94
+ let start, end, contents;
94
95
  if (nextSibling && nextSibling.type !== 'text') {
95
- range.setStartAfter(this);
96
- range.setEndBefore(nextSibling);
96
+ const { childNodes } = parentNode;
97
+ start = childNodes.indexOf(this) + 1;
98
+ end = childNodes.indexOf(nextSibling);
99
+ contents = childNodes.slice(start, end);
97
100
  }
98
101
  else {
99
102
  if (type === 'list') {
@@ -112,12 +115,23 @@ class ListBaseToken extends base_1.NowikiBaseToken {
112
115
  return parentNode;
113
116
  }
114
117
  }
115
- range.setStartAfter(this);
118
+ const { childNodes } = parentNode;
119
+ start = childNodes.indexOf(this) + 1;
116
120
  if (nextSibling) {
117
- range.setEnd(nextSibling, nextSibling.data.indexOf('\n'));
121
+ const { data } = nextSibling, offset = data.indexOf('\n'), text = new text_1.AstText(data.slice(0, offset));
122
+ end = childNodes.indexOf(nextSibling);
123
+ contents = childNodes.slice(start, end);
124
+ const last = contents.at(-1);
125
+ if (last) {
126
+ last.setAttribute('nextSibling', text);
127
+ text.setAttribute('previousSibling', last);
128
+ }
129
+ contents.push(text);
130
+ nextSibling.setAttribute('data', data.slice(offset));
118
131
  }
119
132
  else {
120
- range.setEnd(parentNode, parentNode.length);
133
+ end = childNodes.length;
134
+ contents = childNodes.slice(start);
121
135
  }
122
136
  }
123
137
  const token = debug_1.Shadow.run(() => {
@@ -125,8 +139,8 @@ class ListBaseToken extends base_1.NowikiBaseToken {
125
139
  t.type = 'list-range';
126
140
  return t;
127
141
  });
128
- token.concat(range.extractContents()); // eslint-disable-line unicorn/prefer-spread
129
- (0, debug_1.setChildNodes)(parentNode, parentNode.childNodes.indexOf(this) + 1, 0, [token]);
142
+ token.concat(contents); // eslint-disable-line unicorn/prefer-spread
143
+ (0, debug_1.setChildNodes)(parentNode, start, end - start, [token]);
130
144
  return token;
131
145
  }
132
146
  /** @private */
@@ -32,7 +32,7 @@ export declare abstract class QuoteToken extends NowikiBaseToken {
32
32
  * Find the matching apostrophes
33
33
  *
34
34
  * 搜索匹配的直引号
35
- * @since v1.29.3
35
+ * @since v1.30.0
36
36
  * @param type type of apostrophes to match / 匹配的直引号类型
37
37
  * @throws `RangeError` ambiguous or wrong apostrophe type
38
38
  */
@@ -183,7 +183,7 @@ let QuoteToken = (() => {
183
183
  * Find the matching apostrophes
184
184
  *
185
185
  * 搜索匹配的直引号
186
- * @since v1.29.3
186
+ * @since v1.30.0
187
187
  * @param type type of apostrophes to match / 匹配的直引号类型
188
188
  * @throws `RangeError` ambiguous or wrong apostrophe type
189
189
  */
@@ -99,7 +99,7 @@ let OnlyincludeToken = (() => {
99
99
  }
100
100
  /** @private */
101
101
  print() {
102
- return super.print({
102
+ PRINT: return super.print({
103
103
  pre: '<span class="wpb-ext">&lt;onlyinclude&gt;</span>',
104
104
  post: '<span class="wpb-ext">&lt;/onlyinclude&gt;</span>',
105
105
  });
@@ -203,7 +203,7 @@ let ParameterToken = (() => {
203
203
  }
204
204
  /** @private */
205
205
  print() {
206
- return super.print({ sep: this.anon ? '' : '=' });
206
+ PRINT: return super.print({ sep: this.anon ? '' : '=' });
207
207
  }
208
208
  /** @private */
209
209
  json(_, start = this.getAbsoluteIndex()) {
@@ -108,7 +108,7 @@ let RedirectToken = (() => {
108
108
  }
109
109
  /** @private */
110
110
  print() {
111
- return super.print({ pre: this.#pre, post: this.#post });
111
+ PRINT: return super.print({ pre: this.#pre, post: this.#post });
112
112
  }
113
113
  /* NOT FOR BROWSER */
114
114
  cloneNode() {
@@ -38,13 +38,13 @@ 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");
44
45
  const syntax_1 = require("../syntax");
45
46
  const attributes_1 = require("../attributes");
46
47
  /* NOT FOR BROWSER */
47
- const debug_1 = require("../../util/debug");
48
48
  const constants_1 = require("../../util/constants");
49
49
  /**
50
50
  * 转义表格语法
@@ -54,7 +54,9 @@ const escapeTable = (syntax) => {
54
54
  const wikitext = syntax.childNodes.map(child => child.type === 'text'
55
55
  ? child.data.replace(/\|{1,2}/gu, ({ length }) => `{{${'!'.repeat(length)}}}`)
56
56
  : child.toString()).join(''), { childNodes } = index_1.default.parseWithRef(wikitext, syntax, 2);
57
- syntax.safeReplaceChildren(childNodes);
57
+ debug_1.Shadow.run(() => {
58
+ syntax.safeReplaceChildren(childNodes);
59
+ });
58
60
  };
59
61
  /**
60
62
  * table row that contains the newline at the beginning but not at the end
@@ -11,11 +11,6 @@ export interface TableRenderedCoords {
11
11
  readonly y: number;
12
12
  }
13
13
  export type TableTokens = TableToken | TrToken | TdToken;
14
- /**
15
- * 是否是行尾
16
- * @param {Token} cell 表格单元格
17
- */
18
- export declare const isRowEnd: ({ type }: Token) => boolean;
19
14
  /** @extends {Array<TableCoords[]>} */
20
15
  export declare class Layout extends Array<TableCoords[]> {
21
16
  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");
@@ -52,16 +52,10 @@ const string_1 = require("../../util/string");
52
52
  const closingPattern = /^\n[^\S\n]*(?:\|\}|\{\{\s*!\s*\}\}\}|\{\{\s*!\)\s*\}\})$/u;
53
53
  /**
54
54
  * 生成一个指定长度的空数组
55
- * @param n 数组长度
55
+ * @param length 数组长度
56
56
  * @param callback 回调函数
57
57
  */
58
- const emptyArray = (n, callback) => new Array(n).fill(undefined).map((_, i) => callback(i));
59
- /**
60
- * 是否是行尾
61
- * @param {Token} cell 表格单元格
62
- */
63
- const isRowEnd = ({ type }) => type === 'tr' || type === 'table-syntax';
64
- exports.isRowEnd = isRowEnd;
58
+ const emptyArray = (length, callback) => Array.from({ length }, (_, i) => callback(i));
65
59
  /** @extends {Array<TableCoords[]>} */
66
60
  class Layout extends Array {
67
61
  /* NOT FOR BROWSER */
@@ -251,7 +245,7 @@ let TableToken = (() => {
251
245
  }
252
246
  }
253
247
  }
254
- else if ((0, exports.isRowEnd)(cell)) {
248
+ else if ((0, debug_1.isRowEnd)(cell)) {
255
249
  break;
256
250
  }
257
251
  }
@@ -355,11 +349,8 @@ let TableToken = (() => {
355
349
  * @param coords table coordinates / 表格坐标
356
350
  */
357
351
  getNthCell(coords) {
358
- let rawCoords = coords;
359
- if (coords.row === undefined) {
360
- rawCoords = this.toRawCoords(coords);
361
- }
362
- return rawCoords && this.getNthRow(rawCoords.row, false, false)?.getNthCol(rawCoords.column);
352
+ require('../../addon/table');
353
+ return this.getNthCell(coords);
363
354
  }
364
355
  /**
365
356
  * Print the table layout
@@ -108,9 +108,11 @@ let TdToken = (() => {
108
108
  /* NOT FOR BROWSER */
109
109
  const str = previousSibling.lastChild.toString();
110
110
  result.escape ||= esc;
111
- result.correction = str.includes('\n') && debug_1.Shadow.run(() => new index_2.Token(str, this.getAttribute('config'))
112
- .parseOnce(0, this.getAttribute('include')).parseOnce().parseOnce()
113
- .firstChild.toString().includes('\n'));
111
+ result.correction = str.includes('\n') && debug_1.Shadow.run(() => {
112
+ const token = new index_2.Token(str, this.getAttribute('config'))
113
+ .parseOnce(0, this.getAttribute('include')).parseOnce().parseOnce();
114
+ return token.firstChild.toString().includes('\n');
115
+ }, index_1.default);
114
116
  if (subtype === 'th' && result.subtype !== 'th') {
115
117
  result.subtype = 'th';
116
118
  result.correction = true;
@@ -272,8 +274,10 @@ let TdToken = (() => {
272
274
  }
273
275
  /** @private */
274
276
  print() {
275
- const { childNodes: [syntax, attr, inner] } = this;
276
- return `<span class="wpb-td">${syntax.print()}${attr.print()}${this.#innerSyntax}${inner.print()}</span>`;
277
+ PRINT: {
278
+ const { childNodes: [syntax, attr, inner] } = this;
279
+ return `<span class="wpb-td">${syntax.print()}${attr.print()}${this.#innerSyntax}${inner.print()}</span>`;
280
+ }
277
281
  }
278
282
  /** @private */
279
283
  json(_, start = this.getAbsoluteIndex()) {
@@ -178,7 +178,7 @@ let TagToken = (() => {
178
178
  }
179
179
  /** @private */
180
180
  print() {
181
- return super.print({
181
+ PRINT: return super.print({
182
182
  pre: `&lt;${this.#closing ? '/' : ''}${this.#tag}`,
183
183
  post: `${this.selfClosing ? '/' : ''}&gt;`,
184
184
  });
@@ -234,46 +234,22 @@ let ExtToken = (() => {
234
234
  /** @private */
235
235
  toHtmlInternal(opt) {
236
236
  const { name, firstChild, lastChild } = this;
237
- if (index_1.default.tagHooks.has(name)) {
238
- return index_1.default.tagHooks.get(name)(this);
237
+ if (constants_1.tagHooks.has(name)) {
238
+ return constants_1.tagHooks.get(name)(this);
239
239
  }
240
- switch (name) {
241
- case 'nowiki': {
242
- const html = lastChild.toHtmlInternal();
243
- return this.closest('ext-inner')?.name === 'poem' ? html : (0, string_1.newline)(html);
244
- }
245
- case 'pre': {
246
- const html = lastChild.toHtmlInternal({
247
- ...opt,
248
- nowrap: false,
249
- });
250
- return `<pre${firstChild.toHtmlInternal()}>${this.closest('ext-inner')?.name === 'poem' ? html : (0, string_1.newline)(html)}</pre>`;
251
- }
252
- case 'poem': {
253
- const padding = firstChild.hasAttr('compact') ? '' : '\n';
254
- firstChild.classList.add('poem');
255
- return `<div${firstChild.toHtmlInternal()}>${padding}${lastChild.toHtmlInternal({ ...opt, nowrap: false })
256
- .replace(/(?<!^|<hr>)\n(?!$)/gu, '<br>\n')
257
- .replace(/^ +/gmu, p => '&nbsp;'.repeat(p.length))
258
- .trim()}${padding}</div>`;
259
- }
260
- case 'gallery': {
261
- const caption = firstChild.getAttrToken('caption'), perrow = parseInt(String(firstChild.getAttr('perrow'))), mode = firstChild.getAttr('mode'), nolines = typeof mode === 'string' && mode.toLowerCase() === 'nolines', padding = nolines ? 9 : 43;
262
- firstChild.classList.add('gallery');
263
- if (nolines) {
264
- firstChild.classList.add('mw-gallery-nolines');
265
- }
266
- if (perrow > 0) {
267
- const style = firstChild.getAttr('style');
268
- firstChild.setAttr('style', `max-width: ${(lastChild.widths + padding) * perrow}px;${typeof style === 'string' ? style : ''}`);
269
- }
270
- return `<ul${firstChild.toHtmlInternal()}>\n${caption
271
- ? `\t<li class="gallerycaption">${caption.lastChild.toHtmlInternal({ nowrap: true })}</li>\n`
272
- : ''}${lastChild.toHtmlInternal()}\n</ul>`;
273
- }
274
- default:
275
- return '';
240
+ else if (name === 'nowiki') {
241
+ const html = lastChild.toHtmlInternal();
242
+ return this.closest('ext-inner')?.name === 'poem' ? html : (0, string_1.newline)(html);
243
+ }
244
+ else if (name === 'pre') {
245
+ const html = lastChild.toHtmlInternal({
246
+ ...opt,
247
+ nowrap: false,
248
+ });
249
+ return `<pre${firstChild.toHtmlInternal()}>${this.closest('ext-inner')?.name === 'poem' ? html : (0, string_1.newline)(html)}</pre>`;
276
250
  }
251
+ const { renderExt } = require('../../render/extension');
252
+ return renderExt(this, opt);
277
253
  }
278
254
  };
279
255
  return ExtToken = _classThis;
@@ -123,10 +123,12 @@ let TagPairToken = (() => {
123
123
  }
124
124
  /** @private */
125
125
  print() {
126
- const [opening, closing] = this.#tags;
127
- return super.print(this.selfClosing
128
- ? { pre: `&lt;${opening}`, post: '/&gt;' }
129
- : { pre: `&lt;${opening}`, sep: '&gt;', post: this.closed ? `&lt;/${closing}&gt;` : '' });
126
+ PRINT: {
127
+ const [opening, closing] = this.#tags;
128
+ return super.print(this.selfClosing
129
+ ? { pre: `&lt;${opening}`, post: '/&gt;' }
130
+ : { pre: `&lt;${opening}`, sep: '&gt;', post: this.closed ? `&lt;/${closing}&gt;` : '' });
131
+ }
130
132
  }
131
133
  };
132
134
  return TagPairToken = _classThis;
@@ -102,11 +102,11 @@ let TranslateToken = (() => {
102
102
  /* PRINT ONLY */
103
103
  /** 是否有nowrap属性 */
104
104
  #isNowrap() {
105
- return this.firstChild.toString() === ' nowrap';
105
+ PRINT: return this.firstChild.toString() === ' nowrap';
106
106
  }
107
107
  /** @private */
108
108
  print() {
109
- return `<span class="wpb-ext">&lt;translate${this.#isNowrap()
109
+ PRINT: return `<span class="wpb-ext">&lt;translate${this.#isNowrap()
110
110
  ? '<span class="wpb-ext-attrs"> <span class="wpb-ext-attr">'
111
111
  + '<span class="wpb-attr-key">nowrap</span>'
112
112
  + '</span></span>'