wikiparser-node 1.16.3 → 1.16.5

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 (154) hide show
  1. package/README.md +1 -1
  2. package/bundle/bundle.es7.js +28 -28
  3. package/bundle/bundle.lsp.js +30 -30
  4. package/bundle/bundle.min.js +29 -29
  5. package/coverage/badge.svg +1 -1
  6. package/data/signatures.json +43 -0
  7. package/dist/addon/table.js +7 -4
  8. package/dist/addon/token.js +119 -113
  9. package/dist/addon/transclude.js +7 -5
  10. package/dist/base.d.mts +99 -30
  11. package/dist/base.d.ts +99 -30
  12. package/dist/index.d.ts +10 -4
  13. package/dist/index.js +59 -14
  14. package/dist/lib/attributes.js +2 -2
  15. package/dist/lib/element.d.ts +128 -29
  16. package/dist/lib/element.js +178 -32
  17. package/dist/lib/lsp.d.ts +62 -27
  18. package/dist/lib/lsp.js +395 -304
  19. package/dist/lib/node.d.ts +123 -54
  20. package/dist/lib/node.js +216 -87
  21. package/dist/lib/range.d.ts +83 -31
  22. package/dist/lib/range.js +83 -31
  23. package/dist/lib/ranges.d.ts +1 -1
  24. package/dist/lib/ranges.js +3 -2
  25. package/dist/lib/text.d.ts +40 -14
  26. package/dist/lib/text.js +47 -19
  27. package/dist/lib/title.d.ts +54 -17
  28. package/dist/lib/title.js +101 -47
  29. package/dist/mixin/attributesParent.d.ts +37 -21
  30. package/dist/mixin/attributesParent.js +18 -20
  31. package/dist/mixin/flagsParent.d.ts +38 -12
  32. package/dist/mixin/hidden.d.ts +0 -2
  33. package/dist/mixin/hidden.js +0 -2
  34. package/dist/mixin/magicLinkParent.d.ts +11 -5
  35. package/dist/mixin/singleLine.d.ts +0 -2
  36. package/dist/mixin/singleLine.js +3 -3
  37. package/dist/mixin/sol.d.ts +0 -2
  38. package/dist/mixin/sol.js +2 -3
  39. package/dist/mixin/syntax.d.ts +0 -2
  40. package/dist/mixin/syntax.js +0 -2
  41. package/dist/parser/braces.js +4 -2
  42. package/dist/parser/links.js +13 -7
  43. package/dist/parser/list.js +3 -1
  44. package/dist/parser/quotes.js +22 -2
  45. package/dist/parser/redirect.js +4 -1
  46. package/dist/parser/selector.js +1 -1
  47. package/dist/src/arg.d.ts +19 -9
  48. package/dist/src/arg.js +34 -15
  49. package/dist/src/atom.d.ts +5 -1
  50. package/dist/src/atom.js +5 -1
  51. package/dist/src/attribute.d.ts +26 -8
  52. package/dist/src/attribute.js +30 -11
  53. package/dist/src/attributes.d.ts +50 -22
  54. package/dist/src/attributes.js +54 -26
  55. package/dist/src/converter.d.ts +4 -2
  56. package/dist/src/converter.js +12 -9
  57. package/dist/src/converterFlags.d.ts +45 -15
  58. package/dist/src/converterFlags.js +45 -15
  59. package/dist/src/converterRule.d.ts +30 -11
  60. package/dist/src/converterRule.js +46 -16
  61. package/dist/src/extLink.d.ts +6 -2
  62. package/dist/src/extLink.js +14 -11
  63. package/dist/src/gallery.d.ts +13 -9
  64. package/dist/src/gallery.js +35 -21
  65. package/dist/src/heading.d.ts +13 -7
  66. package/dist/src/heading.js +28 -18
  67. package/dist/src/hidden.d.ts +5 -1
  68. package/dist/src/hidden.js +7 -3
  69. package/dist/src/html.d.ts +12 -10
  70. package/dist/src/html.js +17 -12
  71. package/dist/src/imageParameter.d.ts +27 -12
  72. package/dist/src/imageParameter.js +27 -12
  73. package/dist/src/imagemap.d.ts +4 -4
  74. package/dist/src/imagemap.js +9 -5
  75. package/dist/src/imagemapLink.d.ts +3 -1
  76. package/dist/src/imagemapLink.js +3 -1
  77. package/dist/src/index.d.ts +65 -64
  78. package/dist/src/index.js +111 -132
  79. package/dist/src/link/base.d.ts +14 -6
  80. package/dist/src/link/base.js +45 -21
  81. package/dist/src/link/category.d.ts +9 -4
  82. package/dist/src/link/category.js +20 -4
  83. package/dist/src/link/file.d.ts +71 -23
  84. package/dist/src/link/file.js +100 -36
  85. package/dist/src/link/galleryImage.d.ts +8 -4
  86. package/dist/src/link/galleryImage.js +15 -8
  87. package/dist/src/link/index.d.ts +14 -6
  88. package/dist/src/link/index.js +15 -5
  89. package/dist/src/link/redirectTarget.d.ts +4 -3
  90. package/dist/src/link/redirectTarget.js +5 -3
  91. package/dist/src/magicLink.d.ts +28 -12
  92. package/dist/src/magicLink.js +56 -34
  93. package/dist/src/nested.d.ts +5 -3
  94. package/dist/src/nested.js +9 -6
  95. package/dist/src/nowiki/base.d.ts +4 -2
  96. package/dist/src/nowiki/base.js +6 -5
  97. package/dist/src/nowiki/comment.d.ts +6 -2
  98. package/dist/src/nowiki/comment.js +8 -3
  99. package/dist/src/nowiki/dd.d.ts +0 -3
  100. package/dist/src/nowiki/dd.js +0 -8
  101. package/dist/src/nowiki/doubleUnderscore.d.ts +5 -1
  102. package/dist/src/nowiki/doubleUnderscore.js +5 -1
  103. package/dist/src/nowiki/index.d.ts +5 -1
  104. package/dist/src/nowiki/index.js +5 -1
  105. package/dist/src/nowiki/list.d.ts +5 -1
  106. package/dist/src/nowiki/list.js +5 -1
  107. package/dist/src/nowiki/listBase.d.ts +15 -5
  108. package/dist/src/nowiki/listBase.js +41 -10
  109. package/dist/src/nowiki/noinclude.d.ts +5 -1
  110. package/dist/src/nowiki/noinclude.js +5 -1
  111. package/dist/src/nowiki/quote.d.ts +15 -8
  112. package/dist/src/nowiki/quote.js +32 -12
  113. package/dist/src/onlyinclude.d.ts +4 -2
  114. package/dist/src/onlyinclude.js +4 -2
  115. package/dist/src/paramTag/index.d.ts +1 -1
  116. package/dist/src/paramTag/index.js +1 -1
  117. package/dist/src/parameter.d.ts +24 -12
  118. package/dist/src/parameter.js +45 -27
  119. package/dist/src/pre.d.ts +1 -1
  120. package/dist/src/pre.js +1 -1
  121. package/dist/src/redirect.d.ts +2 -0
  122. package/dist/src/redirect.js +2 -0
  123. package/dist/src/syntax.d.ts +5 -1
  124. package/dist/src/syntax.js +5 -1
  125. package/dist/src/table/base.d.ts +5 -1
  126. package/dist/src/table/base.js +11 -4
  127. package/dist/src/table/index.d.ts +134 -66
  128. package/dist/src/table/index.js +149 -81
  129. package/dist/src/table/td.d.ts +18 -10
  130. package/dist/src/table/td.js +23 -15
  131. package/dist/src/table/tr.d.ts +13 -3
  132. package/dist/src/table/tr.js +14 -6
  133. package/dist/src/table/trBase.d.ts +28 -12
  134. package/dist/src/table/trBase.js +28 -18
  135. package/dist/src/tagPair/ext.d.ts +3 -1
  136. package/dist/src/tagPair/ext.js +11 -10
  137. package/dist/src/tagPair/include.d.ts +8 -2
  138. package/dist/src/tagPair/include.js +8 -2
  139. package/dist/src/tagPair/index.d.ts +6 -2
  140. package/dist/src/tagPair/index.js +6 -2
  141. package/dist/src/transclude.d.ts +107 -33
  142. package/dist/src/transclude.js +139 -45
  143. package/dist/util/debug.js +2 -7
  144. package/dist/util/html.js +1 -14
  145. package/dist/util/string.js +7 -1
  146. package/extensions/dist/base.js +25 -8
  147. package/extensions/dist/codejar.js +2 -1
  148. package/extensions/dist/lsp.js +5 -10
  149. package/extensions/es7/base.js +25 -8
  150. package/extensions/ui.css +1 -162
  151. package/i18n/zh-hans.json +1 -1
  152. package/i18n/zh-hant.json +1 -1
  153. package/package.json +3 -3
  154. package/extensions/dist/test-page.js +0 -89
@@ -43,13 +43,12 @@ const index_2 = require("./index");
43
43
  /* NOT FOR BROWSER */
44
44
  const debug_1 = require("../util/debug");
45
45
  const constants_1 = require("../util/constants");
46
- const html_1 = require("../util/html");
47
46
  const syntax_1 = require("../mixin/syntax");
48
47
  const space = String.raw `(?:[${string_1.zs}\t]| |&#0*160;|&#[xX]0*[aA]0;)`;
49
48
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions, es-x/no-regexp-unicode-property-escapes
50
49
  /(?:[\p{Zs}\t]| |&#0*160;|&#[xX]0*[aA]0;)+/gu;
51
50
  const spaceRegex = new RegExp(`${space}+`, 'gu');
52
- /** NOT FOR BROWSER */
51
+ /* NOT FOR BROWSER */
53
52
  const spdash = String.raw `(?:[\p{Zs}\t-]| |&#0*160;|&#[xX]0*[aA]0;)`;
54
53
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions, es-x/no-regexp-unicode-property-escapes
55
54
  /^(ISBN)[\p{Zs}\t]+(?:97[89][\p{Zs}\t-]?)?(?:\d[\p{Zs}\t-]?){9}[\dxX]$/u;
@@ -57,10 +56,12 @@ const isbnPattern = new RegExp(String.raw `^(ISBN)${space}+(?:97[89]${spdash}?)?
57
56
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions, es-x/no-regexp-unicode-property-escapes
58
57
  /^(RFC|PMID)[\p{Zs}\t]+\d+$/u;
59
58
  const rfcPattern = new RegExp(String.raw `^(RFC|PMID)${space}+\d+$`, 'u');
60
- /** NOT FOR BROWSER END */
59
+ /* NOT FOR BROWSER END */
61
60
  /**
61
+ * free external link
62
+ *
62
63
  * 自由外链
63
- * @classdesc `{childNodes: ...AstText|CommentToken|IncludeToken|NoincludeToken}`
64
+ * @classdesc `{childNodes: (AstText|CommentToken|IncludeToken|NoincludeToken)[]}`
64
65
  */
65
66
  let MagicLinkToken = (() => {
66
67
  let _classDecorators = [(0, syntax_1.syntax)()];
@@ -82,7 +83,7 @@ let MagicLinkToken = (() => {
82
83
  get type() {
83
84
  return this.#type;
84
85
  }
85
- /** 链接显示文字 */
86
+ /** text of the link / 链接显示文字 */
86
87
  get innerText() {
87
88
  const map = new Map([['!', '|'], ['=', '=']]);
88
89
  let link = (0, string_1.text)(this.childNodes.map(child => {
@@ -94,12 +95,13 @@ let MagicLinkToken = (() => {
94
95
  }
95
96
  return link;
96
97
  }
97
- /** 和内链保持一致 */
98
+ /** link / 链接 */
98
99
  get link() {
99
100
  const { innerText } = this;
100
101
  if (this.type === 'magic-link') {
101
102
  return innerText.startsWith('ISBN')
102
- ? `ISBN ${innerText.slice(5).replace(/[- ]/gu, '').replace(/x$/u, 'X')}`
103
+ ? `ISBN ${innerText.slice(5).replace(/[- ]/gu, '')
104
+ .replace(/x$/u, 'X')}`
103
105
  : innerText;
104
106
  }
105
107
  return (0, string_1.decodeNumber)(innerText);
@@ -108,7 +110,7 @@ let MagicLinkToken = (() => {
108
110
  set link(url) {
109
111
  this.setTarget(url);
110
112
  }
111
- /** 协议 */
113
+ /** URL protocol / 协议 */
112
114
  get protocol() {
113
115
  return this.pattern.exec(this.text())?.[1];
114
116
  }
@@ -143,8 +145,8 @@ let MagicLinkToken = (() => {
143
145
  }
144
146
  /** @private */
145
147
  lint(start = this.getAbsoluteIndex(), re) {
146
- const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start);
147
- if (this.type === 'magic-link') {
148
+ const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start), { type, childNodes } = this;
149
+ if (type === 'magic-link') {
148
150
  const { link } = this;
149
151
  if (link.startsWith('ISBN')) {
150
152
  // eslint-disable-next-line unicorn/no-useless-spread, @typescript-eslint/no-misused-spread
@@ -157,7 +159,7 @@ let MagicLinkToken = (() => {
157
159
  }
158
160
  return errors;
159
161
  }
160
- const pipe = this.type === 'ext-link-url', regex = pipe ? /\|/u : /[,;。:!?()]+/u, child = this.childNodes.find((c) => c.type === 'text' && regex.test(c.data));
162
+ const pipe = type === 'ext-link-url', regex = pipe ? /\|/u : /[,;。:!?()]+/u, child = childNodes.find((c) => c.type === 'text' && regex.test(c.data));
161
163
  if (child) {
162
164
  const { data } = child, e = (0, lint_1.generateForChild)(child, rect, 'unterminated-url', index_1.default.msg('$1 in URL', pipe ? '"|"' : 'full-width punctuation'), 'warning'), { index, 0: s } = regex.exec(data), i = e.startIndex + index;
163
165
  e.suggestions = pipe
@@ -170,6 +172,32 @@ let MagicLinkToken = (() => {
170
172
  }
171
173
  return errors;
172
174
  }
175
+ /**
176
+ * Get the URL
177
+ *
178
+ * 获取网址
179
+ * @param articlePath article path / 条目路径
180
+ */
181
+ getUrl(articlePath) {
182
+ LSP: { // eslint-disable-line no-unused-labels
183
+ const { type } = this;
184
+ let { link } = this;
185
+ if (type === 'magic-link') {
186
+ if (link.startsWith('ISBN')) {
187
+ return this
188
+ .normalizeTitle(`BookSources/${link.slice(5)}`, -1, true)
189
+ .getUrl(articlePath);
190
+ }
191
+ link = link.startsWith('RFC')
192
+ ? `https://tools.ietf.org/html/rfc${link.slice(4)}`
193
+ : `https://pubmed.ncbi.nlm.nih.gov/${link.slice(5)}`;
194
+ }
195
+ else if (link.startsWith('//')) {
196
+ link = `https:${link}`;
197
+ }
198
+ return new URL(link);
199
+ }
200
+ }
173
201
  /* NOT FOR BROWSER */
174
202
  cloneNode() {
175
203
  const cloned = this.cloneChildNodes();
@@ -193,36 +221,30 @@ let MagicLinkToken = (() => {
193
221
  }
194
222
  return super.insertAt(token, i);
195
223
  }
196
- /** 获取网址 */
197
- getUrl() {
198
- const { type, protocol } = this;
199
- let { link } = this;
200
- if (type === 'magic-link') {
201
- if (protocol === 'ISBN') {
202
- return this.normalizeTitle(`Special:BookSources/${link.slice(5)}`).getUrl();
203
- }
204
- link = protocol === 'RFC'
205
- ? `https://tools.ietf.org/html/rfc${link.slice(4)}`
206
- : `https://pubmed.ncbi.nlm.nih.gov/${link.slice(5)}`;
207
- }
208
- else if (protocol === '//') {
209
- link = `https:${link}`;
210
- }
211
- return new URL(link);
212
- }
213
224
  /**
225
+ * Set the target of the link
226
+ *
214
227
  * 设置外链目标
215
- * @param url 含协议的网址
228
+ * @param url URL containing the protocol / 含协议的网址
216
229
  */
217
230
  setTarget(url) {
218
- const { childNodes } = index_1.default.parse(url, this.getAttribute('include'), 2, this.getAttribute('config'));
231
+ const { childNodes } = index_1.default
232
+ .parse(url, this.getAttribute('include'), 2, this.getAttribute('config'));
219
233
  this.replaceChildren(...childNodes);
220
234
  }
221
- /** 是否是模板或魔术字参数 */
235
+ /**
236
+ * Check if it is a parameter of a template or magic word
237
+ *
238
+ * 是否是模板或魔术字参数
239
+ */
222
240
  isParamValue() {
223
241
  return this.closest('parameter')?.getValue() === this.text();
224
242
  }
225
- /** 转义 `=` */
243
+ /**
244
+ * Escape `=`
245
+ *
246
+ * 转义 `=`
247
+ */
226
248
  escape() {
227
249
  for (const child of this.childNodes) {
228
250
  if (child.type === 'text') {
@@ -238,9 +260,9 @@ let MagicLinkToken = (() => {
238
260
  url = this.getUrl();
239
261
  }
240
262
  catch { }
241
- return (0, html_1.font)(this, `<a${type === 'magic-link' && protocol === 'ISBN'
263
+ return `<a${type === 'magic-link' && protocol === 'ISBN'
242
264
  ? ''
243
- : ` rel="nofollow" class="external${type === 'free-ext-link' ? ' free' : ''}"`}${url === undefined ? '' : ` href="${typeof url === 'string' ? url : url.href}"`}>${innerText}</a>`);
265
+ : ` rel="nofollow" class="external${type === 'free-ext-link' ? ' free' : ''}"`}${url === undefined ? '' : ` href="${typeof url === 'string' ? url : url.href}"`}>${innerText}</a>`;
244
266
  }
245
267
  };
246
268
  return MagicLinkToken = _classThis;
@@ -6,8 +6,10 @@ import type { LintError } from '../base';
6
6
  import type { CommentToken, AttributesToken, IncludeToken, ArgToken, TranscludeToken } from '../internal';
7
7
  declare type Child = ExtToken | NoincludeToken | CommentToken | IncludeToken | ArgToken | TranscludeToken;
8
8
  /**
9
+ * extension tag that has a nested structure
10
+ *
9
11
  * 嵌套式的扩展标签
10
- * @classdesc `{childNodes: ...ExtToken|NoincludeToken|CommentToken}`
12
+ * @classdesc `{childNodes: (ExtToken|NoincludeToken|CommentToken)[]}`
11
13
  */
12
14
  export declare abstract class NestedToken extends Token {
13
15
  #private;
@@ -32,8 +34,8 @@ export declare abstract class NestedToken extends Token {
32
34
  constructor(wikitext: string | undefined, regex: RegExp | boolean, tags: readonly string[], config?: Parser.Config, accum?: Token[]);
33
35
  /**
34
36
  * @override
35
- * @param token 待插入的子节点
36
- * @param i 插入位置
37
+ * @param token node to be inserted / 待插入的子节点
38
+ * @param i position to be inseted at / 插入位置
37
39
  */
38
40
  insertAt<T extends Token>(token: T, i?: number): T;
39
41
  cloneNode(): this;
@@ -14,8 +14,10 @@ const debug_1 = require("../util/debug");
14
14
  const constants_1 = require("../util/constants");
15
15
  const childTypes = new Set(['comment', 'include', 'arg', 'template', 'magic-word']);
16
16
  /**
17
+ * extension tag that has a nested structure
18
+ *
17
19
  * 嵌套式的扩展标签
18
- * @classdesc `{childNodes: ...ExtToken|NoincludeToken|CommentToken}`
20
+ * @classdesc `{childNodes: (ExtToken|NoincludeToken|CommentToken)[]}`
19
21
  */
20
22
  class NestedToken extends index_2.Token {
21
23
  #tags;
@@ -64,10 +66,11 @@ class NestedToken extends index_2.Token {
64
66
  return [
65
67
  ...super.lint(start, re),
66
68
  ...this.childNodes.filter(child => {
67
- if (child.type === 'ext') {
68
- return !this.#tags.includes(child.name);
69
+ const { type, name } = child;
70
+ if (type === 'ext') {
71
+ return !this.#tags.includes(name);
69
72
  }
70
- else if (childTypes.has(child.type)) {
73
+ else if (childTypes.has(type)) {
71
74
  return false;
72
75
  }
73
76
  const str = child.toString().trim();
@@ -85,8 +88,8 @@ class NestedToken extends index_2.Token {
85
88
  /* NOT FOR BROWSER */
86
89
  /**
87
90
  * @override
88
- * @param token 待插入的子节点
89
- * @param i 插入位置
91
+ * @param token node to be inserted / 待插入的子节点
92
+ * @param i position to be inseted at / 插入位置
90
93
  */
91
94
  insertAt(token, i) {
92
95
  if (!debug_1.Shadow.running && token.type === 'ext' && !this.#tags.includes(token.name)) {
@@ -3,6 +3,8 @@ import type { Config } from '../../base';
3
3
  import type { AstText } from '../../lib/text';
4
4
  declare type NowikiTypes = 'ext-inner' | 'comment' | 'dd' | 'double-underscore' | 'hr' | 'list' | 'noinclude' | 'quote';
5
5
  /**
6
+ * text-only token that will not be parsed
7
+ *
6
8
  * 纯文字Token,不会被解析
7
9
  * @classdesc `{childNodes: [AstText]}`
8
10
  */
@@ -14,14 +16,14 @@ export declare abstract class NowikiBaseToken extends Token {
14
16
  abstract get children(): [];
15
17
  abstract get firstElementChild(): undefined;
16
18
  abstract get lastElementChild(): undefined;
17
- /** 纯文本部分 */
19
+ /** text content / 纯文本部分 */
18
20
  get innerText(): string;
19
21
  /** @param wikitext default: `''` */
20
22
  constructor(wikitext?: string, config?: Config, accum?: Token[]);
21
23
  cloneNode(): this;
22
24
  /**
23
25
  * @override
24
- * @param str 新文本
26
+ * @param str new text / 新文本
25
27
  */
26
28
  setText(str: string): string;
27
29
  }
@@ -41,6 +41,8 @@ const debug_1 = require("../../util/debug");
41
41
  const constants_1 = require("../../util/constants");
42
42
  const fixed_1 = require("../../mixin/fixed");
43
43
  /**
44
+ * text-only token that will not be parsed
45
+ *
44
46
  * 纯文字Token,不会被解析
45
47
  * @classdesc `{childNodes: [AstText]}`
46
48
  */
@@ -60,7 +62,7 @@ let NowikiBaseToken = (() => {
60
62
  __runInitializers(_classThis, _classExtraInitializers);
61
63
  }
62
64
  /* NOT FOR BROWSER END */
63
- /** 纯文本部分 */
65
+ /** text content / 纯文本部分 */
64
66
  get innerText() {
65
67
  return this.firstChild.data;
66
68
  }
@@ -70,15 +72,14 @@ let NowikiBaseToken = (() => {
70
72
  }
71
73
  /* NOT FOR BROWSER */
72
74
  cloneNode() {
73
- const { firstChild: { data } } = this;
74
75
  return debug_1.Shadow.run(() => {
75
- const C = this.constructor, token = new C(data, this.getAttribute('config'));
76
- return token;
76
+ const C = this.constructor;
77
+ return new C(this.innerText, this.getAttribute('config'));
77
78
  });
78
79
  }
79
80
  /**
80
81
  * @override
81
- * @param str 新文本
82
+ * @param str new text / 新文本
82
83
  */
83
84
  setText(str) {
84
85
  return super.setText(str);
@@ -1,11 +1,15 @@
1
1
  import { NowikiBaseToken } from './base';
2
2
  import type { LintError, Config } from '../../base';
3
3
  import type { Token } from '../index';
4
- /** HTML注释,不可见 */
4
+ /**
5
+ * invisible HTML comment
6
+ *
7
+ * HTML注释,不可见
8
+ */
5
9
  export declare abstract class CommentToken extends NowikiBaseToken {
6
10
  closed: boolean;
7
11
  get type(): 'comment';
8
- /** 内部文本 */
12
+ /** comment content / 内部文本 */
9
13
  get innerText(): string;
10
14
  set innerText(text: string);
11
15
  /** @param closed 是否闭合 */
@@ -43,7 +43,11 @@ const base_1 = require("./base");
43
43
  const debug_1 = require("../../util/debug");
44
44
  const constants_1 = require("../../util/constants");
45
45
  /* NOT FOR BROWSER END */
46
- /** HTML注释,不可见 */
46
+ /**
47
+ * invisible HTML comment
48
+ *
49
+ * HTML注释,不可见
50
+ */
47
51
  let CommentToken = (() => {
48
52
  let _classDecorators = [(0, hidden_1.hiddenToken)(false)];
49
53
  let _classDescriptor;
@@ -64,7 +68,7 @@ let CommentToken = (() => {
64
68
  return 'comment';
65
69
  }
66
70
  /* NOT FOR BROWSER */
67
- /** 内部文本 */
71
+ /** comment content / 内部文本 */
68
72
  get innerText() {
69
73
  return super.innerText;
70
74
  }
@@ -106,8 +110,9 @@ let CommentToken = (() => {
106
110
  }
107
111
  /* NOT FOR BROWSER */
108
112
  cloneNode() {
113
+ return debug_1.Shadow.run(
109
114
  // @ts-expect-error abstract class
110
- return debug_1.Shadow.run(() => new CommentToken(this.innerText, this.closed, this.getAttribute('config')));
115
+ () => new CommentToken(this.innerText, this.closed, this.getAttribute('config')));
111
116
  }
112
117
  /** @private */
113
118
  setText(text) {
@@ -2,7 +2,4 @@ import { ListBaseToken } from './listBase';
2
2
  /** `:` */
3
3
  export declare abstract class DdToken extends ListBaseToken {
4
4
  get type(): 'dd';
5
- /** 缩进数 */
6
- get indent(): number;
7
- set indent(indent: number);
8
5
  }
@@ -59,14 +59,6 @@ let DdToken = (() => {
59
59
  get type() {
60
60
  return 'dd';
61
61
  }
62
- /* NOT FOR BROWSER */
63
- /** 缩进数 */
64
- get indent() {
65
- return this.innerText.length;
66
- }
67
- set indent(indent) {
68
- this.setText(':'.repeat(indent));
69
- }
70
62
  };
71
63
  return DdToken = _classThis;
72
64
  })();
@@ -1,7 +1,11 @@
1
1
  import Parser from '../../index';
2
2
  import { NowikiBaseToken } from './base';
3
3
  import type { Token } from '../index';
4
- /** 状态开关 */
4
+ /**
5
+ * behavior switch
6
+ *
7
+ * 状态开关
8
+ */
5
9
  export declare abstract class DoubleUnderscoreToken extends NowikiBaseToken {
6
10
  #private;
7
11
  readonly name: string;
@@ -43,7 +43,11 @@ const debug_1 = require("../../util/debug");
43
43
  const constants_1 = require("../../util/constants");
44
44
  const syntax_1 = require("../../mixin/syntax");
45
45
  /* NOT FOR BROWSER END */
46
- /** 状态开关 */
46
+ /**
47
+ * behavior switch
48
+ *
49
+ * 状态开关
50
+ */
47
51
  let DoubleUnderscoreToken = (() => {
48
52
  let _classDecorators = [(0, syntax_1.syntax)(), (0, hidden_1.hiddenToken)()];
49
53
  let _classDescriptor;
@@ -1,7 +1,11 @@
1
1
  import { NowikiBaseToken } from './base';
2
2
  import type { LintError } from '../../base';
3
3
  import type { AttributesToken, ExtToken } from '../../internal';
4
- /** 扩展标签内的纯文字Token */
4
+ /**
5
+ * text-only token inside an extension tag
6
+ *
7
+ * 扩展标签内的纯文字Token
8
+ */
5
9
  export declare abstract class NowikiToken extends NowikiBaseToken {
6
10
  readonly name: string;
7
11
  abstract get nextSibling(): undefined;
@@ -7,7 +7,11 @@ const base_1 = require("./base");
7
7
  /* NOT FOR BROWSER */
8
8
  const constants_1 = require("../../util/constants");
9
9
  /* NOT FOR BROWSER END */
10
- /** 扩展标签内的纯文字Token */
10
+ /**
11
+ * text-only token inside an extension tag
12
+ *
13
+ * 扩展标签内的纯文字Token
14
+ */
11
15
  class NowikiToken extends base_1.NowikiBaseToken {
12
16
  /* NOT FOR BROWSER END */
13
17
  get type() {
@@ -1,5 +1,9 @@
1
1
  import { ListBaseToken } from './listBase';
2
- /** 位于行首的`;:*#` */
2
+ /**
3
+ * `;:*#` at the start of a line
4
+ *
5
+ * 位于行首的`;:*#`
6
+ */
3
7
  export declare abstract class ListToken extends ListBaseToken {
4
8
  get type(): 'list';
5
9
  }
@@ -41,7 +41,11 @@ const constants_1 = require("../../util/constants");
41
41
  const sol_1 = require("../../mixin/sol");
42
42
  const syntax_1 = require("../../mixin/syntax");
43
43
  /* NOT FOR BROWSER END */
44
- /** 位于行首的`;:*#` */
44
+ /**
45
+ * `;:*#` at the start of a line
46
+ *
47
+ * 位于行首的`;:*#`
48
+ */
45
49
  let ListToken = (() => {
46
50
  let _classDecorators = [(0, sol_1.sol)(true), (0, syntax_1.syntax)(/^[;:*#]+[^\S\n]*$/u)];
47
51
  let _classDescriptor;
@@ -1,4 +1,5 @@
1
1
  import { NowikiBaseToken } from './base';
2
+ import type { AST } from '../../base';
2
3
  import { Token } from '../index';
3
4
  import type { DdToken, ListToken, AstText } from '../../internal';
4
5
  export interface ListRangeToken extends Token {
@@ -10,14 +11,23 @@ export interface ListRangeToken extends Token {
10
11
  /** `;:*#` */
11
12
  export declare abstract class ListBaseToken extends NowikiBaseToken {
12
13
  abstract get type(): 'dd' | 'list';
13
- /** 是否包含`:` */
14
+ /** number of indentation / 缩进数 */
15
+ get indent(): number;
16
+ /** @throws `Error` not `<dd>` only */
17
+ set indent(indent: number);
18
+ /** whether to contain `:` / 是否包含`:` */
14
19
  get dd(): boolean;
15
- /** 是否包含`;` */
20
+ /** whether to contain `;` / 是否包含`;` */
16
21
  get dt(): boolean;
17
- /** 是否包含`*` */
22
+ /** whether to contain `*` / 是否包含`*` */
18
23
  get ul(): boolean;
19
- /** 是否包含`#` */
24
+ /** whether to contain `#` / 是否包含`#` */
20
25
  get ol(): boolean;
21
- /** 获取列表行的范围 */
26
+ /**
27
+ * Get the range of the list
28
+ *
29
+ * 获取列表行的范围
30
+ * @throws `Error` 不存在父节点
31
+ */
22
32
  getRange(): ListRangeToken;
23
33
  }
@@ -9,27 +9,59 @@ const index_1 = require("../index");
9
9
  /* NOT FOR BROWSER END */
10
10
  /** `;:*#` */
11
11
  class ListBaseToken extends base_1.NowikiBaseToken {
12
+ /* PRINT ONLY */
13
+ /** number of indentation / 缩进数 */
14
+ get indent() {
15
+ return this.innerText.split(':').length - 1;
16
+ }
17
+ /* PRINT ONLY END */
12
18
  /* NOT FOR BROWSER */
13
- /** 是否包含`:` */
19
+ /** @throws `Error` not `<dd>` only */
20
+ set indent(indent) {
21
+ if (/[^:]/u.test(this.innerText)) {
22
+ throw new Error('The token is not <dd>!');
23
+ }
24
+ this.setText(':'.repeat(indent));
25
+ }
26
+ /** whether to contain `:` / 是否包含`:` */
14
27
  get dd() {
15
28
  return this.innerText.includes(':');
16
29
  }
17
- /** 是否包含`;` */
30
+ /** whether to contain `;` / 是否包含`;` */
18
31
  get dt() {
19
32
  return this.innerText.includes(';');
20
33
  }
21
- /** 是否包含`*` */
34
+ /** whether to contain `*` / 是否包含`*` */
22
35
  get ul() {
23
36
  return this.innerText.includes('*');
24
37
  }
25
- /** 是否包含`#` */
38
+ /** whether to contain `#` / 是否包含`#` */
26
39
  get ol() {
27
40
  return this.innerText.includes('#');
28
41
  }
29
- /** 获取列表行的范围 */
42
+ /* NOT FOR BROWSER END */
43
+ /** @private */
44
+ json(_, start = this.getAbsoluteIndex()) {
45
+ const json = super.json(undefined, start), { indent } = this;
46
+ if (indent) {
47
+ json['indent'] = indent;
48
+ }
49
+ return json;
50
+ }
51
+ /* NOT FOR BROWSER */
52
+ /**
53
+ * Get the range of the list
54
+ *
55
+ * 获取列表行的范围
56
+ * @throws `Error` 不存在父节点
57
+ */
30
58
  getRange() {
59
+ const { parentNode } = this;
60
+ if (!parentNode) {
61
+ throw new Error('There is no parent node!');
62
+ }
31
63
  let { nextSibling } = this;
32
- if (nextSibling?.type === 'list-range') {
64
+ if (nextSibling?.is('list-range')) {
33
65
  return nextSibling;
34
66
  }
35
67
  const { dt, type } = this;
@@ -57,7 +89,6 @@ class ListBaseToken extends base_1.NowikiBaseToken {
57
89
  range.setEndBefore(nextSibling);
58
90
  }
59
91
  else {
60
- const { parentNode } = this;
61
92
  if (type === 'list') {
62
93
  while (this.previousSibling?.is('list')) {
63
94
  this.setText(this.previousSibling.innerText + this.innerText);
@@ -68,7 +99,7 @@ class ListBaseToken extends base_1.NowikiBaseToken {
68
99
  this.setText(this.innerText + token.innerText);
69
100
  token.remove();
70
101
  }
71
- if (parentNode?.is('list-range')) {
102
+ if (parentNode.is('list-range')) {
72
103
  parentNode.previousSibling.setText(parentNode.previousSibling.innerText + this.innerText);
73
104
  this.remove();
74
105
  return parentNode;
@@ -87,8 +118,8 @@ class ListBaseToken extends base_1.NowikiBaseToken {
87
118
  t.type = 'list-range';
88
119
  return t;
89
120
  });
90
- token.append(...range.extractContents());
91
- range.insertNode(token);
121
+ token.concat(range.extractContents()); // eslint-disable-line unicorn/prefer-spread
122
+ (0, debug_1.setChildNodes)(parentNode, parentNode.childNodes.indexOf(this) + 1, 0, [token]);
92
123
  return token;
93
124
  }
94
125
  /** @private */
@@ -1,5 +1,9 @@
1
1
  import { NowikiBaseToken } from './base';
2
- /** `<noinclude>`和`</noinclude>`,不可进行任何更改 */
2
+ /**
3
+ * `<noinclude>` or `</noinclude>` that allows no modification
4
+ *
5
+ * `<noinclude>`或`</noinclude>`,不可进行任何更改
6
+ */
3
7
  export declare abstract class NoincludeToken extends NowikiBaseToken {
4
8
  get type(): 'noinclude';
5
9
  setText(str: string): string;
@@ -40,7 +40,11 @@ const base_1 = require("./base");
40
40
  /* NOT FOR BROWSER */
41
41
  const constants_1 = require("../../util/constants");
42
42
  /* NOT FOR BROWSER END */
43
- /** `<noinclude>`和`</noinclude>`,不可进行任何更改 */
43
+ /**
44
+ * `<noinclude>` or `</noinclude>` that allows no modification
45
+ *
46
+ * `<noinclude>`或`</noinclude>`,不可进行任何更改
47
+ */
44
48
  let NoincludeToken = (() => {
45
49
  let _classDecorators = [(0, hidden_1.hiddenToken)()];
46
50
  let _classDescriptor;
@@ -1,14 +1,21 @@
1
1
  import { NowikiBaseToken } from './base';
2
- import type { LintError, AST } from '../../base';
3
- /** `''`和`'''` */
2
+ import type { LintError, AST, Config } from '../../base';
3
+ import type { Font } from '../../lib/node';
4
+ import type { Token } from '../index';
5
+ /**
6
+ * `''` and `'''`
7
+ *
8
+ * `''`和`'''`
9
+ */
4
10
  export declare abstract class QuoteToken extends NowikiBaseToken {
11
+ #private;
5
12
  get type(): 'quote';
6
13
  get bold(): boolean;
7
14
  get italic(): boolean;
8
- get font(): {
9
- bold: boolean;
10
- italic: boolean;
11
- };
12
- /** @override */
13
- json(): AST;
15
+ get font(): Font;
16
+ /** whether to be closing quotes / 是否闭合 */
17
+ get closing(): Partial<Font>;
18
+ /** @param closing 是否闭合 */
19
+ constructor(wikitext: string, closing: Font, config?: Config, accum?: Token[]);
20
+ cloneNode(): this;
14
21
  }