wikiparser-node 1.9.3 → 1.10.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 (82) hide show
  1. package/config/.schema.json +5 -0
  2. package/config/enwiki.json +2 -1
  3. package/config/llwiki.json +2 -1
  4. package/config/moegirl.json +2 -1
  5. package/config/zhwiki.json +2 -1
  6. package/dist/addon/token.js +282 -198
  7. package/dist/addon/transclude.js +7 -7
  8. package/dist/base.d.ts +3 -1
  9. package/dist/index.d.ts +2 -0
  10. package/dist/index.js +4 -4
  11. package/dist/lib/element.js +2 -2
  12. package/dist/lib/node.d.ts +6 -1
  13. package/dist/lib/node.js +10 -4
  14. package/dist/lib/text.d.ts +5 -2
  15. package/dist/lib/text.js +15 -5
  16. package/dist/lib/title.d.ts +2 -0
  17. package/dist/lib/title.js +8 -0
  18. package/dist/mixin/attributesParent.js +0 -3
  19. package/dist/mixin/hidden.d.ts +1 -0
  20. package/dist/mixin/hidden.js +5 -2
  21. package/dist/mixin/singleLine.js +2 -4
  22. package/dist/mixin/sol.d.ts +1 -0
  23. package/dist/mixin/sol.js +7 -7
  24. package/dist/mixin/syntax.js +0 -2
  25. package/dist/parser/list.js +8 -6
  26. package/dist/parser/selector.js +2 -1
  27. package/dist/parser/table.js +2 -2
  28. package/dist/src/arg.js +3 -3
  29. package/dist/src/attribute.js +25 -28
  30. package/dist/src/attributes.d.ts +0 -1
  31. package/dist/src/attributes.js +34 -7
  32. package/dist/src/converter.d.ts +2 -2
  33. package/dist/src/converter.js +13 -3
  34. package/dist/src/converterFlags.js +2 -2
  35. package/dist/src/converterRule.js +17 -13
  36. package/dist/src/extLink.js +7 -3
  37. package/dist/src/gallery.js +2 -2
  38. package/dist/src/heading.js +9 -4
  39. package/dist/src/hidden.js +1 -1
  40. package/dist/src/html.js +10 -2
  41. package/dist/src/imageParameter.js +2 -2
  42. package/dist/src/imagemap.js +2 -2
  43. package/dist/src/index.d.ts +11 -1
  44. package/dist/src/index.js +61 -12
  45. package/dist/src/link/base.d.ts +9 -0
  46. package/dist/src/link/base.js +48 -11
  47. package/dist/src/link/file.js +1 -1
  48. package/dist/src/link/index.d.ts +0 -12
  49. package/dist/src/link/index.js +8 -45
  50. package/dist/src/link/redirectTarget.d.ts +3 -12
  51. package/dist/src/link/redirectTarget.js +5 -31
  52. package/dist/src/magicLink.d.ts +3 -2
  53. package/dist/src/magicLink.js +45 -57
  54. package/dist/src/nowiki/base.js +1 -1
  55. package/dist/src/nowiki/comment.js +3 -3
  56. package/dist/src/nowiki/dd.js +64 -18
  57. package/dist/src/nowiki/doubleUnderscore.js +1 -1
  58. package/dist/src/nowiki/hr.js +6 -1
  59. package/dist/src/nowiki/list.d.ts +0 -11
  60. package/dist/src/nowiki/list.js +2 -48
  61. package/dist/src/nowiki/listBase.d.ts +12 -0
  62. package/dist/src/nowiki/listBase.js +67 -53
  63. package/dist/src/nowiki/noinclude.js +5 -1
  64. package/dist/src/nowiki/quote.js +5 -0
  65. package/dist/src/onlyinclude.js +2 -2
  66. package/dist/src/paramTag/index.js +2 -2
  67. package/dist/src/parameter.js +20 -13
  68. package/dist/src/redirect.js +7 -3
  69. package/dist/src/syntax.d.ts +1 -1
  70. package/dist/src/syntax.js +2 -2
  71. package/dist/src/table/index.js +11 -1
  72. package/dist/src/table/td.js +8 -2
  73. package/dist/src/table/trBase.js +15 -7
  74. package/dist/src/tagPair/ext.js +16 -0
  75. package/dist/src/tagPair/include.js +5 -1
  76. package/dist/src/tagPair/index.js +3 -3
  77. package/dist/src/transclude.js +20 -15
  78. package/dist/util/lint.js +1 -1
  79. package/dist/util/string.js +25 -1
  80. package/errors/README +2 -0
  81. package/package.json +1 -1
  82. package/printed/README +2 -0
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LinkToken = void 0;
4
4
  const lint_1 = require("../../util/lint");
5
5
  const constants_1 = require("../../util/constants");
6
+ const string_1 = require("../../util/string");
6
7
  const base_1 = require("./base");
7
8
  /**
8
9
  * 内链
@@ -31,24 +32,6 @@ class LinkToken extends base_1.LinkBaseToken {
31
32
  this.asSelfLink();
32
33
  }
33
34
  }
34
- get fragment() {
35
- return super.fragment;
36
- }
37
- set fragment(fragment) {
38
- this.#setFragment(fragment);
39
- }
40
- /** interwiki */
41
- get interwiki() {
42
- return this.link.interwiki;
43
- }
44
- /** @throws `RangeError` 非法的跨维基前缀 */
45
- set interwiki(interwiki) {
46
- const { link: { prefix, main, fragment } } = this, link = `${interwiki}:${prefix}${main}${fragment === undefined ? '' : `#${fragment}`}`;
47
- if (interwiki && !this.isInterwiki(link)) {
48
- throw new RangeError(`${interwiki} is not a valid interwiki prefix!`);
49
- }
50
- this.setTarget(link);
51
- }
52
35
  /* NOT FOR BROWSER END */
53
36
  /** @private */
54
37
  lint(start = this.getAbsoluteIndex(), re) {
@@ -59,10 +42,6 @@ class LinkToken extends base_1.LinkBaseToken {
59
42
  return errors;
60
43
  }
61
44
  /* NOT FOR BROWSER */
62
- /** @private */
63
- setTarget(link) {
64
- super.setTarget((/^\s*[:#]/u.test(link) ? '' : ':') + link);
65
- }
66
45
  /**
67
46
  * 设置跨语言链接
68
47
  * @param lang 语言前缀
@@ -76,22 +55,6 @@ class LinkToken extends base_1.LinkBaseToken {
76
55
  }
77
56
  super.setTarget(lang + (link.startsWith(':') ? '' : ':') + link);
78
57
  }
79
- /**
80
- * 设置fragment
81
- * @param fragment fragment
82
- * @param page 是否是其他页面
83
- */
84
- #setFragment(fragment, page = true) {
85
- fragment &&= fragment.replace(/[<>[\]#|=]/gu, p => encodeURIComponent(p));
86
- this.setTarget(`${page ? this.name : ''}${fragment === undefined ? '' : `#${fragment}`}`);
87
- }
88
- /**
89
- * 设置fragment
90
- * @param fragment fragment
91
- */
92
- setFragment(fragment) {
93
- this.#setFragment(fragment);
94
- }
95
58
  /**
96
59
  * 修改为到自身的链接
97
60
  * @param fragment fragment
@@ -101,7 +64,7 @@ class LinkToken extends base_1.LinkBaseToken {
101
64
  if (!fragment?.trim()) {
102
65
  throw new RangeError('LinkToken.asSelfLink method must specify a non-empty fragment!');
103
66
  }
104
- this.#setFragment(fragment, false);
67
+ this.setTarget(`#${(0, string_1.encode)(fragment)}`);
105
68
  }
106
69
  /**
107
70
  * 自动生成管道符后的链接文字
@@ -112,21 +75,21 @@ class LinkToken extends base_1.LinkBaseToken {
112
75
  if (linkText.includes('#') || linkText.includes('%')) {
113
76
  throw new Error('Pipe trick cannot be used with "#" or "%"!');
114
77
  }
115
- const m1 = /^:?(?:[ \w\x80-\xFF-]+:)?([^(]+)\(.+\)$/u.exec(linkText);
78
+ const m1 = /^:?(?:[ \w\x80-\xFF-]+:)?([^(]+?) ?\(.+\)$/u.exec(linkText);
116
79
  if (m1) {
117
- this.setLinkText(m1[1].trim());
80
+ this.setLinkText(m1[1]);
118
81
  return;
119
82
  }
120
- const m2 = /^:?(?:[ \w\x80-\xFF-]+:)?([^(]+)(.+)$/u.exec(linkText);
83
+ const m2 = /^:?(?:[ \w\x80-\xFF-]+:)?([^(]+?) ?(.+)$/u.exec(linkText);
121
84
  if (m2) {
122
- this.setLinkText(m2[1].trim());
85
+ this.setLinkText(m2[1]);
123
86
  return;
124
87
  }
125
88
  // eslint-disable-next-line es-x/no-regexp-lookbehind-assertions
126
- const m3 = /^:?(?:[ \w\x80-\xFF-]+:)?(.+?)(?:(?<!\()\(.+\))?(?:, |,|، )./u
89
+ const m3 = /^:?(?:[ \w\x80-\xFF-]+:)?(.+?)(?: ?(?<!\()\(.+\))?(?:(?:, |,|، ).|$)/u
127
90
  .exec(linkText);
128
91
  if (m3) {
129
- this.setLinkText(m3[1].trim());
92
+ this.setLinkText(m3[1]);
130
93
  return;
131
94
  }
132
95
  this.setLinkText(linkText);
@@ -6,7 +6,7 @@ import type { Title } from '../../lib/title';
6
6
  import type { Token, AtomToken } from '../../internal';
7
7
  /**
8
8
  * 重定向目标
9
- * @classdesc `{childNodes: [AtomToken, ?Token]}`
9
+ * @classdesc `{childNodes: [AtomToken, ?NoincludeToken]}`
10
10
  */
11
11
  export declare abstract class RedirectTargetToken extends LinkBaseToken {
12
12
  readonly childNodes: readonly [AtomToken] | readonly [AtomToken, NoincludeToken];
@@ -16,21 +16,12 @@ export declare abstract class RedirectTargetToken extends LinkBaseToken {
16
16
  abstract get link(): Title;
17
17
  abstract set link(link: string);
18
18
  get type(): 'redirect-target';
19
- get fragment(): string | undefined;
20
- set fragment(fragment: string | undefined);
21
- /** interwiki */
22
- get interwiki(): string;
23
- /** @throws `RangeError` 非法的跨维基前缀 */
24
- set interwiki(interwiki: string);
19
+ /** 链接显示文字 */
20
+ get innerText(): string;
25
21
  /**
26
22
  * @param link 链接标题
27
23
  * @param linkText 链接显示文字
28
24
  * @param delimiter `|`
29
25
  */
30
26
  constructor(link: string, linkText?: string, config?: Parser.Config, accum?: Token[]);
31
- /**
32
- * 设置fragment
33
- * @param fragment fragment
34
- */
35
- setFragment(fragment?: string): void;
36
27
  }
@@ -8,7 +8,7 @@ const base_1 = require("./base");
8
8
  const noinclude_1 = require("../nowiki/noinclude");
9
9
  /**
10
10
  * 重定向目标
11
- * @classdesc `{childNodes: [AtomToken, ?Token]}`
11
+ * @classdesc `{childNodes: [AtomToken, ?NoincludeToken]}`
12
12
  */
13
13
  class RedirectTargetToken extends base_1.LinkBaseToken {
14
14
  /* NOT FOR BROWSER END */
@@ -16,23 +16,9 @@ class RedirectTargetToken extends base_1.LinkBaseToken {
16
16
  return 'redirect-target';
17
17
  }
18
18
  /* NOT FOR BROWSER */
19
- get fragment() {
20
- return super.fragment;
21
- }
22
- set fragment(fragment) {
23
- this.setFragment(fragment);
24
- }
25
- /** interwiki */
26
- get interwiki() {
27
- return this.link.interwiki;
28
- }
29
- /** @throws `RangeError` 非法的跨维基前缀 */
30
- set interwiki(interwiki) {
31
- const { link: { prefix, main, fragment } } = this, link = `${interwiki}:${prefix}${main}${fragment === undefined ? '' : `#${fragment}`}`;
32
- if (interwiki && !this.isInterwiki(link)) {
33
- throw new RangeError(`${interwiki} is not a valid interwiki prefix!`);
34
- }
35
- this.setTarget(link);
19
+ /** 链接显示文字 */
20
+ get innerText() {
21
+ return String(this.link);
36
22
  }
37
23
  /* NOT FOR BROWSER END */
38
24
  /**
@@ -56,12 +42,8 @@ class RedirectTargetToken extends base_1.LinkBaseToken {
56
42
  return this.normalizeTitle(this.firstChild.toString(), 0, true, true);
57
43
  }
58
44
  /** @private */
59
- text() {
60
- return `[[${this.firstChild.toString()}]]`;
61
- }
62
- /** @private */
63
45
  lint(start = this.getAbsoluteIndex()) {
64
- const errors = super.lint(start, /\]\]/u);
46
+ const errors = super.lint(start, false);
65
47
  if (this.length === 2) {
66
48
  const e = (0, lint_1.generateForChild)(this.lastChild, { start }, 'no-ignored', 'useless link text');
67
49
  e.startIndex--;
@@ -79,14 +61,6 @@ class RedirectTargetToken extends base_1.LinkBaseToken {
79
61
  setTarget(link) {
80
62
  this.firstChild.setText(link);
81
63
  }
82
- /**
83
- * 设置fragment
84
- * @param fragment fragment
85
- */
86
- setFragment(fragment) {
87
- fragment &&= fragment.replace(/[\]|]/gu, p => encodeURIComponent(p));
88
- this.setTarget(`${this.name}${fragment === undefined ? '' : `#${fragment}`}`);
89
- }
90
64
  /** @private */
91
65
  setLinkText(linkStr) {
92
66
  if (!linkStr) {
@@ -21,6 +21,8 @@ export declare abstract class MagicLinkToken extends Token {
21
21
  abstract get firstElementChild(): CommentToken | IncludeToken | NoincludeToken | TranscludeToken | undefined;
22
22
  abstract get lastElementChild(): CommentToken | IncludeToken | NoincludeToken | TranscludeToken | undefined;
23
23
  get type(): ExtLinkTypes;
24
+ /** 链接显示文字 */
25
+ get innerText(): string;
24
26
  /** 和内链保持一致 */
25
27
  get link(): string;
26
28
  set link(url: string);
@@ -43,10 +45,9 @@ export declare abstract class MagicLinkToken extends Token {
43
45
  insertAt<T extends AstNodes>(token: T, i?: number): T;
44
46
  /**
45
47
  * 获取网址
46
- * @throws `Error` ISBN
47
48
  * @throws `Error` 非标准协议
48
49
  */
49
- getUrl(): URL;
50
+ getUrl(): URL | string;
50
51
  /**
51
52
  * 设置外链目标
52
53
  * @param url 含协议的网址
@@ -76,21 +76,26 @@ let MagicLinkToken = (() => {
76
76
  get type() {
77
77
  return this.#type;
78
78
  }
79
- /** 和内链保持一致 */
80
- get link() {
81
- const map = { '!': '|', '=': '=' };
79
+ /** 链接显示文字 */
80
+ get innerText() {
81
+ const map = new Map([['!', '|'], ['=', '=']]);
82
82
  let link = (0, string_1.text)(this.childNodes.map(child => {
83
- const { type, name } = child;
84
- return type === 'magic-word' && String(name) in map ? map[name] : child;
83
+ const { type } = child, name = String(child.name);
84
+ return type === 'magic-word' && map.has(name) ? map.get(name) : child;
85
85
  }));
86
86
  if (this.type === 'magic-link') {
87
87
  link = link.replace(spaceRegex, ' ');
88
- if (link.startsWith('ISBN')) {
89
- link = `ISBN ${link.slice(5).replace(/[- ]/gu, '').replace(/x$/u, 'X')}`;
90
- }
91
88
  }
92
89
  return link;
93
90
  }
91
+ /** 和内链保持一致 */
92
+ get link() {
93
+ let { innerText } = this;
94
+ if (this.type === 'magic-link' && innerText.startsWith('ISBN')) {
95
+ innerText = `ISBN ${innerText.slice(5).replace(/[- ]/gu, '').replace(/x$/u, 'X')}`;
96
+ }
97
+ return innerText;
98
+ }
94
99
  /* NOT FOR BROWSER */
95
100
  set link(url) {
96
101
  this.setTarget(url);
@@ -145,53 +150,30 @@ let MagicLinkToken = (() => {
145
150
  }
146
151
  return errors;
147
152
  }
148
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
149
- /[,;。:!?()]+/gu;
150
- const pipe = this.type === 'ext-link-url', source = pipe ? String.raw `\|+` : '[,;。:!?()]+', regex = new RegExp(source, 'u'), regexGlobal = new RegExp(source, 'gu');
151
- for (const child of this.childNodes) {
152
- const { type, data } = child;
153
- if (type !== 'text' || !regex.test(data)) {
154
- continue;
155
- }
156
- const refError = (0, lint_1.generateForChild)(child, rect, 'unterminated-url', '', 'warning');
157
- regexGlobal.lastIndex = 0;
158
- for (let mt = regexGlobal.exec(data); mt; mt = regexGlobal.exec(data)) {
159
- const { index, 0: s } = mt, lines = data.slice(0, index).split('\n'), top = lines.length, left = lines[top - 1].length, startIndex = refError.startIndex + index, startLine = refError.startLine + top - 1, startCol = top === 1 ? refError.startCol + left : left;
160
- const e = {
161
- ...refError,
162
- message: index_1.default.msg('$1 in URL', pipe ? '"|"' : 'full-width punctuation'),
163
- startIndex,
164
- endIndex: startIndex + s.length,
165
- startLine,
166
- endLine: startLine,
167
- startCol,
168
- endCol: startCol + s.length,
169
- };
170
- if (!pipe) {
171
- e.suggestions = [
172
- {
173
- desc: 'whitespace',
174
- range: [startIndex, startIndex],
175
- text: ' ',
176
- },
177
- {
178
- desc: 'escape',
179
- range: [startIndex, e.endIndex],
180
- text: encodeURI(s),
181
- },
182
- ];
183
- }
184
- else if (s.length === 1) {
185
- e.suggestions = [
186
- {
187
- desc: 'whitespace',
188
- range: [startIndex, startIndex + 1],
189
- text: ' ',
190
- },
191
- ];
192
- }
193
- errors.push(e);
194
- }
153
+ const pipe = this.type === 'ext-link-url', regex = pipe ? /\|/u : /[,;。:!?()]+/u, child = this.childNodes.find((c) => c.type === 'text' && regex.test(c.data));
154
+ if (child) {
155
+ 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;
156
+ e.suggestions = pipe
157
+ ? [
158
+ {
159
+ desc: 'whitespace',
160
+ range: [i, i + 1],
161
+ text: ' ',
162
+ },
163
+ ]
164
+ : [
165
+ {
166
+ desc: 'whitespace',
167
+ range: [i, i],
168
+ text: ' ',
169
+ },
170
+ {
171
+ desc: 'escape',
172
+ range: [i, i + s.length],
173
+ text: encodeURI(s),
174
+ },
175
+ ];
176
+ errors.push(e);
195
177
  }
196
178
  return errors;
197
179
  }
@@ -219,7 +201,6 @@ let MagicLinkToken = (() => {
219
201
  }
220
202
  /**
221
203
  * 获取网址
222
- * @throws `Error` ISBN
223
204
  * @throws `Error` 非标准协议
224
205
  */
225
206
  getUrl() {
@@ -227,7 +208,7 @@ let MagicLinkToken = (() => {
227
208
  let { link } = this;
228
209
  if (type === 'magic-link') {
229
210
  if (protocol === 'ISBN') {
230
- throw new Error(`MagicLinkToken.getUrl method does not support ISBN links: ${link}`);
211
+ return this.normalizeTitle(`Special:BookSources/${link.slice(5)}`).getUrl();
231
212
  }
232
213
  link = protocol === 'RFC'
233
214
  ? `https://tools.ietf.org/html/rfc${link.slice(4)}`
@@ -266,6 +247,13 @@ let MagicLinkToken = (() => {
266
247
  }
267
248
  }
268
249
  }
250
+ /** @private */
251
+ toHtml() {
252
+ const url = this.getUrl(), { type, innerText, protocol } = this;
253
+ return `<a ${type === 'magic-link' && protocol === 'ISBN'
254
+ ? ''
255
+ : `class="external${type === 'free-ext-link' ? ' free' : ''}" rel="nofollow" `}href="${typeof url === 'string' ? url : url.href}">${innerText}</a>`;
256
+ }
269
257
  };
270
258
  return MagicLinkToken = _classThis;
271
259
  })();
@@ -80,7 +80,7 @@ let NowikiBaseToken = (() => {
80
80
  * @param str 新文本
81
81
  */
82
82
  setText(str) {
83
- return super.setText(str, 0);
83
+ return super.setText(str);
84
84
  }
85
85
  };
86
86
  return NowikiBaseToken = _classThis;
@@ -43,7 +43,7 @@ const index_1 = require("../../index");
43
43
  const base_1 = require("./base");
44
44
  /** HTML注释,不可见 */
45
45
  let CommentToken = (() => {
46
- let _classDecorators = [(0, hidden_1.hiddenToken)()];
46
+ let _classDecorators = [(0, hidden_1.hiddenToken)(false)];
47
47
  let _classDescriptor;
48
48
  let _classExtraInitializers = [];
49
49
  let _classThis;
@@ -92,14 +92,14 @@ let CommentToken = (() => {
92
92
  return [e];
93
93
  }
94
94
  /** @private */
95
- toString() {
95
+ toString(skip) {
96
96
  /* NOT FOR BROWSER */
97
97
  if (!this.closed && this.nextSibling) {
98
98
  index_1.default.error('Auto-closing HTML comment', this);
99
99
  this.closed = true;
100
100
  }
101
101
  /* NOT FOR BROWSER END */
102
- return `<!--${this.innerText}${this.closed ? '-->' : ''}`;
102
+ return skip ? '' : `<!--${this.innerText}${this.closed ? '-->' : ''}`;
103
103
  }
104
104
  /** @private */
105
105
  print() {
@@ -1,26 +1,72 @@
1
1
  "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
2
36
  Object.defineProperty(exports, "__esModule", { value: true });
3
37
  exports.DdToken = void 0;
4
38
  const constants_1 = require("../../util/constants");
39
+ const syntax_1 = require("../../mixin/syntax");
5
40
  const listBase_1 = require("./listBase");
6
41
  /** `:` */
7
- class DdToken extends listBase_1.ListBaseToken {
8
- get type() {
9
- return 'dd';
10
- }
11
- /* NOT FOR BROWSER */
12
- /** 缩进数 */
13
- get indent() {
14
- return this.innerText.length;
15
- }
16
- set indent(indent) {
17
- this.setText(':'.repeat(indent));
18
- }
19
- /** @private */
20
- afterBuild() {
21
- this.setAttribute('pattern', /^:+$/u);
22
- super.afterBuild();
23
- }
24
- }
42
+ let DdToken = (() => {
43
+ let _classDecorators = [(0, syntax_1.syntax)(/^:+[^\S\n]*$/u)];
44
+ let _classDescriptor;
45
+ let _classExtraInitializers = [];
46
+ let _classThis;
47
+ let _classSuper = listBase_1.ListBaseToken;
48
+ var DdToken = class extends _classSuper {
49
+ static { _classThis = this; }
50
+ static {
51
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
52
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
53
+ DdToken = _classThis = _classDescriptor.value;
54
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
55
+ __runInitializers(_classThis, _classExtraInitializers);
56
+ }
57
+ get type() {
58
+ return 'dd';
59
+ }
60
+ /* NOT FOR BROWSER */
61
+ /** 缩进数 */
62
+ get indent() {
63
+ return this.innerText.trimEnd().length;
64
+ }
65
+ set indent(indent) {
66
+ this.setText(':'.repeat(indent));
67
+ }
68
+ };
69
+ return DdToken = _classThis;
70
+ })();
25
71
  exports.DdToken = DdToken;
26
72
  constants_1.classes['DdToken'] = __filename;
@@ -42,7 +42,7 @@ const syntax_1 = require("../../mixin/syntax");
42
42
  const base_1 = require("./base");
43
43
  /** 状态开关 */
44
44
  let DoubleUnderscoreToken = (() => {
45
- let _classDecorators = [(0, syntax_1.syntax)(), (0, hidden_1.hiddenToken)(true)];
45
+ let _classDecorators = [(0, syntax_1.syntax)(), (0, hidden_1.hiddenToken)()];
46
46
  let _classDescriptor;
47
47
  let _classExtraInitializers = [];
48
48
  let _classThis;
@@ -41,7 +41,7 @@ const syntax_1 = require("../../mixin/syntax");
41
41
  const base_1 = require("./base");
42
42
  /** `<hr>` */
43
43
  let HrToken = (() => {
44
- let _classDecorators = [sol_1.sol, (0, syntax_1.syntax)(/^-{4,}$/u)];
44
+ let _classDecorators = [(0, sol_1.sol)(), (0, syntax_1.syntax)(/^-{4,}$/u)];
45
45
  let _classDescriptor;
46
46
  let _classExtraInitializers = [];
47
47
  let _classThis;
@@ -58,6 +58,11 @@ let HrToken = (() => {
58
58
  get type() {
59
59
  return 'hr';
60
60
  }
61
+ /* NOT FOR BROWSER */
62
+ /** @private */
63
+ toHtml() {
64
+ return '<hr>';
65
+ }
61
66
  };
62
67
  return HrToken = _classThis;
63
68
  })();
@@ -1,16 +1,5 @@
1
1
  import { ListBaseToken } from './listBase';
2
- import type { AstRange } from '../../lib/range';
3
2
  /** 位于行首的`;:*#` */
4
3
  export declare abstract class ListToken extends ListBaseToken {
5
4
  get type(): 'list';
6
- /** 是否包含`:` */
7
- get dd(): boolean;
8
- /** 是否包含`;` */
9
- get dt(): boolean;
10
- /** 是否包含`*` */
11
- get ul(): boolean;
12
- /** 是否包含`#` */
13
- get ol(): boolean;
14
- /** 获取列表行的范围 */
15
- getRange(): AstRange;
16
5
  }
@@ -37,10 +37,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
37
37
  exports.ListToken = void 0;
38
38
  const constants_1 = require("../../util/constants");
39
39
  const sol_1 = require("../../mixin/sol");
40
+ const syntax_1 = require("../../mixin/syntax");
40
41
  const listBase_1 = require("./listBase");
41
42
  /** 位于行首的`;:*#` */
42
43
  let ListToken = (() => {
43
- let _classDecorators = [sol_1.sol];
44
+ let _classDecorators = [(0, sol_1.sol)(true), (0, syntax_1.syntax)(/^[;:*#][:*#]*[^\S\n]*$/u)];
44
45
  let _classDescriptor;
45
46
  let _classExtraInitializers = [];
46
47
  let _classThis;
@@ -57,53 +58,6 @@ let ListToken = (() => {
57
58
  get type() {
58
59
  return 'list';
59
60
  }
60
- /* NOT FOR BROWSER */
61
- /** 是否包含`:` */
62
- get dd() {
63
- return this.innerText.includes(':');
64
- }
65
- /** 是否包含`;` */
66
- get dt() {
67
- return this.innerText.includes(';');
68
- }
69
- /** 是否包含`*` */
70
- get ul() {
71
- return this.innerText.includes('*');
72
- }
73
- /** 是否包含`#` */
74
- get ol() {
75
- return this.innerText.includes('#');
76
- }
77
- /** 获取列表行的范围 */
78
- getRange() {
79
- const range = this.createRange();
80
- let nDt = this.dt ? this.innerText.split(';').length - 2 : 0;
81
- range.setStartBefore(this);
82
- let { nextSibling } = this;
83
- while (nextSibling && (nextSibling.type !== 'text' || !nextSibling.data.includes('\n'))) {
84
- if (nextSibling.type === 'dd') {
85
- nDt -= nextSibling.indent;
86
- }
87
- if (nDt < 0) {
88
- break;
89
- }
90
- ({ nextSibling } = nextSibling);
91
- }
92
- if (nextSibling) {
93
- if (nDt < 0) {
94
- range.setEndBefore(nextSibling);
95
- }
96
- else {
97
- const i = nextSibling.data.indexOf('\n');
98
- range.setEnd(nextSibling, i);
99
- }
100
- }
101
- else {
102
- const { parentNode } = this;
103
- range.setEnd(parentNode, parentNode.length);
104
- }
105
- return range;
106
- }
107
61
  };
108
62
  return ListToken = _classThis;
109
63
  })();
@@ -1,5 +1,17 @@
1
1
  import { NowikiBaseToken } from './base';
2
+ import type { AstRange } from '../../lib/range';
3
+ export declare const list: Map<string, string[]>;
2
4
  /** `;:*#` */
3
5
  export declare abstract class ListBaseToken extends NowikiBaseToken {
4
6
  abstract get type(): 'dd' | 'list';
7
+ /** 是否包含`:` */
8
+ get dd(): boolean;
9
+ /** 是否包含`;` */
10
+ get dt(): boolean;
11
+ /** 是否包含`*` */
12
+ get ul(): boolean;
13
+ /** 是否包含`#` */
14
+ get ol(): boolean;
15
+ /** 获取列表行的范围 */
16
+ getRange(): AstRange;
5
17
  }