wikiparser-node 1.18.2 → 1.18.4

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 (76) hide show
  1. package/README.md +6 -1
  2. package/bundle/bundle-es7.min.js +29 -28
  3. package/bundle/bundle-lsp.min.js +31 -30
  4. package/bundle/bundle.min.js +30 -29
  5. package/config/minimum.json +7 -0
  6. package/dist/addon/token.js +37 -28
  7. package/dist/addon/transclude.js +1 -3
  8. package/dist/base.d.mts +4 -0
  9. package/dist/base.d.ts +4 -0
  10. package/dist/base.js +1 -0
  11. package/dist/base.mjs +2 -1
  12. package/dist/bin/config.js +3 -2
  13. package/dist/index.d.ts +14 -1
  14. package/dist/index.js +72 -72
  15. package/dist/lib/element.d.ts +6 -0
  16. package/dist/lib/element.js +543 -466
  17. package/dist/lib/lsp.d.ts +1 -0
  18. package/dist/lib/lsp.js +20 -15
  19. package/dist/lib/redirectMap.d.ts +7 -0
  20. package/dist/lib/redirectMap.js +31 -0
  21. package/dist/lib/text.d.ts +2 -2
  22. package/dist/lib/text.js +385 -325
  23. package/dist/lib/title.d.ts +23 -4
  24. package/dist/lib/title.js +17 -5
  25. package/dist/mixin/noEscape.d.ts +4 -0
  26. package/dist/mixin/noEscape.js +22 -0
  27. package/dist/mixin/readOnly.d.ts +4 -0
  28. package/dist/mixin/readOnly.js +26 -0
  29. package/dist/parser/braces.js +79 -37
  30. package/dist/parser/commentAndExt.js +5 -16
  31. package/dist/parser/links.js +1 -1
  32. package/dist/parser/quotes.js +1 -1
  33. package/dist/parser/redirect.js +1 -3
  34. package/dist/src/arg.js +253 -202
  35. package/dist/src/attribute.d.ts +0 -5
  36. package/dist/src/attribute.js +4 -8
  37. package/dist/src/converter.js +213 -162
  38. package/dist/src/gallery.js +1 -2
  39. package/dist/src/heading.js +5 -6
  40. package/dist/src/imageParameter.js +16 -16
  41. package/dist/src/imagemap.js +3 -2
  42. package/dist/src/index.d.ts +1 -1
  43. package/dist/src/index.js +722 -694
  44. package/dist/src/link/base.js +292 -241
  45. package/dist/src/link/file.js +13 -17
  46. package/dist/src/link/galleryImage.js +1 -1
  47. package/dist/src/link/redirectTarget.js +1 -2
  48. package/dist/src/magicLink.d.ts +0 -6
  49. package/dist/src/magicLink.js +5 -15
  50. package/dist/src/nested.js +7 -7
  51. package/dist/src/nowiki/base.js +2 -1
  52. package/dist/src/nowiki/index.js +4 -3
  53. package/dist/src/onlyinclude.js +95 -44
  54. package/dist/src/parameter.d.ts +0 -6
  55. package/dist/src/parameter.js +1 -13
  56. package/dist/src/redirect.js +6 -6
  57. package/dist/src/syntax.d.ts +4 -1
  58. package/dist/src/syntax.js +4 -1
  59. package/dist/src/table/base.d.ts +0 -5
  60. package/dist/src/table/base.js +2 -9
  61. package/dist/src/table/index.d.ts +1 -0
  62. package/dist/src/table/index.js +7 -4
  63. package/dist/src/table/td.d.ts +1 -0
  64. package/dist/src/table/td.js +2 -3
  65. package/dist/src/table/trBase.js +31 -14
  66. package/dist/src/tagPair/index.js +2 -1
  67. package/dist/src/transclude.js +713 -657
  68. package/dist/util/debug.js +10 -3
  69. package/dist/util/diff.js +1 -1
  70. package/dist/util/string.js +4 -5
  71. package/extensions/dist/base.js +8 -6
  72. package/extensions/dist/lint.js +1 -1
  73. package/extensions/es7/base.js +8 -6
  74. package/extensions/es7/lint.js +1 -1
  75. package/extensions/ui.css +1 -1
  76. package/package.json +3 -3
@@ -1,4 +1,38 @@
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
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
38
  };
@@ -13,6 +47,7 @@ const index_2 = require("../index");
13
47
  const atom_1 = require("../atom");
14
48
  /* NOT FOR BROWSER */
15
49
  const debug_1 = require("../../util/debug");
50
+ const noEscape_1 = require("../../mixin/noEscape");
16
51
  /* NOT FOR BROWSER END */
17
52
  /**
18
53
  * 是否为普通内链
@@ -25,271 +60,287 @@ const isLink = (type) => type === 'redirect-target' || type === 'link';
25
60
  * 内链
26
61
  * @classdesc `{childNodes: [AtomToken, ...Token[]]}`
27
62
  */
28
- class LinkBaseToken extends index_2.Token {
29
- #bracket = true;
30
- #delimiter;
31
- #title;
32
- /* NOT FOR BROWSER END */
33
- /** full link / 完整链接 */
34
- get link() {
35
- // eslint-disable-next-line no-unused-labels
36
- LSP: return this.#title;
37
- }
38
- /* PRINT ONLY */
39
- /** 片段标识符 */
40
- get fragment() {
41
- return this.#title.fragment;
42
- }
43
- /* PRINT ONLY END */
44
- /* NOT FOR BROWSER */
45
- set fragment(fragment) {
46
- this.setFragment(fragment);
47
- }
48
- set link(link) {
49
- this.setTarget(link);
50
- }
51
- /** interwiki */
52
- get interwiki() {
53
- return this.#title.interwiki;
54
- }
55
- /** @throws `RangeError` 非法的跨维基前缀 */
56
- set interwiki(interwiki) {
57
- if (isLink(this.type)) {
58
- const { prefix, main, fragment } = this.#title, link = `${interwiki}:${prefix}${main}${fragment === undefined ? '' : `#${fragment}`}`;
59
- /* istanbul ignore if */
60
- if (interwiki && !this.isInterwiki(link)) {
61
- throw new RangeError(`${interwiki} is not a valid interwiki prefix!`);
62
- }
63
- this.setTarget(link);
63
+ let LinkBaseToken = (() => {
64
+ let _classDecorators = [noEscape_1.noEscape];
65
+ let _classDescriptor;
66
+ let _classExtraInitializers = [];
67
+ let _classThis;
68
+ let _classSuper = index_2.Token;
69
+ var LinkBaseToken = class extends _classSuper {
70
+ static { _classThis = this; }
71
+ static {
72
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
73
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
74
+ LinkBaseToken = _classThis = _classDescriptor.value;
75
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
76
+ __runInitializers(_classThis, _classExtraInitializers);
64
77
  }
65
- }
66
- /* NOT FOR BROWSER END */
67
- /**
68
- * @param link 链接标题
69
- * @param linkText 链接显示文字
70
- * @param delimiter `|`
71
- */
72
- constructor(link, linkText, config = index_1.default.getConfig(), accum = [], delimiter = '|') {
73
- super(undefined, config, accum, {
74
- AtomToken: 0, Token: 1,
75
- });
76
- this.insertAt(new atom_1.AtomToken(link, 'link-target', config, accum, {
77
- 'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '',
78
- }));
79
- if (linkText !== undefined) {
80
- const inner = new index_2.Token(linkText, config, accum, {
81
- 'Stage-5': ':', QuoteToken: ':', ConverterToken: ':',
82
- });
83
- inner.type = 'link-text';
84
- inner.setAttribute('stage', constants_1.MAX_STAGE - 1);
85
- this.insertAt(inner);
78
+ #bracket = true;
79
+ #delimiter;
80
+ #title;
81
+ /* NOT FOR BROWSER END */
82
+ /** full link / 完整链接 */
83
+ get link() {
84
+ // eslint-disable-next-line no-unused-labels
85
+ LSP: return this.#title;
86
86
  }
87
- this.#delimiter = delimiter;
88
- /* NOT FOR BROWSER */
89
- this.protectChildren(0);
90
- }
91
- /** @private */
92
- afterBuild() {
93
- this.#title = this.getTitle();
94
- if (this.#delimiter.includes('\0')) {
95
- this.#delimiter = this.buildFromStr(this.#delimiter, constants_1.BuildMethod.String);
87
+ /* PRINT ONLY */
88
+ /** 片段标识符 */
89
+ get fragment() {
90
+ return this.#title.fragment;
96
91
  }
97
- this.setAttribute('name', this.#title.title);
98
- super.afterBuild();
92
+ /* PRINT ONLY END */
99
93
  /* NOT FOR BROWSER */
100
- const /** @implements */ linkListener = (e, data) => {
101
- const { prevTarget } = e, { type } = this;
102
- if (prevTarget?.type === 'link-target') {
103
- const name = prevTarget.toString(true), titleObj = this.getTitle(), { title, interwiki, ns, valid } = titleObj;
104
- if (!valid) {
105
- (0, debug_1.undo)(e, data);
106
- throw new Error(`Invalid link target: ${name}`);
107
- }
108
- else if (type === 'category' && (interwiki || ns !== 14)
109
- || (type === 'file' || type === 'gallery-image' || type === 'imagemap-image')
110
- && (interwiki || ns !== 6)) {
111
- (0, debug_1.undo)(e, data);
112
- throw new Error(`${type === 'category' ? 'Category' : 'File'} link cannot change namespace: ${name}`);
94
+ set fragment(fragment) {
95
+ this.setFragment(fragment);
96
+ }
97
+ set link(link) {
98
+ this.setTarget(link);
99
+ }
100
+ /** interwiki */
101
+ get interwiki() {
102
+ return this.#title.interwiki;
103
+ }
104
+ /** @throws `RangeError` 非法的跨维基前缀 */
105
+ set interwiki(interwiki) {
106
+ if (isLink(this.type)) {
107
+ const { prefix, main, fragment } = this.#title, link = `${interwiki}:${prefix}${main}${fragment === undefined ? '' : `#${fragment}`}`;
108
+ /* istanbul ignore if */
109
+ if (interwiki && !this.isInterwiki(link)) {
110
+ throw new RangeError(`${interwiki} is not a valid interwiki prefix!`);
113
111
  }
114
- else if (type === 'link' && !interwiki && (ns === 6 || ns === 14)
115
- && !name.trim().startsWith(':')) {
116
- const { firstChild } = prevTarget;
117
- if (firstChild?.type === 'text') {
118
- firstChild.insertData(0, ':');
112
+ this.setTarget(link);
113
+ }
114
+ }
115
+ /* NOT FOR BROWSER END */
116
+ /**
117
+ * @param link 链接标题
118
+ * @param linkText 链接显示文字
119
+ * @param delimiter `|`
120
+ */
121
+ constructor(link, linkText, config = index_1.default.getConfig(), accum = [], delimiter = '|') {
122
+ super(undefined, config, accum, {
123
+ AtomToken: 0, Token: 1,
124
+ });
125
+ this.insertAt(new atom_1.AtomToken(link, 'link-target', config, accum, {
126
+ 'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '',
127
+ }));
128
+ if (linkText !== undefined) {
129
+ const inner = new index_2.Token(linkText, config, accum, {
130
+ 'Stage-5': ':', QuoteToken: ':', ConverterToken: ':',
131
+ });
132
+ inner.type = 'link-text';
133
+ inner.setAttribute('stage', constants_1.MAX_STAGE - 1);
134
+ this.insertAt(inner);
135
+ }
136
+ this.#delimiter = delimiter;
137
+ /* NOT FOR BROWSER */
138
+ this.protectChildren(0);
139
+ }
140
+ /** @private */
141
+ afterBuild() {
142
+ this.#title = this.getTitle();
143
+ if (this.#delimiter.includes('\0')) {
144
+ this.#delimiter = this.buildFromStr(this.#delimiter, constants_1.BuildMethod.String);
145
+ }
146
+ this.setAttribute('name', this.#title.title);
147
+ super.afterBuild();
148
+ /* NOT FOR BROWSER */
149
+ const /** @implements */ linkListener = (e, data) => {
150
+ const { prevTarget } = e, { type } = this;
151
+ if (prevTarget?.type === 'link-target') {
152
+ const name = prevTarget.text(), titleObj = this.getTitle(), { title, interwiki, ns, valid } = titleObj;
153
+ if (!valid) {
154
+ (0, debug_1.undo)(e, data);
155
+ throw new Error(`Invalid link target: ${name}`);
119
156
  }
120
- else {
121
- prevTarget.prepend(':');
157
+ else if (type === 'category' && (interwiki || ns !== 14)
158
+ || (type === 'file' || type === 'gallery-image' || type === 'imagemap-image')
159
+ && (interwiki || ns !== 6)) {
160
+ (0, debug_1.undo)(e, data);
161
+ throw new Error(`${type === 'category' ? 'Category' : 'File'} link cannot change namespace: ${name}`);
122
162
  }
163
+ else if (type === 'link' && !interwiki && (ns === 6 || ns === 14)
164
+ && !name.trim().startsWith(':')) {
165
+ const { firstChild } = prevTarget;
166
+ if (firstChild?.type === 'text') {
167
+ firstChild.insertData(0, ':');
168
+ }
169
+ else {
170
+ prevTarget.prepend(':');
171
+ }
172
+ }
173
+ this.#title = titleObj;
174
+ this.setAttribute('name', title);
123
175
  }
124
- this.#title = titleObj;
125
- this.setAttribute('name', title);
126
- }
127
- };
128
- this.addEventListener(['remove', 'insert', 'replace', 'text'], linkListener);
129
- }
130
- /** @private */
131
- setAttribute(key, value) {
132
- if (key === 'bracket') {
133
- this.#bracket = value;
176
+ };
177
+ this.addEventListener(['remove', 'insert', 'replace', 'text'], linkListener);
134
178
  }
135
- else if (key === 'title') {
136
- this.#title = value;
179
+ /** @private */
180
+ setAttribute(key, value) {
181
+ if (key === 'bracket') {
182
+ this.#bracket = value;
183
+ }
184
+ else if (key === 'title') {
185
+ this.#title = value;
186
+ }
187
+ else {
188
+ super.setAttribute(key, value);
189
+ }
137
190
  }
138
- else {
139
- super.setAttribute(key, value);
191
+ /** @private */
192
+ toString(skip) {
193
+ const str = super.toString(skip, this.#delimiter);
194
+ return this.#bracket ? `[[${str}]]` : str;
140
195
  }
141
- }
142
- /** @private */
143
- toString(skip) {
144
- const str = super.toString(skip, this.#delimiter);
145
- return this.#bracket ? `[[${str}]]` : str;
146
- }
147
- /** @private */
148
- text() {
149
- const str = super.text('|');
150
- return this.#bracket ? `[[${str}]]` : str;
151
- }
152
- /** @private */
153
- getAttribute(key) {
154
- if (key === 'title') {
155
- return this.#title;
196
+ /** @private */
197
+ text() {
198
+ const str = super.text('|');
199
+ return this.#bracket ? `[[${str}]]` : str;
156
200
  }
157
- return key === 'padding' ? 2 : super.getAttribute(key);
158
- }
159
- /** @private */
160
- getGaps(i) {
161
- return i === 0 ? this.#delimiter.length : 1;
162
- }
163
- /** @private */
164
- lint(start = this.getAbsoluteIndex(), re) {
165
- const errors = super.lint(start, re), { childNodes: [target, linkText], type } = this, { encoded, fragment } = this.#title, rect = new rect_1.BoundingRect(this, start);
166
- if (target.childNodes.some(({ type: t }) => t === 'template')) {
167
- errors.push((0, lint_1.generateForChild)(target, rect, 'unknown-page', 'template in an internal link target', 'warning'));
201
+ /** @private */
202
+ getAttribute(key) {
203
+ if (key === 'title') {
204
+ return this.#title;
205
+ }
206
+ return key === 'padding' ? 2 : super.getAttribute(key);
168
207
  }
169
- if (encoded) {
170
- const e = (0, lint_1.generateForChild)(target, rect, 'url-encoding', 'unnecessary URL encoding in an internal link');
171
- e.suggestions = [{ desc: 'decode', range: [e.startIndex, e.endIndex], text: (0, string_1.rawurldecode)(target.text()) }];
172
- errors.push(e);
208
+ /** @private */
209
+ getGaps(i) {
210
+ return i === 0 ? this.#delimiter.length : 1;
173
211
  }
174
- if (type === 'link' || type === 'category') {
175
- const j = linkText?.childNodes.findIndex(c => c.type === 'text' && c.data.includes('|')), textNode = linkText?.childNodes[j];
176
- if (textNode) {
177
- const e = (0, lint_1.generateForChild)(linkText, rect, 'pipe-like', 'additional "|" in the link text', 'warning'), i = e.startIndex + linkText.getRelativeIndex(j);
178
- e.suggestions = [
179
- {
180
- desc: 'escape',
181
- range: [i, i + textNode.data.length],
182
- text: textNode.data.replace(/\|/gu, '&#124;'),
183
- },
184
- ];
212
+ /** @private */
213
+ lint(start = this.getAbsoluteIndex(), re) {
214
+ const errors = super.lint(start, re), { childNodes: [target, linkText], type } = this, { encoded, fragment } = this.#title, rect = new rect_1.BoundingRect(this, start);
215
+ if (target.childNodes.some(({ type: t }) => t === 'template')) {
216
+ errors.push((0, lint_1.generateForChild)(target, rect, 'unknown-page', 'template in an internal link target', 'warning'));
217
+ }
218
+ if (encoded) {
219
+ const e = (0, lint_1.generateForChild)(target, rect, 'url-encoding', 'unnecessary URL encoding in an internal link');
220
+ e.suggestions = [{ desc: 'decode', range: [e.startIndex, e.endIndex], text: (0, string_1.rawurldecode)(target.text()) }];
185
221
  errors.push(e);
186
222
  }
187
- }
188
- if (fragment !== undefined && !isLink(type)) {
189
- const e = (0, lint_1.generateForChild)(target, rect, 'no-ignored', 'useless fragment'), j = target.childNodes.findIndex(c => c.type === 'text' && c.data.includes('#')), textNode = target.childNodes[j];
190
- if (textNode) {
191
- e.fix = {
192
- range: [
193
- e.startIndex + target.getRelativeIndex(j) + textNode.data.indexOf('#'),
194
- e.endIndex,
195
- ],
196
- text: '',
197
- desc: 'remove',
198
- };
223
+ if (type === 'link' || type === 'category') {
224
+ const j = linkText?.childNodes.findIndex(c => c.type === 'text' && c.data.includes('|')), textNode = linkText?.childNodes[j];
225
+ if (textNode) {
226
+ const e = (0, lint_1.generateForChild)(linkText, rect, 'pipe-like', 'additional "|" in the link text', 'warning'), i = e.startIndex + linkText.getRelativeIndex(j);
227
+ e.suggestions = [
228
+ {
229
+ desc: 'escape',
230
+ range: [i, i + textNode.data.length],
231
+ text: textNode.data.replace(/\|/gu, '&#124;'),
232
+ },
233
+ ];
234
+ errors.push(e);
235
+ }
236
+ }
237
+ if (fragment !== undefined && !isLink(type)) {
238
+ const e = (0, lint_1.generateForChild)(target, rect, 'no-ignored', 'useless fragment'), j = target.childNodes.findIndex(c => c.type === 'text' && c.data.includes('#')), textNode = target.childNodes[j];
239
+ if (textNode) {
240
+ e.fix = {
241
+ range: [
242
+ e.startIndex + target.getRelativeIndex(j) + textNode.data.indexOf('#'),
243
+ e.endIndex,
244
+ ],
245
+ text: '',
246
+ desc: 'remove',
247
+ };
248
+ }
249
+ errors.push(e);
199
250
  }
200
- errors.push(e);
251
+ return errors;
201
252
  }
202
- return errors;
203
- }
204
- /** @private */
205
- getTitle(temporary, halfParsed) {
206
- return this.normalizeTitle(this.firstChild.toString(true), 0, temporary, halfParsed, true, true);
207
- }
208
- /** @private */
209
- print() {
210
- return super.print(this.#bracket ? { pre: '[[', post: ']]', sep: this.#delimiter } : { sep: this.#delimiter });
211
- }
212
- /** @private */
213
- json(_, start = this.getAbsoluteIndex()) {
214
- const json = super.json(undefined, start), { type, fragment } = this;
215
- if (fragment !== undefined && (type === 'link' || type === 'redirect-target')) {
216
- json['fragment'] = fragment;
253
+ /** @private */
254
+ getTitle(temporary, halfParsed) {
255
+ return this.normalizeTitle(this.firstChild.text(), 0, { halfParsed, temporary, decode: true, selfLink: true });
217
256
  }
218
- return json;
219
- }
220
- /* NOT FOR BROWSER */
221
- cloneNode() {
222
- const [link, ...linkText] = this.cloneChildNodes();
223
- return debug_1.Shadow.run(() => {
224
- const C = this.constructor, token = new C('', undefined, this.getAttribute('config'));
225
- token.firstChild.safeReplaceWith(link);
226
- token.append(...linkText);
227
- return token;
228
- });
229
- }
230
- /**
231
- * Set the link target
232
- *
233
- * 设置链接目标
234
- * @param link link target / 链接目标
235
- */
236
- setTarget(link) {
237
- const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(link, this.getAttribute('include'), 2, config), token = debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'link-target', config, [], {
238
- 'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '',
239
- }));
240
- token.append(...childNodes);
241
- this.firstChild.safeReplaceWith(token);
242
- }
243
- /**
244
- * Set the fragment
245
- *
246
- * 设置片段标识符
247
- * @param fragment 片段标识符
248
- */
249
- setFragment(fragment) {
250
- const { type, name } = this;
251
- if (fragment === undefined || isLink(type)) {
252
- fragment &&= (0, string_1.encode)(fragment);
253
- this.setTarget(name + (fragment === undefined ? '' : `#${fragment}`));
257
+ /** @private */
258
+ print() {
259
+ return super.print(this.#bracket ? { pre: '[[', post: ']]', sep: this.#delimiter } : { sep: this.#delimiter });
254
260
  }
255
- }
256
- /**
257
- * Set the link text
258
- *
259
- * 设置链接显示文字
260
- * @param linkStr link text / 链接显示文字
261
- */
262
- setLinkText(linkStr) {
263
- if (linkStr === undefined) {
264
- this.childNodes[1]?.remove();
265
- return;
261
+ /** @private */
262
+ json(_, start = this.getAbsoluteIndex()) {
263
+ const json = super.json(undefined, start), { type, fragment } = this;
264
+ if (fragment !== undefined && (type === 'link' || type === 'redirect-target')) {
265
+ json['fragment'] = fragment;
266
+ }
267
+ return json;
266
268
  }
267
- const root = index_1.default
268
- .parse(linkStr, this.getAttribute('include'), undefined, this.getAttribute('config'));
269
- if (this.length === 1) {
270
- root.type = 'link-text';
271
- root.setAttribute('acceptable', {
272
- 'Stage-5': ':', QuoteToken: ':', ConverterToken: ':',
269
+ /* NOT FOR BROWSER */
270
+ cloneNode() {
271
+ const [link, ...linkText] = this.cloneChildNodes();
272
+ return debug_1.Shadow.run(() => {
273
+ const C = this.constructor, token = new C('', undefined, this.getAttribute('config'));
274
+ token.firstChild.safeReplaceWith(link);
275
+ token.append(...linkText);
276
+ return token;
273
277
  });
274
- this.insertAt(root);
275
278
  }
276
- else {
277
- this.lastChild.replaceChildren(...root.childNodes);
279
+ /**
280
+ * Set the link target
281
+ *
282
+ * 设置链接目标
283
+ * @param link link target / 链接目标
284
+ */
285
+ setTarget(link) {
286
+ const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(link, this.getAttribute('include'), 2, config), token = debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'link-target', config, [], {
287
+ 'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '',
288
+ }));
289
+ token.append(...childNodes);
290
+ this.firstChild.safeReplaceWith(token);
278
291
  }
279
- }
280
- /** @private */
281
- toHtmlInternal(opt) {
282
- if (this.is('link') || this.is('redirect-target')) {
283
- const { link, length, lastChild, type } = this, title = link.getTitleAttr();
284
- return `<a${link.interwiki && ' class="extiw"'} href="${link.getUrl()}"${title && ` title="${title}"`}>${type === 'link' && length > 1
285
- ? lastChild.toHtmlInternal({
286
- ...opt,
287
- nowrap: true,
288
- })
289
- : (0, string_1.sanitize)(this.innerText)}</a>`;
292
+ /**
293
+ * Set the fragment
294
+ *
295
+ * 设置片段标识符
296
+ * @param fragment 片段标识符
297
+ */
298
+ setFragment(fragment) {
299
+ const { type, name } = this;
300
+ if (fragment === undefined || isLink(type)) {
301
+ fragment &&= (0, string_1.encode)(fragment);
302
+ this.setTarget(name + (fragment === undefined ? '' : `#${fragment}`));
303
+ }
290
304
  }
291
- return '';
292
- }
293
- }
305
+ /**
306
+ * Set the link text
307
+ *
308
+ * 设置链接显示文字
309
+ * @param linkStr link text / 链接显示文字
310
+ */
311
+ setLinkText(linkStr) {
312
+ if (linkStr === undefined) {
313
+ this.childNodes[1]?.remove();
314
+ return;
315
+ }
316
+ const root = index_1.default
317
+ .parse(linkStr, this.getAttribute('include'), undefined, this.getAttribute('config'));
318
+ if (this.length === 1) {
319
+ root.type = 'link-text';
320
+ root.setAttribute('acceptable', {
321
+ 'Stage-5': ':', QuoteToken: ':', ConverterToken: ':',
322
+ });
323
+ this.insertAt(root);
324
+ }
325
+ else {
326
+ this.lastChild.replaceChildren(...root.childNodes);
327
+ }
328
+ }
329
+ /** @private */
330
+ toHtmlInternal(opt) {
331
+ if (this.is('link') || this.is('redirect-target')) {
332
+ const { link, length, lastChild, type } = this, title = link.getTitleAttr();
333
+ return `<a${link.interwiki && ' class="extiw"'} href="${link.getUrl()}"${title && ` title="${title}"`}>${type === 'link' && length > 1
334
+ ? lastChild.toHtmlInternal({
335
+ ...opt,
336
+ nowrap: true,
337
+ })
338
+ : (0, string_1.sanitize)(this.innerText)}</a>`;
339
+ }
340
+ return '';
341
+ }
342
+ };
343
+ return LinkBaseToken = _classThis;
344
+ })();
294
345
  exports.LinkBaseToken = LinkBaseToken;
295
346
  constants_1.classes['LinkBaseToken'] = __filename;