wikiparser-node 1.19.0 → 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 (105) hide show
  1. package/README.md +3 -0
  2. package/bundle/bundle-es7.min.js +24 -31
  3. package/bundle/bundle-lsp.min.js +25 -98
  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 +4 -4
  10. package/dist/base.d.mts +1 -1
  11. package/dist/base.d.ts +1 -1
  12. package/dist/bin/config.js +26 -8
  13. package/dist/index.js +10 -1
  14. package/dist/internal.d.ts +2 -0
  15. package/dist/lib/document.d.ts +1 -0
  16. package/dist/lib/document.js +10 -1
  17. package/dist/lib/element.js +15 -21
  18. package/dist/lib/lsp.js +88 -58
  19. package/dist/lib/node.js +21 -24
  20. package/dist/lib/text.js +3 -4
  21. package/dist/lib/title.js +2 -1
  22. package/dist/mixin/attributesParent.js +1 -1
  23. package/dist/mixin/fixed.d.ts +1 -2
  24. package/dist/mixin/fixed.js +2 -3
  25. package/dist/mixin/gapped.d.ts +4 -0
  26. package/dist/mixin/gapped.js +24 -0
  27. package/dist/mixin/hidden.js +1 -1
  28. package/dist/mixin/multiLine.d.ts +4 -0
  29. package/dist/mixin/multiLine.js +33 -0
  30. package/dist/mixin/noEscape.js +1 -1
  31. package/dist/mixin/padded.d.ts +5 -0
  32. package/dist/mixin/padded.js +24 -0
  33. package/dist/mixin/singleLine.js +1 -1
  34. package/dist/mixin/sol.js +1 -1
  35. package/dist/mixin/syntax.js +3 -3
  36. package/dist/parser/braces.js +8 -12
  37. package/dist/parser/commentAndExt.js +18 -2
  38. package/dist/parser/magicLinks.js +2 -2
  39. package/dist/parser/selector.js +5 -2
  40. package/dist/src/arg.js +10 -13
  41. package/dist/src/atom.js +2 -7
  42. package/dist/src/attribute.js +6 -6
  43. package/dist/src/attributes.js +8 -12
  44. package/dist/src/commented.d.ts +26 -0
  45. package/dist/src/commented.js +52 -0
  46. package/dist/src/converter.js +3 -6
  47. package/dist/src/converterFlags.js +266 -223
  48. package/dist/src/converterRule.d.ts +2 -2
  49. package/dist/src/converterRule.js +2 -2
  50. package/dist/src/extLink.d.ts +2 -3
  51. package/dist/src/extLink.js +222 -175
  52. package/dist/src/gallery.d.ts +4 -5
  53. package/dist/src/gallery.js +177 -144
  54. package/dist/src/heading.js +11 -11
  55. package/dist/src/hidden.js +2 -7
  56. package/dist/src/imageParameter.d.ts +2 -2
  57. package/dist/src/imageParameter.js +6 -5
  58. package/dist/src/imagemap.d.ts +2 -2
  59. package/dist/src/imagemap.js +155 -123
  60. package/dist/src/imagemapLink.d.ts +2 -2
  61. package/dist/src/index.js +44 -20
  62. package/dist/src/link/base.d.ts +2 -3
  63. package/dist/src/link/base.js +13 -15
  64. package/dist/src/link/file.d.ts +2 -3
  65. package/dist/src/link/file.js +3 -3
  66. package/dist/src/link/galleryImage.d.ts +2 -3
  67. package/dist/src/link/galleryImage.js +7 -13
  68. package/dist/src/magicLink.js +7 -9
  69. package/dist/src/nested.d.ts +2 -2
  70. package/dist/src/nested.js +4 -7
  71. package/dist/src/nowiki/comment.js +2 -5
  72. package/dist/src/nowiki/doubleUnderscore.js +2 -5
  73. package/dist/src/nowiki/index.d.ts +2 -2
  74. package/dist/src/nowiki/index.js +2 -1
  75. package/dist/src/onlyinclude.js +6 -13
  76. package/dist/src/paramTag/index.d.ts +2 -2
  77. package/dist/src/paramTag/index.js +102 -66
  78. package/dist/src/parameter.d.ts +4 -5
  79. package/dist/src/parameter.js +13 -13
  80. package/dist/src/pre.d.ts +4 -5
  81. package/dist/src/pre.js +8 -17
  82. package/dist/src/syntax.d.ts +1 -1
  83. package/dist/src/syntax.js +2 -7
  84. package/dist/src/table/base.d.ts +2 -2
  85. package/dist/src/table/base.js +8 -8
  86. package/dist/src/table/index.js +1 -1
  87. package/dist/src/table/td.d.ts +3 -3
  88. package/dist/src/table/td.js +9 -9
  89. package/dist/src/table/tr.d.ts +2 -2
  90. package/dist/src/tagPair/ext.js +35 -30
  91. package/dist/src/tagPair/index.d.ts +1 -1
  92. package/dist/src/tagPair/index.js +2 -5
  93. package/dist/src/tagPair/translate.d.ts +38 -0
  94. package/dist/src/tagPair/translate.js +129 -0
  95. package/dist/src/transclude.js +5 -6
  96. package/dist/util/html.js +16 -1
  97. package/dist/util/lint.js +17 -30
  98. package/dist/util/sharable.js +29 -1
  99. package/dist/util/sharable.mjs +31 -3
  100. package/dist/util/string.js +14 -1
  101. package/extensions/dist/base.js +1 -1
  102. package/extensions/dist/lsp.js +13 -2
  103. package/package.json +4 -3
  104. package/extensions/es7/base.js +0 -320
  105. package/extensions/es7/lint.js +0 -97
@@ -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
  };
@@ -7,6 +41,7 @@ exports.ImagemapToken = void 0;
7
41
  const lint_1 = require("../util/lint");
8
42
  const debug_1 = require("../util/debug");
9
43
  const rect_1 = require("../lib/rect");
44
+ const multiLine_1 = require("../mixin/multiLine");
10
45
  const index_1 = __importDefault(require("../index"));
11
46
  const index_2 = require("./index");
12
47
  const noinclude_1 = require("./nowiki/noinclude");
@@ -14,149 +49,146 @@ const galleryImage_1 = require("./link/galleryImage");
14
49
  const imagemapLink_1 = require("./imagemapLink");
15
50
  /* NOT FOR BROWSER */
16
51
  const constants_1 = require("../util/constants");
52
+ const html_1 = require("../util/html");
17
53
  const singleLine_1 = require("../mixin/singleLine");
18
54
  /**
19
55
  * `<imagemap>`
20
56
  * @classdesc `{childNodes: [...NoincludeToken[], GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)[]]}`
21
57
  */
22
- class ImagemapToken extends index_2.Token {
23
- /* NOT FOR BROWSER END */
24
- get type() {
25
- return 'ext-inner';
26
- }
27
- /** 图片 */
28
- get image() {
29
- return this.childNodes.find((0, debug_1.isToken)('imagemap-image'));
30
- }
31
- /** @param inner 标签内部wikitext */
32
- constructor(inner, config = index_1.default.getConfig(), accum = []) {
33
- super(undefined, config, accum, {
34
- GalleryImageToken: ':', ImagemapLinkToken: ':', NoincludeToken: ':', AstText: ':',
35
- });
36
- if (!inner) {
37
- return;
58
+ let ImagemapToken = (() => {
59
+ let _classDecorators = [multiLine_1.multiLine];
60
+ let _classDescriptor;
61
+ let _classExtraInitializers = [];
62
+ let _classThis;
63
+ let _classSuper = index_2.Token;
64
+ var ImagemapToken = class extends _classSuper {
65
+ static { _classThis = this; }
66
+ static {
67
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
68
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
69
+ ImagemapToken = _classThis = _classDescriptor.value;
70
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
71
+ __runInitializers(_classThis, _classExtraInitializers);
72
+ }
73
+ /* NOT FOR BROWSER END */
74
+ get type() {
75
+ return 'ext-inner';
76
+ }
77
+ /** 图片 */
78
+ get image() {
79
+ return this.childNodes.find((0, debug_1.isToken)('imagemap-image'));
38
80
  }
39
- const lines = inner.split('\n'), protocols = new Set(config.protocol.split('|')), SingleLineNoincludeToken = (0, singleLine_1.singleLine)()(noinclude_1.NoincludeToken);
40
- let first = true, error = false;
41
- for (const line of lines) {
42
- const trimmed = line.trim();
43
- if (error || !trimmed || trimmed.startsWith('#')) {
44
- //
81
+ /** @param inner 标签内部wikitext */
82
+ constructor(inner, config = index_1.default.getConfig(), accum = []) {
83
+ super(undefined, config, accum, {
84
+ GalleryImageToken: ':', ImagemapLinkToken: ':', NoincludeToken: ':', AstText: ':',
85
+ });
86
+ if (!inner) {
87
+ return;
45
88
  }
46
- else if (first) {
47
- const pipe = line.indexOf('|'), file = pipe === -1 ? line : line.slice(0, pipe), { valid, ns,
48
- /* NOT FOR BROWSER */
49
- interwiki, } = this.normalizeTitle(file, 0, { halfParsed: true, temporary: true });
50
- if (valid
51
- && !interwiki
52
- && ns === 6) {
53
- // @ts-expect-error abstract class
54
- const token = new galleryImage_1.GalleryImageToken('imagemap', file, pipe === -1 ? undefined : line.slice(pipe + 1), config, accum);
55
- super.insertAt(token);
56
- first = false;
57
- continue;
58
- }
59
- else {
60
- error = true;
89
+ const lines = inner.split('\n'), protocols = new Set(config.protocol.split('|')), SingleLineNoincludeToken = (0, singleLine_1.singleLine)()(noinclude_1.NoincludeToken);
90
+ let first = true, error = false;
91
+ for (const line of lines) {
92
+ const trimmed = line.trim();
93
+ if (error || !trimmed || trimmed.startsWith('#')) {
94
+ //
61
95
  }
62
- }
63
- else if (line.trim().split(/[\t ]/u, 1)[0] === 'desc') {
64
- super.insertAt(line);
65
- continue;
66
- }
67
- else if (line.includes('[')) {
68
- const i = line.indexOf('['), substr = line.slice(i), mtIn = /^\[\[([^|]+)(?:\|([^\]]+))?\]\][\w\s]*$/u
69
- .exec(substr);
70
- if (mtIn) {
71
- if (this.normalizeTitle(mtIn[1], 0, { halfParsed: true, temporary: true, selfLink: true })
72
- .valid) {
96
+ else if (first) {
97
+ const pipe = line.indexOf('|'), file = pipe === -1 ? line : line.slice(0, pipe), { valid, ns,
98
+ /* NOT FOR BROWSER */
99
+ interwiki, } = this.normalizeTitle(file, 0, { halfParsed: true, temporary: true });
100
+ if (valid
101
+ && !interwiki
102
+ && ns === 6) {
73
103
  // @ts-expect-error abstract class
74
- super.insertAt(new imagemapLink_1.ImagemapLinkToken(line.slice(0, i), mtIn.slice(1), substr.slice(substr.indexOf(']]') + 2), config, accum));
104
+ const token = new galleryImage_1.GalleryImageToken('imagemap', file, pipe === -1 ? undefined : line.slice(pipe + 1), config, accum);
105
+ super.insertAt(token);
106
+ first = false;
75
107
  continue;
76
108
  }
109
+ else {
110
+ error = true;
111
+ }
77
112
  }
78
- else if (protocols.has(substr.slice(1, substr.indexOf(':') + 1))
79
- || protocols.has(substr.slice(1, substr.indexOf('//') + 2))) {
80
- const mtEx = /^\[([^\]\s]+)(?:(\s+(?!\s))([^\]]*))?\][\w\s]*$/u
113
+ else if (line.trim().split(/[\t ]/u, 1)[0] === 'desc') {
114
+ super.insertAt(line);
115
+ continue;
116
+ }
117
+ else if (line.includes('[')) {
118
+ const i = line.indexOf('['), substr = line.slice(i), mtIn = /^\[\[([^|]+)(?:\|([^\]]*))?\]\][\w\s]*$/u
81
119
  .exec(substr);
82
- if (mtEx) {
83
- // @ts-expect-error abstract class
84
- super.insertAt(new imagemapLink_1.ImagemapLinkToken(line.slice(0, i), mtEx.slice(1), substr.slice(substr.indexOf(']') + 1), config, accum));
85
- continue;
120
+ if (mtIn) {
121
+ if (this.normalizeTitle(mtIn[1], 0, { halfParsed: true, temporary: true, selfLink: true })
122
+ .valid) {
123
+ // @ts-expect-error abstract class
124
+ super.insertAt(new imagemapLink_1.ImagemapLinkToken(line.slice(0, i), mtIn.slice(1), substr.slice(substr.indexOf(']]') + 2), config, accum));
125
+ continue;
126
+ }
127
+ }
128
+ else if (substr.startsWith('[//')
129
+ || protocols.has(substr.slice(1, substr.indexOf(':') + 1))
130
+ || protocols.has(substr.slice(1, substr.indexOf('//') + 2))) {
131
+ const mtEx = /^\[([^\]\s]+)(?:(\s+(?!\s))([^\]]*))?\][\w\s]*$/u
132
+ .exec(substr);
133
+ if (mtEx) {
134
+ // @ts-expect-error abstract class
135
+ super.insertAt(new imagemapLink_1.ImagemapLinkToken(line.slice(0, i), mtEx.slice(1), substr.slice(substr.indexOf(']') + 1), config, accum));
136
+ continue;
137
+ }
86
138
  }
87
139
  }
140
+ // @ts-expect-error abstract class
141
+ super.insertAt(new SingleLineNoincludeToken(line, config, accum));
88
142
  }
89
- // @ts-expect-error abstract class
90
- super.insertAt(new SingleLineNoincludeToken(line, config, accum));
91
- }
92
- }
93
- /** @private */
94
- toString(skip) {
95
- return super.toString(skip, '\n');
96
- }
97
- /** @private */
98
- text() {
99
- return super.text('\n').replace(/\n{2,}/gu, '\n');
100
- }
101
- /** @private */
102
- getGaps() {
103
- return 1;
104
- }
105
- /** @private */
106
- lint(start = this.getAbsoluteIndex(), re) {
107
- const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start);
108
- if (this.image) {
109
- errors.push(...this.childNodes.filter(child => {
110
- const str = child.toString().trim();
111
- return child.type === 'noinclude' && str && !str.startsWith('#');
112
- }).map(child => {
113
- const e = (0, lint_1.generateForChild)(child, rect, 'invalid-imagemap', 'invalid link in <imagemap>');
114
- e.suggestions = [
115
- { desc: 'remove', range: [e.startIndex - 1, e.endIndex], text: '' },
116
- { desc: 'comment', range: [e.startIndex, e.startIndex], text: '# ' },
117
- ];
118
- return e;
119
- }));
120
- }
121
- else {
122
- errors.push((0, lint_1.generateForSelf)(this, rect, 'invalid-imagemap', '<imagemap> without an image'));
123
143
  }
124
- return errors;
125
- }
126
- /** @private */
127
- print() {
128
- return super.print({ sep: '\n' });
129
- }
130
- insertAt(token, i) {
131
- const { image } = this;
132
- if (!image && (typeof token === 'string' || token.type === 'imagemap-link' || token.type === 'text')) {
133
- throw new Error('Missing a valid image!');
144
+ /** @private */
145
+ lint(start = this.getAbsoluteIndex(), re) {
146
+ const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start);
147
+ if (this.image) {
148
+ errors.push(...this.childNodes.filter(child => {
149
+ const str = child.toString().trim();
150
+ return child.type === 'noinclude' && str && !str.startsWith('#');
151
+ }).map(child => {
152
+ const e = (0, lint_1.generateForChild)(child, rect, 'invalid-imagemap', 'invalid link in <imagemap>');
153
+ e.suggestions = [
154
+ { desc: 'remove', range: [e.startIndex - 1, e.endIndex], text: '' },
155
+ { desc: 'comment', range: [e.startIndex, e.startIndex], text: '# ' },
156
+ ];
157
+ return e;
158
+ }));
159
+ }
160
+ else {
161
+ errors.push((0, lint_1.generateForSelf)(this, rect, 'invalid-imagemap', '<imagemap> without an image'));
162
+ }
163
+ return errors;
134
164
  }
135
- else if (image && typeof token !== 'string' && token.type === 'imagemap-image') {
136
- throw new RangeError('Already have a valid image!');
165
+ insertAt(token, i) {
166
+ const { image } = this;
167
+ if (!image && (typeof token === 'string' || token.type === 'imagemap-link' || token.type === 'text')) {
168
+ throw new Error('Missing a valid image!');
169
+ }
170
+ else if (image && typeof token !== 'string' && token.type === 'imagemap-image') {
171
+ throw new RangeError('Already have a valid image!');
172
+ }
173
+ return super.insertAt(token, i);
137
174
  }
138
- return super.insertAt(token, i);
139
- }
140
- /**
141
- * @override
142
- * @param i position of the child node /移除位置
143
- * @throws `Error` 禁止移除图片
144
- */
145
- removeAt(i) {
146
- if (this.childNodes[i]?.type === 'imagemap-image') {
147
- throw new Error('Do not remove the image in <imagemap>!');
175
+ /**
176
+ * @override
177
+ * @param i position of the child node /移除位置
178
+ * @throws `Error` 禁止移除图片
179
+ */
180
+ removeAt(i) {
181
+ if (this.childNodes[i]?.type === 'imagemap-image') {
182
+ throw new Error('Do not remove the image in <imagemap>!');
183
+ }
184
+ return super.removeAt(i);
148
185
  }
149
- return super.removeAt(i);
150
- }
151
- cloneNode() {
152
- const cloned = this.cloneChildNodes();
153
- return debug_1.Shadow.run(() => {
186
+ cloneNode() {
154
187
  // @ts-expect-error abstract class
155
- const token = new ImagemapToken(undefined, this.getAttribute('config'));
156
- token.append(...cloned);
157
- return token;
158
- });
159
- }
160
- }
188
+ return (0, html_1.cloneNode)(this, () => new ImagemapToken(undefined, this.getAttribute('config')));
189
+ }
190
+ };
191
+ return ImagemapToken = _classThis;
192
+ })();
161
193
  exports.ImagemapToken = ImagemapToken;
162
194
  constants_1.classes['ImagemapToken'] = __filename;
@@ -16,13 +16,13 @@ export declare abstract class ImagemapLinkToken extends Token {
16
16
  abstract get firstChild(): AstText;
17
17
  abstract get lastChild(): NoincludeToken;
18
18
  abstract get parentNode(): ImagemapToken | undefined;
19
- abstract get previousSibling(): GalleryImageToken | this | NoincludeToken | AstText;
19
+ abstract get previousSibling(): GalleryImageToken | this | NoincludeToken | AstText | undefined;
20
20
  abstract get nextSibling(): this | NoincludeToken | AstText | undefined;
21
21
  abstract get children(): [LinkToken | ExtLinkToken, NoincludeToken];
22
22
  abstract get firstElementChild(): LinkToken | ExtLinkToken;
23
23
  abstract get lastElementChild(): NoincludeToken;
24
24
  abstract get parentElement(): ImagemapToken | undefined;
25
- abstract get previousElementSibling(): GalleryImageToken | this | NoincludeToken;
25
+ abstract get previousElementSibling(): GalleryImageToken | this | NoincludeToken | undefined;
26
26
  abstract get nextElementSibling(): this | NoincludeToken | undefined;
27
27
  get type(): 'imagemap-link';
28
28
  /** internal or external link / 内外链接 */
package/dist/src/index.js CHANGED
@@ -25,13 +25,14 @@
25
25
  // b: TableToken
26
26
  // c: CommentToke
27
27
  // d: ListToken
28
- // e: ExtToken
29
- // f: MagicLinkToken inside ImageParameterToken
28
+ // e: ExtToken或OnlyincludeToken
29
+ // f: ImageParameterToken内的MagicLinkToken
30
+ // g: TranslateToken
30
31
  // h: HeadingToken
31
32
  // i: RFC/PMID/ISBN
32
33
  // l: LinkToken
33
- // m: `{{fullurl:}}`、`{{canonicalurl:}}`或`{{filepath:}}`
34
- // n: NoIncludeTokenIncludeToken
34
+ // m: `{{server}}`、`{{fullurl:}}`、`{{canonicalurl:}}`或`{{filepath:}}`
35
+ // n: NoIncludeTokenIncludeToken、DoubleUnderscoreToken或`{{#vardefine:}}`
35
36
  // o: RedirectToken
36
37
  // q: QuoteToken
37
38
  // r: HrToken
@@ -39,7 +40,7 @@
39
40
  // t: ArgToken或TranscludeToken
40
41
  // u: `__toc__`
41
42
  // v: ConverterToken
42
- // w: ExtLinkToken
43
+ // w: ExtLinkToken或free-ext-link
43
44
  // x: HtmlToken
44
45
  var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
45
46
  var useValue = arguments.length > 2;
@@ -89,6 +90,7 @@ const element_1 = require("../lib/element");
89
90
  const text_1 = require("../lib/text");
90
91
  /* NOT FOR BROWSER */
91
92
  const strict_1 = __importDefault(require("assert/strict"));
93
+ const html_1 = require("../util/html");
92
94
  const ranges_1 = require("../lib/ranges");
93
95
  const range_1 = require("../lib/range");
94
96
  const readOnly_1 = require("../mixin/readOnly");
@@ -173,6 +175,7 @@ let Token = (() => {
173
175
  'td-inner',
174
176
  'ext-inner',
175
177
  'list-range',
178
+ 'translate-inner',
176
179
  ];
177
180
  if (!plainTypes.includes(value)) {
178
181
  throw new RangeError(`"${value}" is not a valid type for ${this.constructor.name}!`);
@@ -194,7 +197,7 @@ let Token = (() => {
194
197
  }
195
198
  /** @private */
196
199
  parseOnce(n = this.#stage, include = false, tidy) {
197
- if (n < this.#stage || this.length === 0 || !this.getAttribute('plain')) {
200
+ if (n < this.#stage || this.length === 0 || !this.isPlain()) {
198
201
  return this;
199
202
  }
200
203
  else if (this.#stage >= constants_1.MAX_STAGE) {
@@ -415,10 +418,12 @@ let Token = (() => {
415
418
  }
416
419
  }
417
420
  /** @private */
421
+ isPlain() {
422
+ return this.constructor === Token;
423
+ }
424
+ /** @private */
418
425
  getAttribute(key) {
419
426
  switch (key) {
420
- case 'plain':
421
- return (this.constructor === Token);
422
427
  case 'config':
423
428
  return this.#config;
424
429
  case 'include':
@@ -480,7 +485,7 @@ let Token = (() => {
480
485
  /* NOT FOR BROWSER */
481
486
  const e = new Event('insert', { bubbles: true });
482
487
  this.dispatchEvent(e, { type: 'insert', position: i < 0 ? i + this.length - 1 : i });
483
- if (type !== 'list-range' && constructor === Token && this.getAttribute('plain')) {
488
+ if (type !== 'list-range' && constructor === Token && this.isPlain()) {
484
489
  index_1.default.warn('You are inserting a plain token as a child of another plain token. '
485
490
  + 'Consider calling Token.flatten method afterwards.');
486
491
  }
@@ -619,7 +624,7 @@ let Token = (() => {
619
624
  }
620
625
  }
621
626
  /** @private */
622
- protectChildren(...args) {
627
+ protectChildren(args) {
623
628
  this.#protectedChildren.push(...new ranges_1.Ranges(args));
624
629
  }
625
630
  /** @private */
@@ -767,8 +772,8 @@ let Token = (() => {
767
772
  token.setAttribute('stage', this.#stage);
768
773
  token.setAttribute('include', Boolean(this.#include));
769
774
  token.setAttribute('name', this.name);
770
- token.append(...cloned);
771
- token.protectChildren(...this.#protectedChildren);
775
+ token.safeAppend(cloned);
776
+ token.protectChildren(this.#protectedChildren);
772
777
  return token;
773
778
  });
774
779
  }
@@ -833,10 +838,11 @@ let Token = (() => {
833
838
  * 合并普通节点的普通子节点
834
839
  */
835
840
  flatten() {
836
- if (this.getAttribute('plain')) {
841
+ if (this.isPlain()) {
837
842
  for (const child of this.childNodes) {
838
- if (child.type !== 'text' && child.getAttribute('plain')) {
839
- child.replaceWith(...child.childNodes);
843
+ if (child.type !== 'text' && child.isPlain()) {
844
+ child.insertAdjacent(child.childNodes, 1);
845
+ child.remove();
840
846
  }
841
847
  }
842
848
  }
@@ -851,20 +857,38 @@ let Token = (() => {
851
857
  return this.toHtml();
852
858
  }
853
859
  /**
854
- * Build lists
855
- *
856
860
  * 构建列表
861
+ * @param recursive 是否递归
857
862
  */
858
- buildLists() {
863
+ #buildLists(recursive) {
859
864
  for (let i = 0; i < this.length; i++) {
860
865
  const child = this.childNodes[i];
861
866
  if (child.is('list') || child.is('dd')) {
862
867
  child.getRange();
863
868
  }
864
- else if (child.type !== 'text') {
865
- child.buildLists();
869
+ else if (recursive && child.type !== 'text') {
870
+ child.#buildLists(true);
871
+ }
872
+ }
873
+ }
874
+ /**
875
+ * Build lists
876
+ *
877
+ * 构建列表
878
+ */
879
+ buildLists() {
880
+ this.#buildLists(true);
881
+ }
882
+ /** @private */
883
+ toHtmlInternal(opt) {
884
+ for (const child of this.childNodes) {
885
+ if (child.type === 'text') {
886
+ child.removeBlankLines();
866
887
  }
867
888
  }
889
+ this.#buildLists();
890
+ this.normalize();
891
+ return (0, html_1.html)(this.childNodes, '', opt);
868
892
  }
869
893
  };
870
894
  })();
@@ -1,7 +1,6 @@
1
- import Parser from '../../index';
2
1
  import { Token } from '../index';
3
2
  import { AtomToken } from '../atom';
4
- import type { LintError, AST } from '../../base';
3
+ import type { Config, LintError, AST } from '../../base';
5
4
  import type { Title } from '../../lib/title';
6
5
  /**
7
6
  * internal link
@@ -34,7 +33,7 @@ export declare abstract class LinkBaseToken extends Token {
34
33
  * @param linkText 链接显示文字
35
34
  * @param delimiter `|`
36
35
  */
37
- constructor(link: string, linkText?: string, config?: Parser.Config, accum?: Token[], delimiter?: string);
36
+ constructor(link: string, linkText?: string, config?: Config, accum?: Token[], delimiter?: string);
38
37
  cloneNode(): this;
39
38
  /**
40
39
  * Set the link target
@@ -42,12 +42,13 @@ const lint_1 = require("../../util/lint");
42
42
  const constants_1 = require("../../util/constants");
43
43
  const string_1 = require("../../util/string");
44
44
  const rect_1 = require("../../lib/rect");
45
- const index_1 = __importDefault(require("../../index"));
46
- const index_2 = require("../index");
45
+ const padded_1 = require("../../mixin/padded");
46
+ const index_1 = require("../index");
47
47
  const atom_1 = require("../atom");
48
48
  /* NOT FOR BROWSER */
49
49
  const debug_1 = require("../../util/debug");
50
50
  const noEscape_1 = require("../../mixin/noEscape");
51
+ const index_2 = __importDefault(require("../../index"));
51
52
  /* NOT FOR BROWSER END */
52
53
  /**
53
54
  * 是否为普通内链
@@ -61,11 +62,11 @@ const isLink = (type) => type === 'redirect-target' || type === 'link';
61
62
  * @classdesc `{childNodes: [AtomToken, ...Token[]]}`
62
63
  */
63
64
  let LinkBaseToken = (() => {
64
- let _classDecorators = [noEscape_1.noEscape];
65
+ let _classDecorators = [noEscape_1.noEscape, (0, padded_1.padded)('[[')];
65
66
  let _classDescriptor;
66
67
  let _classExtraInitializers = [];
67
68
  let _classThis;
68
- let _classSuper = index_2.Token;
69
+ let _classSuper = index_1.Token;
69
70
  var LinkBaseToken = class extends _classSuper {
70
71
  static { _classThis = this; }
71
72
  static {
@@ -118,7 +119,7 @@ let LinkBaseToken = (() => {
118
119
  * @param linkText 链接显示文字
119
120
  * @param delimiter `|`
120
121
  */
121
- constructor(link, linkText, config = index_1.default.getConfig(), accum = [], delimiter = '|') {
122
+ constructor(link, linkText, config, accum = [], delimiter = '|') {
122
123
  super(undefined, config, accum, {
123
124
  AtomToken: 0, Token: 1,
124
125
  });
@@ -126,7 +127,7 @@ let LinkBaseToken = (() => {
126
127
  'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '',
127
128
  }));
128
129
  if (linkText !== undefined) {
129
- const inner = new index_2.Token(linkText, config, accum, {
130
+ const inner = new index_1.Token(linkText, config, accum, {
130
131
  'Stage-5': ':', QuoteToken: ':', ConverterToken: ':',
131
132
  });
132
133
  inner.type = 'link-text';
@@ -200,10 +201,7 @@ let LinkBaseToken = (() => {
200
201
  }
201
202
  /** @private */
202
203
  getAttribute(key) {
203
- if (key === 'title') {
204
- return this.#title;
205
- }
206
- return key === 'padding' ? 2 : super.getAttribute(key);
204
+ return key === 'title' ? this.#title : super.getAttribute(key);
207
205
  }
208
206
  /** @private */
209
207
  getGaps(i) {
@@ -272,7 +270,7 @@ let LinkBaseToken = (() => {
272
270
  return debug_1.Shadow.run(() => {
273
271
  const C = this.constructor, token = new C('', undefined, this.getAttribute('config'));
274
272
  token.firstChild.safeReplaceWith(link);
275
- token.append(...linkText);
273
+ token.safeAppend(linkText);
276
274
  return token;
277
275
  });
278
276
  }
@@ -283,10 +281,10 @@ let LinkBaseToken = (() => {
283
281
  * @param link link target / 链接目标
284
282
  */
285
283
  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, [], {
284
+ const config = this.getAttribute('config'), { childNodes } = index_2.default.parse(link, this.getAttribute('include'), 2, config), token = debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'link-target', config, [], {
287
285
  'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '',
288
286
  }));
289
- token.append(...childNodes);
287
+ token.safeAppend(childNodes);
290
288
  this.firstChild.safeReplaceWith(token);
291
289
  }
292
290
  /**
@@ -313,7 +311,7 @@ let LinkBaseToken = (() => {
313
311
  this.childNodes[1]?.remove();
314
312
  return;
315
313
  }
316
- const root = index_1.default
314
+ const root = index_2.default
317
315
  .parse(linkStr, this.getAttribute('include'), undefined, this.getAttribute('config'));
318
316
  if (this.length === 1) {
319
317
  root.type = 'link-text';
@@ -323,7 +321,7 @@ let LinkBaseToken = (() => {
323
321
  this.insertAt(root);
324
322
  }
325
323
  else {
326
- this.lastChild.replaceChildren(...root.childNodes);
324
+ this.lastChild.safeReplaceChildren(root.childNodes);
327
325
  }
328
326
  }
329
327
  /** @private */
@@ -1,7 +1,6 @@
1
- import Parser from '../../index';
2
1
  import { LinkBaseToken } from './base';
3
2
  import { ImageParameterToken } from '../imageParameter';
4
- import type { LintError, AST } from '../../base';
3
+ import type { Config, LintError, AST } from '../../base';
5
4
  import type { Token, AtomToken } from '../../internal';
6
5
  import { Title } from '../../lib/title';
7
6
  /**
@@ -42,7 +41,7 @@ export declare abstract class FileToken extends LinkBaseToken {
42
41
  * @param text 图片参数
43
42
  * @param delimiter `|`
44
43
  */
45
- constructor(link: string, text?: string, config?: Parser.Config, accum?: Token[], delimiter?: string);
44
+ constructor(link: string, text?: string, config?: Config, accum?: Token[], delimiter?: string);
46
45
  /**
47
46
  * Get all image parameter tokens
48
47
  *
@@ -112,14 +112,14 @@ class FileToken extends base_1.LinkBaseToken {
112
112
  * @param text 图片参数
113
113
  * @param delimiter `|`
114
114
  */
115
- constructor(link, text, config = index_1.default.getConfig(), accum = [], delimiter = '|') {
115
+ constructor(link, text, config, accum = [], delimiter = '|') {
116
116
  super(link, undefined, config, accum, delimiter);
117
117
  /* NOT FOR BROWSER */
118
118
  this.setAttribute('acceptable', { AtomToken: 0, ImageParameterToken: '1:' });
119
119
  /* NOT FOR BROWSER END */
120
120
  const { extension } = this.getTitle(true, true);
121
121
  /-\{|\}-|\|/gu; // eslint-disable-line @typescript-eslint/no-unused-expressions
122
- this.append(...explode(text).map(
122
+ this.safeAppend(explode(text).map(
123
123
  // @ts-expect-error abstract class
124
124
  (part) => new imageParameter_1.ImageParameterToken(part, extension, config, accum)));
125
125
  }
@@ -363,7 +363,7 @@ class FileToken extends base_1.LinkBaseToken {
363
363
  if (free) {
364
364
  const { childNodes } = index_1.default
365
365
  .parse(value, this.getAttribute('include'), undefined, config);
366
- parameter.replaceChildren(...childNodes);
366
+ parameter.safeReplaceChildren(childNodes);
367
367
  }
368
368
  this.insertAt(parameter);
369
369
  }