wikiparser-node 1.4.2 → 1.4.3

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 (103) hide show
  1. package/dist/addon/table.js +5 -1
  2. package/dist/base.d.ts +6 -1
  3. package/dist/index.d.ts +0 -2
  4. package/dist/index.js +3 -3
  5. package/dist/lib/element.d.ts +3 -2
  6. package/dist/lib/element.js +20 -13
  7. package/dist/lib/node.js +13 -10
  8. package/dist/lib/text.js +3 -3
  9. package/dist/lib/title.js +4 -12
  10. package/dist/mixin/attributesParent.d.ts +32 -2
  11. package/dist/mixin/attributesParent.js +14 -25
  12. package/dist/mixin/fixed.d.ts +2 -1
  13. package/dist/mixin/fixed.js +3 -1
  14. package/dist/mixin/flagsParent.d.ts +28 -17
  15. package/dist/mixin/flagsParent.js +12 -25
  16. package/dist/mixin/magicLinkParent.d.ts +14 -8
  17. package/dist/mixin/magicLinkParent.js +7 -8
  18. package/dist/mixin/singleLine.d.ts +2 -1
  19. package/dist/mixin/singleLine.js +3 -2
  20. package/dist/mixin/sol.d.ts +2 -4
  21. package/dist/mixin/sol.js +8 -6
  22. package/dist/mixin/syntax.d.ts +5 -2
  23. package/dist/mixin/syntax.js +14 -18
  24. package/dist/parser/links.js +1 -3
  25. package/dist/src/arg.d.ts +4 -4
  26. package/dist/src/arg.js +4 -4
  27. package/dist/src/attribute.d.ts +9 -7
  28. package/dist/src/attribute.js +271 -218
  29. package/dist/src/attributes.d.ts +3 -3
  30. package/dist/src/attributes.js +0 -1
  31. package/dist/src/converter.d.ts +7 -2
  32. package/dist/src/converter.js +113 -64
  33. package/dist/src/converterFlags.d.ts +5 -5
  34. package/dist/src/converterFlags.js +0 -1
  35. package/dist/src/converterRule.d.ts +5 -5
  36. package/dist/src/converterRule.js +0 -1
  37. package/dist/src/extLink.d.ts +7 -2
  38. package/dist/src/extLink.js +159 -110
  39. package/dist/src/gallery.d.ts +5 -5
  40. package/dist/src/gallery.js +0 -1
  41. package/dist/src/heading.d.ts +8 -8
  42. package/dist/src/heading.js +172 -125
  43. package/dist/src/html.d.ts +8 -5
  44. package/dist/src/html.js +263 -214
  45. package/dist/src/imageParameter.d.ts +2 -2
  46. package/dist/src/imageParameter.js +1 -0
  47. package/dist/src/imagemap.d.ts +5 -5
  48. package/dist/src/imagemap.js +4 -10
  49. package/dist/src/imagemapLink.d.ts +7 -4
  50. package/dist/src/imagemapLink.js +75 -26
  51. package/dist/src/index.js +3 -4
  52. package/dist/src/link/base.d.ts +2 -2
  53. package/dist/src/link/base.js +1 -4
  54. package/dist/src/link/file.d.ts +1 -1
  55. package/dist/src/link/file.js +0 -1
  56. package/dist/src/link/galleryImage.d.ts +2 -1
  57. package/dist/src/link/galleryImage.js +136 -88
  58. package/dist/src/link/index.js +0 -1
  59. package/dist/src/magicLink.d.ts +11 -3
  60. package/dist/src/magicLink.js +170 -120
  61. package/dist/src/nested.d.ts +5 -5
  62. package/dist/src/nested.js +1 -0
  63. package/dist/src/nowiki/base.d.ts +6 -2
  64. package/dist/src/nowiki/base.js +79 -28
  65. package/dist/src/nowiki/comment.d.ts +0 -2
  66. package/dist/src/nowiki/comment.js +0 -9
  67. package/dist/src/nowiki/doubleUnderscore.js +88 -38
  68. package/dist/src/nowiki/hr.d.ts +1 -4
  69. package/dist/src/nowiki/hr.js +53 -4
  70. package/dist/src/nowiki/index.d.ts +2 -2
  71. package/dist/src/nowiki/index.js +1 -0
  72. package/dist/src/nowiki/list.d.ts +1 -4
  73. package/dist/src/nowiki/list.js +88 -39
  74. package/dist/src/nowiki/listBase.d.ts +1 -1
  75. package/dist/src/nowiki/listBase.js +52 -2
  76. package/dist/src/nowiki/quote.d.ts +3 -3
  77. package/dist/src/nowiki/quote.js +102 -54
  78. package/dist/src/paramTag/index.d.ts +5 -5
  79. package/dist/src/paramTag/index.js +2 -1
  80. package/dist/src/parameter.d.ts +11 -8
  81. package/dist/src/parameter.js +225 -176
  82. package/dist/src/pre.d.ts +5 -5
  83. package/dist/src/pre.js +1 -0
  84. package/dist/src/syntax.d.ts +6 -0
  85. package/dist/src/syntax.js +74 -23
  86. package/dist/src/table/base.d.ts +6 -3
  87. package/dist/src/table/base.js +100 -49
  88. package/dist/src/table/index.d.ts +6 -3
  89. package/dist/src/table/index.js +5 -9
  90. package/dist/src/table/td.d.ts +9 -5
  91. package/dist/src/table/td.js +270 -217
  92. package/dist/src/table/tr.d.ts +4 -4
  93. package/dist/src/table/tr.js +1 -0
  94. package/dist/src/tagPair/ext.d.ts +6 -3
  95. package/dist/src/tagPair/ext.js +168 -118
  96. package/dist/src/tagPair/include.d.ts +2 -4
  97. package/dist/src/tagPair/include.js +0 -8
  98. package/dist/src/tagPair/index.d.ts +1 -1
  99. package/dist/src/tagPair/index.js +115 -66
  100. package/dist/src/transclude.d.ts +3 -3
  101. package/dist/src/transclude.js +4 -9
  102. package/dist/util/debug.js +0 -2
  103. 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
  Object.defineProperty(exports, "__esModule", { value: true });
3
37
  exports.HeadingToken = void 0;
4
38
  const lint_1 = require("../util/lint");
@@ -9,135 +43,148 @@ const sol_1 = require("../mixin/sol");
9
43
  const index_1 = require("../index");
10
44
  const index_2 = require("./index");
11
45
  const syntax_1 = require("./syntax");
12
- /* NOT FOR BROWSER END */
13
46
  /**
14
47
  * 章节标题
15
48
  * @classdesc `{childNodes: [Token, SyntaxToken]}`
16
49
  */
17
- class HeadingToken extends (0, sol_1.sol)((0, fixed_1.fixedToken)(index_2.Token)) {
18
- type = 'heading';
19
- #level;
20
- /** 标题格式的等号 */
21
- get #equals() {
22
- return '='.repeat(this.level);
23
- }
24
- /** 标题层级 */
25
- get level() {
26
- return this.#level;
27
- }
28
- /* NOT FOR BROWSER */
29
- set level(n) {
30
- this.setLevel(n);
31
- }
32
- /** 内部wikitext */
33
- get innerText() {
34
- return this.firstChild.text();
35
- }
36
- /** @throws `Error` 首尾包含`=` */
37
- set innerText(text) {
38
- if (text.length > 1 && text.startsWith('=') && text.endsWith('=')) {
39
- throw new Error('修改标题层级请使用 setLevel 方法!');
50
+ let HeadingToken = (() => {
51
+ let _classDecorators = [fixed_1.fixedToken, sol_1.sol];
52
+ let _classDescriptor;
53
+ let _classExtraInitializers = [];
54
+ let _classThis;
55
+ let _classSuper = index_2.Token;
56
+ var HeadingToken = class extends _classSuper {
57
+ static { _classThis = this; }
58
+ static {
59
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
60
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
61
+ HeadingToken = _classThis = _classDescriptor.value;
62
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
63
+ __runInitializers(_classThis, _classExtraInitializers);
40
64
  }
41
- const { childNodes } = index_1.default.parse(text, this.getAttribute('include'), undefined, this.getAttribute('config'));
42
- this.firstChild.replaceChildren(...childNodes);
43
- }
44
- /* NOT FOR BROWSER END */
45
- /**
46
- * @param level 标题层级
47
- * @param input 标题文字
48
- */
49
- constructor(level, input, config = index_1.default.getConfig(), accum = []) {
50
- super(undefined, config, accum);
51
- this.#level = level;
52
- const token = new index_2.Token(input[0], config, accum);
53
- token.type = 'heading-title';
54
- token.setAttribute('stage', 2);
55
- const trail = new syntax_1.SyntaxToken(input[1], /^[^\S\n]*$/u, 'heading-trail', config, accum, {
56
- 'Stage-1': ':', '!ExtToken': '',
57
- });
58
- this.append(token, trail);
59
- }
60
- /** @private */
61
- toString() {
62
- const equals = this.#equals;
63
- return `${this.prependNewLine()}${equals}${String(this.firstChild)}${equals}${String(this.lastChild)}`;
64
- }
65
- /** @override */
66
- text() {
67
- const equals = this.#equals;
68
- return `${this.prependNewLine()}${equals}${this.firstChild.text()}${equals}`;
69
- }
70
- /** @private */
71
- getAttribute(key) {
72
- return key === 'padding'
73
- ? super.getAttribute('padding') + this.level
74
- : super.getAttribute(key);
75
- }
76
- /** @private */
77
- getGaps() {
78
- return this.level;
79
- }
80
- /** @override */
81
- lint(start = this.getAbsoluteIndex()) {
82
- const errors = super.lint(start), { firstChild, level } = this, innerStr = String(firstChild), quotes = firstChild.childNodes.filter((node) => node.type === 'quote'), boldQuotes = quotes.filter(({ bold }) => bold), italicQuotes = quotes.filter(({ italic }) => italic);
83
- let rect;
84
- if (this.level === 1) {
85
- rect = { start, ...this.getRootNode().posFromIndex(start) };
86
- errors.push((0, lint_1.generateForChild)(firstChild, rect, '<h1>'));
87
- }
88
- if (innerStr.startsWith('=') || innerStr.endsWith('=')) {
89
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
90
- errors.push((0, lint_1.generateForChild)(firstChild, rect, index_1.default.msg('unbalanced $1 in a section header', '"="')));
91
- }
92
- if (this.closest('html-attrs, table-attrs')) {
93
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
94
- errors.push((0, lint_1.generateForSelf)(this, rect, 'section header in a HTML tag'));
95
- }
96
- if (boldQuotes.length % 2) {
97
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
98
- errors.push((0, lint_1.generateForChild)(boldQuotes[boldQuotes.length - 1], { ...rect, start: start + level, left: rect.left + level }, index_1.default.msg('unbalanced $1 in a section header', 'bold apostrophes')));
99
- }
100
- if (italicQuotes.length % 2) {
101
- rect ??= { start, ...this.getRootNode().posFromIndex(start) };
102
- errors.push((0, lint_1.generateForChild)(italicQuotes[italicQuotes.length - 1], { start: start + level }, index_1.default.msg('unbalanced $1 in a section header', 'italic apostrophes')));
103
- }
104
- return errors;
105
- }
106
- /** @override */
107
- print() {
108
- const equals = this.#equals;
109
- return super.print({ pre: equals, sep: equals });
110
- }
111
- /** @override */
112
- json() {
113
- return {
114
- ...super.json(),
115
- level: this.level,
116
- };
117
- }
118
- /* NOT FOR BROWSER */
119
- /** @override */
120
- cloneNode() {
121
- const [title, trail] = this.cloneChildNodes();
122
- return debug_1.Shadow.run(() => {
123
- // @ts-expect-error abstract class
124
- const token = new HeadingToken(this.level, [], this.getAttribute('config'));
125
- token.firstChild.safeReplaceWith(title);
126
- token.lastChild.safeReplaceWith(trail);
127
- return token;
128
- });
129
- }
130
- /**
131
- * 设置标题层级
132
- * @param n 标题层级
133
- */
134
- setLevel(n) {
135
- this.#level = Math.min(Math.max(n, 1), 6);
136
- }
137
- /** 移除标题后的不可见内容 */
138
- removeTrail() {
139
- this.lastChild.replaceChildren();
140
- }
141
- }
65
+ type = 'heading';
66
+ #level;
67
+ /* NOT FOR BROWSER END */
68
+ /** 标题格式的等号 */
69
+ get #equals() {
70
+ return '='.repeat(this.level);
71
+ }
72
+ /** 标题层级 */
73
+ get level() {
74
+ return this.#level;
75
+ }
76
+ /* NOT FOR BROWSER */
77
+ set level(n) {
78
+ this.setLevel(n);
79
+ }
80
+ /** 内部wikitext */
81
+ get innerText() {
82
+ return this.firstChild.text();
83
+ }
84
+ /** @throws `Error` 首尾包含`=` */
85
+ set innerText(text) {
86
+ if (text.length > 1 && text.startsWith('=') && text.endsWith('=')) {
87
+ throw new Error('修改标题层级请使用 setLevel 方法!');
88
+ }
89
+ const { childNodes } = index_1.default.parse(text, this.getAttribute('include'), undefined, this.getAttribute('config'));
90
+ this.firstChild.replaceChildren(...childNodes);
91
+ }
92
+ /* NOT FOR BROWSER END */
93
+ /**
94
+ * @param level 标题层级
95
+ * @param input 标题文字
96
+ */
97
+ constructor(level, input, config = index_1.default.getConfig(), accum = []) {
98
+ super(undefined, config, accum);
99
+ this.#level = level;
100
+ const token = new index_2.Token(input[0], config, accum);
101
+ token.type = 'heading-title';
102
+ token.setAttribute('stage', 2);
103
+ const trail = new syntax_1.SyntaxToken(input[1], /^[^\S\n]*$/u, 'heading-trail', config, accum, {
104
+ 'Stage-1': ':', '!ExtToken': '',
105
+ });
106
+ this.append(token, trail);
107
+ }
108
+ /** @private */
109
+ toString() {
110
+ const equals = this.#equals;
111
+ return `${equals}${String(this.firstChild)}${equals}${String(this.lastChild)}`;
112
+ }
113
+ /** @override */
114
+ text() {
115
+ const equals = this.#equals;
116
+ return `${equals}${this.firstChild.text()}${equals}`;
117
+ }
118
+ /** @private */
119
+ getAttribute(key) {
120
+ return key === 'padding' ? this.level : super.getAttribute(key);
121
+ }
122
+ /** @private */
123
+ getGaps() {
124
+ return this.level;
125
+ }
126
+ /** @override */
127
+ lint(start = this.getAbsoluteIndex()) {
128
+ const errors = super.lint(start), { firstChild, level } = this, innerStr = String(firstChild), quotes = firstChild.childNodes.filter((node) => node.type === 'quote'), boldQuotes = quotes.filter(({ bold }) => bold), italicQuotes = quotes.filter(({ italic }) => italic);
129
+ let rect;
130
+ if (this.level === 1) {
131
+ rect = { start, ...this.getRootNode().posFromIndex(start) };
132
+ errors.push((0, lint_1.generateForChild)(firstChild, rect, '<h1>'));
133
+ }
134
+ if (innerStr.startsWith('=') || innerStr.endsWith('=')) {
135
+ rect ??= { start, ...this.getRootNode().posFromIndex(start) };
136
+ errors.push((0, lint_1.generateForChild)(firstChild, rect, index_1.default.msg('unbalanced $1 in a section header', '"="')));
137
+ }
138
+ if (this.closest('html-attrs, table-attrs')) {
139
+ rect ??= { start, ...this.getRootNode().posFromIndex(start) };
140
+ errors.push((0, lint_1.generateForSelf)(this, rect, 'section header in a HTML tag'));
141
+ }
142
+ if (boldQuotes.length % 2) {
143
+ rect ??= { start, ...this.getRootNode().posFromIndex(start) };
144
+ errors.push((0, lint_1.generateForChild)(boldQuotes[boldQuotes.length - 1], { ...rect, start: start + level, left: rect.left + level }, index_1.default.msg('unbalanced $1 in a section header', 'bold apostrophes')));
145
+ }
146
+ if (italicQuotes.length % 2) {
147
+ rect ??= { start, ...this.getRootNode().posFromIndex(start) };
148
+ errors.push((0, lint_1.generateForChild)(italicQuotes[italicQuotes.length - 1], { start: start + level }, index_1.default.msg('unbalanced $1 in a section header', 'italic apostrophes')));
149
+ }
150
+ return errors;
151
+ }
152
+ /** @override */
153
+ print() {
154
+ const equals = this.#equals;
155
+ return super.print({ pre: equals, sep: equals });
156
+ }
157
+ /** @override */
158
+ json() {
159
+ const json = super.json();
160
+ json['level'] = this.level;
161
+ return json;
162
+ }
163
+ /* NOT FOR BROWSER */
164
+ /** @override */
165
+ cloneNode() {
166
+ const [title, trail] = this.cloneChildNodes();
167
+ return debug_1.Shadow.run(() => {
168
+ // @ts-expect-error abstract class
169
+ const token = new HeadingToken(this.level, [], this.getAttribute('config'));
170
+ token.firstChild.safeReplaceWith(title);
171
+ token.lastChild.safeReplaceWith(trail);
172
+ return token;
173
+ });
174
+ }
175
+ /**
176
+ * 设置标题层级
177
+ * @param n 标题层级
178
+ */
179
+ setLevel(n) {
180
+ this.#level = Math.min(Math.max(n, 1), 6);
181
+ }
182
+ /** 移除标题后的不可见内容 */
183
+ removeTrail() {
184
+ this.lastChild.replaceChildren();
185
+ }
186
+ };
187
+ return HeadingToken = _classThis;
188
+ })();
142
189
  exports.HeadingToken = HeadingToken;
143
190
  constants_1.classes['HeadingToken'] = __filename;
@@ -1,19 +1,23 @@
1
1
  import Parser from '../index';
2
2
  import { Token } from './index';
3
- import type { LintError } from '../base';
3
+ import type { LintError, AST } from '../base';
4
4
  import type { AttributesParentBase } from '../mixin/attributesParent';
5
5
  import type { AttributesToken } from '../internal';
6
6
  export interface HtmlToken extends AttributesParentBase {
7
7
  }
8
+ /**
9
+ * HTML标签
10
+ * @classdesc `{childNodes: [AttributesToken]}`
11
+ */
8
12
  export declare abstract class HtmlToken extends Token {
9
13
  #private;
10
14
  readonly type = "html";
11
15
  readonly name: string;
12
16
  readonly childNodes: readonly [AttributesToken];
13
- abstract get children(): [AttributesToken];
14
17
  abstract get firstChild(): AttributesToken;
15
- abstract get firstElementChild(): AttributesToken;
16
18
  abstract get lastChild(): AttributesToken;
19
+ abstract get children(): [AttributesToken];
20
+ abstract get firstElementChild(): AttributesToken;
17
21
  abstract get lastElementChild(): AttributesToken;
18
22
  /** 是否是闭合标签 */
19
23
  get closing(): boolean;
@@ -44,7 +48,7 @@ export declare abstract class HtmlToken extends Token {
44
48
  /** @override */
45
49
  print(): string;
46
50
  /** @override */
47
- json(): object;
51
+ json(): AST;
48
52
  /** @override */
49
53
  cloneNode(): this;
50
54
  /**
@@ -59,4 +63,3 @@ export declare abstract class HtmlToken extends Token {
59
63
  */
60
64
  fix(): void;
61
65
  }
62
- export {};