wikiparser-node 1.18.4 → 1.20.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 (108) hide show
  1. package/README.md +3 -0
  2. package/bundle/bundle-es7.min.js +25 -32
  3. package/bundle/bundle-lsp.min.js +26 -99
  4. package/bundle/bundle.min.js +25 -32
  5. package/config/default.json +49 -3
  6. package/config/minimum.json +5 -1
  7. package/data/ext/math.json +660 -0
  8. package/dist/addon/table.js +24 -5
  9. package/dist/addon/transclude.js +5 -5
  10. package/dist/base.d.mts +4 -3
  11. package/dist/base.d.ts +4 -3
  12. package/dist/bin/config.js +26 -8
  13. package/dist/index.d.ts +2 -2
  14. package/dist/index.js +10 -1
  15. package/dist/internal.d.ts +2 -0
  16. package/dist/lib/document.d.ts +5 -0
  17. package/dist/lib/document.js +31 -2
  18. package/dist/lib/element.js +15 -21
  19. package/dist/lib/lsp.js +104 -42
  20. package/dist/lib/node.js +21 -24
  21. package/dist/lib/text.js +3 -4
  22. package/dist/lib/title.js +2 -1
  23. package/dist/mixin/attributesParent.js +1 -1
  24. package/dist/mixin/fixed.d.ts +1 -2
  25. package/dist/mixin/fixed.js +2 -3
  26. package/dist/mixin/gapped.d.ts +4 -0
  27. package/dist/mixin/gapped.js +24 -0
  28. package/dist/mixin/hidden.js +1 -1
  29. package/dist/mixin/multiLine.d.ts +4 -0
  30. package/dist/mixin/multiLine.js +33 -0
  31. package/dist/mixin/noEscape.js +1 -1
  32. package/dist/mixin/padded.d.ts +5 -0
  33. package/dist/mixin/padded.js +24 -0
  34. package/dist/mixin/singleLine.js +1 -1
  35. package/dist/mixin/sol.js +1 -1
  36. package/dist/mixin/syntax.js +3 -3
  37. package/dist/parser/braces.js +9 -13
  38. package/dist/parser/commentAndExt.js +18 -2
  39. package/dist/parser/magicLinks.js +2 -2
  40. package/dist/parser/selector.js +5 -2
  41. package/dist/src/arg.js +10 -13
  42. package/dist/src/atom.js +2 -7
  43. package/dist/src/attribute.js +6 -6
  44. package/dist/src/attributes.js +8 -12
  45. package/dist/src/commented.d.ts +26 -0
  46. package/dist/src/commented.js +52 -0
  47. package/dist/src/converter.js +3 -6
  48. package/dist/src/converterFlags.js +266 -223
  49. package/dist/src/converterRule.d.ts +2 -2
  50. package/dist/src/converterRule.js +2 -2
  51. package/dist/src/extLink.d.ts +2 -3
  52. package/dist/src/extLink.js +222 -175
  53. package/dist/src/gallery.d.ts +4 -5
  54. package/dist/src/gallery.js +177 -144
  55. package/dist/src/heading.js +11 -11
  56. package/dist/src/hidden.js +2 -7
  57. package/dist/src/imageParameter.d.ts +2 -2
  58. package/dist/src/imageParameter.js +13 -10
  59. package/dist/src/imagemap.d.ts +2 -2
  60. package/dist/src/imagemap.js +155 -123
  61. package/dist/src/imagemapLink.d.ts +2 -2
  62. package/dist/src/index.js +51 -27
  63. package/dist/src/link/base.d.ts +2 -3
  64. package/dist/src/link/base.js +13 -15
  65. package/dist/src/link/file.d.ts +2 -3
  66. package/dist/src/link/file.js +3 -3
  67. package/dist/src/link/galleryImage.d.ts +2 -3
  68. package/dist/src/link/galleryImage.js +7 -13
  69. package/dist/src/magicLink.js +7 -9
  70. package/dist/src/nested.d.ts +2 -2
  71. package/dist/src/nested.js +4 -7
  72. package/dist/src/nowiki/comment.js +2 -5
  73. package/dist/src/nowiki/doubleUnderscore.js +2 -5
  74. package/dist/src/nowiki/index.d.ts +2 -2
  75. package/dist/src/nowiki/index.js +2 -1
  76. package/dist/src/onlyinclude.js +6 -13
  77. package/dist/src/paramTag/index.d.ts +2 -2
  78. package/dist/src/paramTag/index.js +102 -66
  79. package/dist/src/paramTag/inputbox.js +9 -4
  80. package/dist/src/parameter.d.ts +4 -5
  81. package/dist/src/parameter.js +13 -13
  82. package/dist/src/pre.d.ts +4 -5
  83. package/dist/src/pre.js +8 -17
  84. package/dist/src/syntax.d.ts +1 -1
  85. package/dist/src/syntax.js +2 -7
  86. package/dist/src/table/base.d.ts +2 -2
  87. package/dist/src/table/base.js +8 -8
  88. package/dist/src/table/index.js +1 -1
  89. package/dist/src/table/td.d.ts +3 -3
  90. package/dist/src/table/td.js +9 -9
  91. package/dist/src/table/tr.d.ts +2 -2
  92. package/dist/src/tagPair/ext.js +39 -32
  93. package/dist/src/tagPair/index.d.ts +1 -1
  94. package/dist/src/tagPair/index.js +2 -5
  95. package/dist/src/tagPair/translate.d.ts +38 -0
  96. package/dist/src/tagPair/translate.js +129 -0
  97. package/dist/src/transclude.js +6 -7
  98. package/dist/util/html.js +16 -4
  99. package/dist/util/lint.js +17 -30
  100. package/dist/util/sharable.js +29 -1
  101. package/dist/util/sharable.mjs +31 -3
  102. package/dist/util/string.js +14 -1
  103. package/extensions/dist/base.js +1 -1
  104. package/extensions/dist/lsp.js +13 -2
  105. package/extensions/typings.d.ts +2 -2
  106. package/package.json +9 -7
  107. package/extensions/es7/base.js +0 -320
  108. package/extensions/es7/lint.js +0 -97
@@ -43,7 +43,7 @@ catch {
43
43
  * @param s 模板或魔术字名
44
44
  */
45
45
  const getSymbol = (s) => {
46
- const name = (0, string_1.removeComment)(s).trim().toLowerCase();
46
+ const name = (0, string_1.trimLc)((0, string_1.removeComment)(s));
47
47
  if (marks.has(name)) {
48
48
  return marks.get(name); // 标记{{!}}等
49
49
  }
@@ -64,12 +64,7 @@ const getSymbol = (s) => {
64
64
  * @throws `TranscludeToken.constructor()`
65
65
  */
66
66
  const parseBraces = (wikitext, config, accum) => {
67
- const source = String.raw `${config.excludes?.includes('heading') ? '' : String.raw `^((?:\0\d+[cno]\x7F)*)={1,6}|`}\[\[|-\{(?!\{)`, { parserFunction: [, , , subst] } = config, stack = [], linkStack = [];
68
- /**
69
- * 恢复内链
70
- * @param s 不含内链的字符串
71
- */
72
- const restore = (s) => s.replace(/\0(\d+)\x7F/gu, (_, p1) => linkStack[p1]);
67
+ const source = String.raw `${config.excludes.includes('heading') ? '' : String.raw `^((?:\0\d+[cno]\x7F)*)={1,6}|`}\[\[|-\{(?!\{)`, { parserFunction: [, , , subst] } = config, stack = [], linkStack = [];
73
68
  /**
74
69
  * 填入模板内容
75
70
  * @param text wikitext全文
@@ -78,7 +73,7 @@ const parseBraces = (wikitext, config, accum) => {
78
73
  * @param index 匹配位置
79
74
  */
80
75
  const push = (text, parts, lastIndex, index) => {
81
- parts[parts.length - 1].push(restore(text.slice(lastIndex, index)));
76
+ parts[parts.length - 1].push((0, string_1.restore)(text.slice(lastIndex, index), linkStack));
82
77
  };
83
78
  let replaced;
84
79
  do {
@@ -90,9 +85,10 @@ const parseBraces = (wikitext, config, accum) => {
90
85
  try {
91
86
  const { length } = accum, parts = (p1 ?? p2).split('|');
92
87
  // @ts-expect-error abstract class
93
- new transclude_1.TranscludeToken(restore(parts[0]), parts.slice(1).map(part => {
88
+ new transclude_1.TranscludeToken((0, string_1.restore)(parts[0], linkStack), parts.slice(1).map(part => {
94
89
  const i = part.indexOf('=');
95
- return (i === -1 ? [part] : [part.slice(0, i), part.slice(i + 1)]).map(restore);
90
+ return (i === -1 ? [part] : [part.slice(0, i), part.slice(i + 1)])
91
+ .map(s => (0, string_1.restore)(s, linkStack));
96
92
  }), config, accum);
97
93
  return `\0${length}${getSymbol(parts[0])}\x7F`;
98
94
  }
@@ -103,7 +99,7 @@ const parseBraces = (wikitext, config, accum) => {
103
99
  }
104
100
  }
105
101
  }
106
- linkStack.push(restore(m));
102
+ linkStack.push((0, string_1.restore)(m, linkStack));
107
103
  return `\0${linkStack.length - 1}\x7F`;
108
104
  });
109
105
  } while (replaced !== wikitext);
@@ -137,7 +133,7 @@ const parseBraces = (wikitext, config, accum) => {
137
133
  const rmt = /^(={1,6})(.+)\1((?:\s|\0\d+[cn]\x7F)*)$/u
138
134
  .exec(wikitext.slice(index, curIndex));
139
135
  if (rmt) {
140
- rmt[2] = restore(rmt[2]);
136
+ rmt[2] = (0, string_1.restore)(rmt[2], linkStack);
141
137
  if (!rmt[2].includes('\n')) {
142
138
  wikitext = `${wikitext.slice(0, index)}\0${accum.length}h\x7F${wikitext.slice(curIndex)}`;
143
139
  lastIndex = index + 4 + String(accum.length).length;
@@ -221,7 +217,7 @@ const parseBraces = (wikitext, config, accum) => {
221
217
  regex.lastIndex = lastIndex;
222
218
  mt = regex.exec(wikitext);
223
219
  }
224
- return restore(wikitext);
220
+ return (0, string_1.restore)(wikitext, linkStack);
225
221
  };
226
222
  exports.parseBraces = parseBraces;
227
223
  constants_1.parsers['parseBraces'] = __filename;
@@ -2,8 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseCommentAndExt = void 0;
4
4
  const common_1 = require("@bhsd/common");
5
+ const string_1 = require("../util/string");
5
6
  const onlyinclude_1 = require("../src/onlyinclude");
6
7
  const noinclude_1 = require("../src/nowiki/noinclude");
8
+ const translate_1 = require("../src/tagPair/translate");
7
9
  const include_1 = require("../src/tagPair/include");
8
10
  const ext_1 = require("../src/tagPair/ext");
9
11
  const comment_1 = require("../src/nowiki/comment");
@@ -61,13 +63,27 @@ const parseCommentAndExt = (wikitext, config, accum, includeOnly) => {
61
63
  return str;
62
64
  }
63
65
  }
64
- return wikitext.replace(getRegex[includeOnly ? 1 : 0](config.ext), (substr, name, attr, inner, closing, include, includeAttr, includeInner, includeClosing) => {
66
+ const { ext } = config, newExt = ext.filter(e => e !== 'translate' && e !== 'tvar'), newConfig = { ...config, ext: newExt };
67
+ if (ext.includes('translate')) {
68
+ const stack = [];
69
+ wikitext = wikitext.replace(/<nowiki>[\s\S]*?<\/nowiki>/giu, m => {
70
+ stack.push(m);
71
+ return `\0${stack.length - 1}\x7F`;
72
+ }).replace(/<translate( nowrap)?>([\s\S]+?)?<\/translate>/gu, (_, p1, p2) => {
73
+ const l = accum.length;
74
+ // @ts-expect-error abstract class
75
+ new translate_1.TranslateToken(p1, p2 && (0, string_1.restore)(p2, stack), newConfig, accum);
76
+ return `\0${l}g\x7F`;
77
+ });
78
+ wikitext = (0, string_1.restore)(wikitext, stack);
79
+ }
80
+ return wikitext.replace(getRegex[includeOnly ? 1 : 0](newExt), (substr, name, attr, inner, closing, include, includeAttr, includeInner, includeClosing) => {
65
81
  const l = accum.length;
66
82
  let ch = 'n';
67
83
  if (name) {
68
84
  ch = 'e';
69
85
  // @ts-expect-error abstract class
70
- new ext_1.ExtToken(name, attr, inner, closing, config, include, accum);
86
+ new ext_1.ExtToken(name, attr, inner, closing, newConfig, include, accum);
71
87
  }
72
88
  else if (substr.startsWith('<!--')) {
73
89
  ch = 'c';
@@ -17,8 +17,8 @@ const parseMagicLinks = (wikitext, config, accum) => {
17
17
  if (!config.regexMagicLinks) {
18
18
  try {
19
19
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions, es-x/no-regexp-unicode-property-escapes
20
- /(^|[^\p{L}\d_])(?:(?:ftp:\/\/|http:\/\/)((?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])[^[\]<>"\0\t\n\p{Zs}]*)|(?:rfc|pmid)[\p{Zs}\t]+\d+\b|isbn[\p{Zs}\t]+(?:97[89][\p{Zs}\t-]?)?(?:\d[\p{Zs}\t-]?){9}[\dx]\b)/giu;
21
- config.regexMagicLinks = new RegExp(String.raw `(^|[^\p{L}\d_])(?:(?:${config.protocol})(${string_1.extUrlCharFirst}${string_1.extUrlChar})|${magicLinkPattern})`, 'giu');
20
+ /(^|[^\p{L}\p{N}_])(?:(?:ftp:\/\/|http:\/\/)((?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])[^[\]<>"\0\t\n\p{Zs}]*)|(?:rfc|pmid)[\p{Zs}\t]+\d+\b|isbn[\p{Zs}\t]+(?:97[89][\p{Zs}\t-]?)?(?:\d[\p{Zs}\t-]?){9}[\dx]\b)/giu;
21
+ config.regexMagicLinks = new RegExp(String.raw `(^|[^\p{L}\p{N}_])(?:(?:${config.protocol})(${string_1.extUrlCharFirst}${string_1.extUrlChar})|${magicLinkPattern})`, 'giu');
22
22
  }
23
23
  catch /* istanbul ignore next */ {
24
24
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
@@ -14,8 +14,11 @@ const attributes_1 = require("../lib/attributes");
14
14
  * @param name
15
15
  */
16
16
  const basic = (selector, type, name) => {
17
- const [t, ...names] = selector.split('#');
18
- return (!t || t === type) && names.every(n => n === name);
17
+ if (selector.includes('#')) {
18
+ const [t, ...names] = selector.split('#');
19
+ return (!t || t === type) && names.every(n => n === name);
20
+ }
21
+ return !selector || selector === type;
19
22
  };
20
23
  /* NOT FOR BROWSER */
21
24
  const simplePseudos = new Set([
package/dist/src/arg.js CHANGED
@@ -41,6 +41,8 @@ exports.ArgToken = void 0;
41
41
  const string_1 = require("../util/string");
42
42
  const lint_1 = require("../util/lint");
43
43
  const rect_1 = require("../lib/rect");
44
+ const padded_1 = require("../mixin/padded");
45
+ const gapped_1 = require("../mixin/gapped");
44
46
  const index_1 = require("./index");
45
47
  const atom_1 = require("./atom");
46
48
  const hidden_1 = require("./hidden");
@@ -57,7 +59,7 @@ const index_2 = __importDefault(require("../index"));
57
59
  * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken[]]}`
58
60
  */
59
61
  let ArgToken = (() => {
60
- let _classDecorators = [noEscape_1.noEscape];
62
+ let _classDecorators = [noEscape_1.noEscape, (0, padded_1.padded)('{{{'), (0, gapped_1.gapped)()];
61
63
  let _classDescriptor;
62
64
  let _classExtraInitializers = [];
63
65
  let _classThis;
@@ -119,14 +121,6 @@ let ArgToken = (() => {
119
121
  text() {
120
122
  return `{{{${(0, string_1.text)(this.childNodes.slice(0, 2), '|')}}}}`;
121
123
  }
122
- /** @private */
123
- getAttribute(key) {
124
- return key === 'padding' ? 3 : super.getAttribute(key);
125
- }
126
- /** @private */
127
- getGaps() {
128
- return 1;
129
- }
130
124
  /** 设置name */
131
125
  #setName() {
132
126
  // eslint-disable-next-line no-unused-labels
@@ -160,7 +154,10 @@ let ArgToken = (() => {
160
154
  if (argDefault) {
161
155
  const index = start + 4 + argName.toString().length;
162
156
  argDefault.setAttribute('aIndex', index);
163
- errors.push(...argDefault.lint(index, re));
157
+ const childErrors = argDefault.lint(index, re);
158
+ if (childErrors.length > 0) {
159
+ errors.push(...childErrors);
160
+ }
164
161
  }
165
162
  if (rest.length > 0) {
166
163
  const rect = new rect_1.BoundingRect(this, start);
@@ -194,7 +191,7 @@ let ArgToken = (() => {
194
191
  // @ts-expect-error abstract class
195
192
  const token = new ArgToken([''], this.getAttribute('config'));
196
193
  token.firstChild.safeReplaceWith(name);
197
- token.append(...cloned);
194
+ token.safeAppend(cloned);
198
195
  return token;
199
196
  });
200
197
  }
@@ -251,7 +248,7 @@ let ArgToken = (() => {
251
248
  setName(name) {
252
249
  const { childNodes } = index_2.default
253
250
  .parse(name, this.getAttribute('include'), 2, this.getAttribute('config'));
254
- this.firstChild.replaceChildren(...childNodes);
251
+ this.firstChild.safeReplaceChildren(childNodes);
255
252
  }
256
253
  /**
257
254
  * Set the default value
@@ -267,7 +264,7 @@ let ArgToken = (() => {
267
264
  const root = index_2.default
268
265
  .parse(value, this.getAttribute('include'), undefined, this.getAttribute('config')), { childNodes: [, oldDefault] } = this;
269
266
  if (oldDefault) {
270
- oldDefault.replaceChildren(...root.childNodes);
267
+ oldDefault.safeReplaceChildren(root.childNodes);
271
268
  }
272
269
  else {
273
270
  root.type = 'arg-default';
package/dist/src/atom.js CHANGED
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AtomToken = void 0;
4
4
  const index_1 = require("./index");
5
5
  /* NOT FOR BROWSER */
6
- const debug_1 = require("../util/debug");
7
6
  const constants_1 = require("../util/constants");
7
+ const html_1 = require("../util/html");
8
8
  /* NOT FOR BROWSER END */
9
9
  const atomTypes = [
10
10
  'arg-name',
@@ -47,12 +47,7 @@ class AtomToken extends index_1.Token {
47
47
  }
48
48
  /* NOT FOR BROWSER */
49
49
  cloneNode() {
50
- const cloned = this.cloneChildNodes(), config = this.getAttribute('config'), acceptable = this.getAcceptable();
51
- return debug_1.Shadow.run(() => {
52
- const token = new AtomToken(undefined, this.type, config, [], acceptable);
53
- token.append(...cloned);
54
- return token;
55
- });
50
+ return (0, html_1.cloneNode)(this, () => new AtomToken(undefined, this.type, this.getAttribute('config'), [], this.getAcceptable()));
56
51
  }
57
52
  }
58
53
  exports.AtomToken = AtomToken;
@@ -153,7 +153,7 @@ let AttributeToken = (() => {
153
153
  this.#equal = equal;
154
154
  this.#quotes = [...quotes];
155
155
  this.#tag = tag;
156
- this.setAttribute('name', (0, string_1.removeComment)(key).trim().toLowerCase());
156
+ this.setAttribute('name', (0, string_1.trimLc)((0, string_1.removeComment)(key)));
157
157
  }
158
158
  /** @private */
159
159
  afterBuild() {
@@ -163,7 +163,7 @@ let AttributeToken = (() => {
163
163
  if (this.parentNode) {
164
164
  this.#tag = this.parentNode.name;
165
165
  }
166
- this.setAttribute('name', this.firstChild.text().trim().toLowerCase());
166
+ this.setAttribute('name', (0, string_1.trimLc)(this.firstChild.text()));
167
167
  super.afterBuild();
168
168
  }
169
169
  /** @private */
@@ -213,8 +213,8 @@ let AttributeToken = (() => {
213
213
  errors.push(e);
214
214
  }
215
215
  else if (type !== 'ext-attr' && !lastChild.childNodes.some(({ type: t }) => complexTypes.has(t))) {
216
- const data = lint_1.htmlData.provideValues(tag, name), v = String(value).toLowerCase();
217
- if (data.length > 0 && data.every(({ name: n }) => n !== v)) {
216
+ const data = (0, lint_1.provideValues)(tag, name), v = String(value).toLowerCase();
217
+ if (data.length > 0 && data.every(n => n !== v)) {
218
218
  errors.push((0, lint_1.generateForChild)(lastChild, rect, 'illegal-attr', 'illegal attribute value', 'warning'));
219
219
  }
220
220
  }
@@ -293,7 +293,7 @@ let AttributeToken = (() => {
293
293
  throw new RangeError('Attribute values cannot contain single and double quotes simultaneously!');
294
294
  }
295
295
  const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(value, this.getAttribute('include'), stages[type] + 1, config);
296
- lastChild.replaceChildren(...childNodes);
296
+ lastChild.safeReplaceChildren(childNodes);
297
297
  if (value.includes('"')) {
298
298
  this.#quotes = [`'`, `'`];
299
299
  }
@@ -316,7 +316,7 @@ let AttributeToken = (() => {
316
316
  throw new Error(`${this.name} attribute cannot be renamed!`);
317
317
  }
318
318
  const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(key, this.getAttribute('include'), stages[this.type] + 1, config);
319
- this.firstChild.replaceChildren(...childNodes);
319
+ this.firstChild.safeReplaceChildren(childNodes);
320
320
  }
321
321
  /** @private */
322
322
  toHtmlInternal() {
@@ -29,7 +29,7 @@ const toDirty = (type) => `${toAttributeType(type)}-dirty`;
29
29
  let wordRegex;
30
30
  try {
31
31
  // eslint-disable-next-line prefer-regex-literals, es-x/no-regexp-unicode-property-escapes
32
- wordRegex = new RegExp(String.raw `[\p{L}\d]`, 'u');
32
+ wordRegex = new RegExp(String.raw `[\p{L}\p{N}]`, 'u');
33
33
  }
34
34
  catch /* istanbul ignore next */ {
35
35
  wordRegex = /[^\W_]/u;
@@ -162,7 +162,7 @@ class AttributesToken extends index_2.Token {
162
162
  * @param key attribute name / 属性名
163
163
  */
164
164
  getAttrTokens(key) {
165
- return this.childNodes.filter((child) => child instanceof attribute_1.AttributeToken && (!key || child.name === key.toLowerCase().trim()));
165
+ return this.childNodes.filter((child) => child instanceof attribute_1.AttributeToken && (!key || child.name === (0, string_1.trimLc)(key)));
166
166
  }
167
167
  /**
168
168
  * Get the last AttributeToken with the specified attribute name
@@ -260,13 +260,9 @@ class AttributesToken extends index_2.Token {
260
260
  }
261
261
  }
262
262
  cloneNode() {
263
- const cloned = this.cloneChildNodes();
264
- return debug_1.Shadow.run(() => {
265
- // @ts-expect-error abstract class
266
- const token = new AttributesToken(undefined, this.type, this.name, this.getAttribute('config'));
267
- token.append(...cloned);
268
- return token;
269
- });
263
+ return (0, html_1.cloneNode)(this,
264
+ // @ts-expect-error abstract class
265
+ () => new AttributesToken(undefined, this.type, this.name, this.getAttribute('config')));
270
266
  }
271
267
  /**
272
268
  * @override
@@ -308,7 +304,7 @@ class AttributesToken extends index_2.Token {
308
304
  return token;
309
305
  }
310
306
  setAttr(keyOrProp, value) {
311
- if (typeof keyOrProp !== 'string') {
307
+ if (typeof keyOrProp === 'object') {
312
308
  for (const [key, val] of Object.entries(keyOrProp)) {
313
309
  this.setAttr(key, val);
314
310
  }
@@ -318,7 +314,7 @@ class AttributesToken extends index_2.Token {
318
314
  if (type === 'ext-attrs' && typeof value === 'string' && value.includes('>')) {
319
315
  throw new RangeError('Attributes of an extension tag cannot contain ">"!');
320
316
  }
321
- const key = keyOrProp.toLowerCase().trim(), attr = this.getAttrToken(key);
317
+ const key = (0, string_1.trimLc)(keyOrProp), attr = this.getAttrToken(key);
322
318
  if (attr) {
323
319
  attr.setValue(value);
324
320
  return;
@@ -375,7 +371,7 @@ class AttributesToken extends index_2.Token {
375
371
  * @throws `RangeError` 不为Boolean类型的属性值
376
372
  */
377
373
  toggleAttr(key, force) {
378
- key = key.toLowerCase().trim();
374
+ key = (0, string_1.trimLc)(key);
379
375
  const attr = this.getAttrToken(key);
380
376
  if (attr && attr.getValue() !== true) {
381
377
  throw new RangeError(`${key} attribute is not Boolean!`);
@@ -0,0 +1,26 @@
1
+ import { Token } from './index';
2
+ import { CommentToken } from './nowiki/comment';
3
+ import type { Config, LintError } from '../base';
4
+ import type { AstText, AttributesToken, ExtToken } from '../internal';
5
+ /**
6
+ * `<hiero>`
7
+ * @classdesc `{childNodes: (AstText|CommentToken)[]}`
8
+ */
9
+ export declare abstract class CommentedToken extends Token {
10
+ readonly childNodes: readonly (AstText | CommentToken)[];
11
+ abstract get firstChild(): AstText | CommentToken | undefined;
12
+ abstract get lastChild(): AstText | CommentToken | undefined;
13
+ abstract get nextSibling(): undefined;
14
+ abstract get previousSibling(): AttributesToken | undefined;
15
+ abstract get parentNode(): ExtToken | undefined;
16
+ abstract get children(): CommentToken[];
17
+ abstract get firstElementChild(): CommentToken | undefined;
18
+ abstract get lastElementChild(): CommentToken | undefined;
19
+ abstract get previousElementSibling(): AttributesToken | undefined;
20
+ abstract get nextElementSibling(): undefined;
21
+ abstract get parentElement(): ExtToken | undefined;
22
+ get type(): 'ext-inner';
23
+ /** @class */
24
+ constructor(wikitext?: string, config?: Config, accum?: Token[]);
25
+ cloneNode(): this;
26
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommentedToken = void 0;
4
+ const index_1 = require("./index");
5
+ const comment_1 = require("./nowiki/comment");
6
+ /* NOT FOR BROWSER */
7
+ const constants_1 = require("../util/constants");
8
+ const html_1 = require("../util/html");
9
+ /* NOT FOR BROWSER END */
10
+ /**
11
+ * `<hiero>`
12
+ * @classdesc `{childNodes: (AstText|CommentToken)[]}`
13
+ */
14
+ class CommentedToken extends index_1.Token {
15
+ /* NOT FOR BROWSER END */
16
+ get type() {
17
+ return 'ext-inner';
18
+ }
19
+ /** @class */
20
+ constructor(wikitext, config, accum = []) {
21
+ super(undefined, config, accum, {
22
+ AstText: ':', CommentToken: ':',
23
+ });
24
+ if (wikitext) {
25
+ let i = wikitext.indexOf('<!--'), j = i !== -1 && wikitext.indexOf('-->', i + 4), lastIndex = 0;
26
+ while (j !== false && j !== -1) {
27
+ if (i > lastIndex) {
28
+ this.insertAt(wikitext.slice(lastIndex, i));
29
+ }
30
+ // @ts-expect-error abstract class
31
+ this.insertAt(new comment_1.CommentToken(wikitext.slice(i + 4, j), true, config, accum));
32
+ lastIndex = j + 3;
33
+ i = wikitext.indexOf('<!--', lastIndex);
34
+ j = i !== -1 && wikitext.indexOf('-->', i + 4);
35
+ }
36
+ if (lastIndex < wikitext.length) {
37
+ this.insertAt(wikitext.slice(lastIndex));
38
+ }
39
+ }
40
+ }
41
+ /** @private */
42
+ lint(start = this.getAbsoluteIndex()) {
43
+ return super.lint(start, /<\s*(?:\/\s*)?(hiero)\b/giu);
44
+ }
45
+ /* NOT FOR BROWSER */
46
+ cloneNode() {
47
+ // @ts-expect-error abstract class
48
+ return (0, html_1.cloneNode)(this, () => new CommentedToken(undefined, this.getAttribute('config')));
49
+ }
50
+ }
51
+ exports.CommentedToken = CommentedToken;
52
+ constants_1.classes['CommentedToken'] = __filename;
@@ -36,6 +36,7 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
37
  exports.ConverterToken = void 0;
38
38
  const string_1 = require("../util/string");
39
+ const padded_1 = require("../mixin/padded");
39
40
  const index_1 = require("./index");
40
41
  const converterFlags_1 = require("./converterFlags");
41
42
  const converterRule_1 = require("./converterRule");
@@ -52,7 +53,7 @@ const noEscape_1 = require("../mixin/noEscape");
52
53
  * @classdesc `{childNodes: [ConverterFlagsToken, ...ConverterRuleToken[]]}`
53
54
  */
54
55
  let ConverterToken = (() => {
55
- let _classDecorators = [noEscape_1.noEscape];
56
+ let _classDecorators = [noEscape_1.noEscape, (0, padded_1.padded)('-{')];
56
57
  let _classDescriptor;
57
58
  let _classExtraInitializers = [];
58
59
  let _classThis;
@@ -119,10 +120,6 @@ let ConverterToken = (() => {
119
120
  return `-{${flags.text()}|${(0, string_1.text)(rules, ';')}}-`;
120
121
  }
121
122
  /** @private */
122
- getAttribute(key) {
123
- return key === 'padding' ? 2 : super.getAttribute(key);
124
- }
125
- /** @private */
126
123
  getGaps(i) {
127
124
  return i || this.firstChild.length > 0 ? 1 : 0;
128
125
  }
@@ -139,7 +136,7 @@ let ConverterToken = (() => {
139
136
  const token = new ConverterToken([], [''], this.getAttribute('config'));
140
137
  token.firstChild.safeReplaceWith(flags);
141
138
  token.removeAt(1);
142
- token.append(...rules);
139
+ token.safeAppend(rules);
143
140
  return token;
144
141
  });
145
142
  }