wikiparser-node 1.21.2 → 1.21.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 (70) hide show
  1. package/README.md +3 -5
  2. package/bundle/bundle-es8.min.js +25 -25
  3. package/bundle/bundle-lsp.min.js +26 -26
  4. package/bundle/bundle.min.js +25 -25
  5. package/dist/base.d.mts +6 -1
  6. package/dist/base.d.ts +6 -1
  7. package/dist/index.d.ts +2 -2
  8. package/dist/index.js +10 -1
  9. package/dist/lib/element.js +2 -1
  10. package/dist/lib/lintConfig.d.ts +13 -0
  11. package/dist/lib/lintConfig.js +161 -0
  12. package/dist/lib/lsp.js +6 -4
  13. package/dist/lib/node.js +646 -606
  14. package/dist/lib/text.js +4 -0
  15. package/dist/mixin/attributesParent.d.ts +6 -6
  16. package/dist/mixin/attributesParent.js +4 -4
  17. package/dist/mixin/cached.d.ts +5 -0
  18. package/dist/mixin/cached.js +22 -0
  19. package/dist/mixin/clone.d.ts +5 -0
  20. package/dist/mixin/clone.js +23 -0
  21. package/dist/mixin/hidden.js +68 -18
  22. package/dist/mixin/sol.js +1 -1
  23. package/dist/parser/commentAndExt.js +1 -1
  24. package/dist/parser/html.js +3 -3
  25. package/dist/parser/table.js +2 -2
  26. package/dist/src/arg.js +13 -7
  27. package/dist/src/atom.js +76 -31
  28. package/dist/src/attribute.js +49 -21
  29. package/dist/src/attributes.d.ts +7 -7
  30. package/dist/src/attributes.js +415 -366
  31. package/dist/src/commented.js +81 -35
  32. package/dist/src/converter.js +13 -7
  33. package/dist/src/converterFlags.js +33 -22
  34. package/dist/src/converterRule.js +263 -216
  35. package/dist/src/extLink.js +21 -16
  36. package/dist/src/gallery.js +18 -8
  37. package/dist/src/heading.js +66 -57
  38. package/dist/src/hidden.js +14 -9
  39. package/dist/src/html.js +28 -9
  40. package/dist/src/imageParameter.js +13 -6
  41. package/dist/src/imagemap.js +32 -25
  42. package/dist/src/index.js +53 -44
  43. package/dist/src/link/base.js +13 -8
  44. package/dist/src/link/file.js +401 -354
  45. package/dist/src/link/galleryImage.js +9 -5
  46. package/dist/src/link/index.js +7 -3
  47. package/dist/src/link/redirectTarget.js +7 -3
  48. package/dist/src/magicLink.js +23 -14
  49. package/dist/src/nested.js +122 -74
  50. package/dist/src/nowiki/base.js +5 -2
  51. package/dist/src/nowiki/comment.js +5 -1
  52. package/dist/src/nowiki/index.js +3 -3
  53. package/dist/src/nowiki/quote.js +13 -8
  54. package/dist/src/onlyinclude.js +17 -9
  55. package/dist/src/paramTag/index.js +21 -14
  56. package/dist/src/parameter.js +26 -20
  57. package/dist/src/pre.js +91 -45
  58. package/dist/src/syntax.js +14 -10
  59. package/dist/src/table/index.js +550 -503
  60. package/dist/src/table/td.js +65 -58
  61. package/dist/src/table/trBase.js +179 -129
  62. package/dist/src/tagPair/ext.js +32 -20
  63. package/dist/src/tagPair/include.js +5 -5
  64. package/dist/src/tagPair/translate.js +150 -103
  65. package/dist/src/transclude.js +13 -8
  66. package/dist/util/html.js +46 -41
  67. package/dist/util/lint.js +4 -4
  68. package/dist/util/string.js +13 -7
  69. package/extensions/dist/base.js +2 -2
  70. package/package.json +15 -15
@@ -1,4 +1,11 @@
1
1
  "use strict";
2
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
3
+ var useValue = arguments.length > 2;
4
+ for (var i = 0; i < initializers.length; i++) {
5
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
6
+ }
7
+ return useValue ? value : void 0;
8
+ };
2
9
  var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
10
  function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
11
  var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
@@ -26,12 +33,9 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
26
33
  if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
34
  done = true;
28
35
  };
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;
36
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
37
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
38
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
35
39
  };
36
40
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
41
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -41,6 +45,7 @@ exports.createTd = exports.TdToken = void 0;
41
45
  const lint_1 = require("../../util/lint");
42
46
  const constants_1 = require("../../util/constants");
43
47
  const rect_1 = require("../../lib/rect");
48
+ const cached_1 = require("../../mixin/cached");
44
49
  const index_1 = require("../index");
45
50
  const base_1 = require("./base");
46
51
  /* NOT FOR BROWSER */
@@ -56,23 +61,73 @@ const index_2 = __importDefault(require("../../index"));
56
61
  * @classdesc `{childNodes: [SyntaxToken, AttributesToken, Token]}`
57
62
  */
58
63
  let TdToken = (() => {
59
- var _a;
60
64
  let _classDecorators = [fixed_1.fixedToken];
61
65
  let _classDescriptor;
62
66
  let _classExtraInitializers = [];
63
67
  let _classThis;
64
68
  let _classSuper = base_1.TableBaseToken;
69
+ let _instanceExtraInitializers = [];
70
+ let _private_getSyntax_decorators;
71
+ let _private_getSyntax_descriptor;
72
+ let _toHtmlInternal_decorators;
65
73
  var TdToken = class extends _classSuper {
66
74
  static { _classThis = this; }
67
75
  static {
68
76
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
77
+ _private_getSyntax_decorators = [(0, cached_1.cached)(false)];
78
+ _toHtmlInternal_decorators = [(0, cached_1.cached)()];
79
+ __esDecorate(this, _private_getSyntax_descriptor = { value: __setFunctionName(function () {
80
+ const syntax = this.firstChild.text(),
81
+ /* NOT FOR BROWSER */
82
+ esc = syntax.includes('{{'),
83
+ /* NOT FOR BROWSER END */
84
+ char = syntax.slice(-1);
85
+ let subtype = 'td';
86
+ if (char === '!') {
87
+ subtype = 'th';
88
+ }
89
+ else if (char === '+') {
90
+ subtype = 'caption';
91
+ }
92
+ if (this.isIndependent()) {
93
+ return {
94
+ subtype,
95
+ /* NOT FOR BROWSER */
96
+ escape: esc,
97
+ correction: false,
98
+ };
99
+ }
100
+ const { previousSibling } = this;
101
+ /* NOT FOR BROWSER */
102
+ if (!(previousSibling instanceof TdToken)) {
103
+ return { subtype, escape: esc, correction: true };
104
+ }
105
+ /* NOT FOR BROWSER END */
106
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
107
+ const result = { ...previousSibling.#getSyntax() };
108
+ /* NOT FOR BROWSER */
109
+ const str = previousSibling.lastChild.toString();
110
+ result.escape ||= esc;
111
+ result.correction = str.includes('\n') && debug_1.Shadow.run(() => new index_1.Token(str, this.getAttribute('config'))
112
+ .parseOnce(0, this.getAttribute('include'))
113
+ .parseOnce()
114
+ .parseOnce()
115
+ .toString()
116
+ .includes('\n'));
117
+ if (subtype === 'th' && result.subtype !== 'th') {
118
+ result.subtype = 'th';
119
+ result.correction = true;
120
+ }
121
+ /* NOT FOR BROWSER END */
122
+ return result;
123
+ }, "#getSyntax") }, _private_getSyntax_decorators, { kind: "method", name: "#getSyntax", static: false, private: true, access: { has: obj => #getSyntax in obj, get: obj => obj.#getSyntax }, metadata: _metadata }, null, _instanceExtraInitializers);
124
+ __esDecorate(this, null, _toHtmlInternal_decorators, { kind: "method", name: "toHtmlInternal", static: false, private: false, access: { has: obj => "toHtmlInternal" in obj, get: obj => obj.toHtmlInternal }, metadata: _metadata }, null, _instanceExtraInitializers);
69
125
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
70
126
  TdToken = _classThis = _classDescriptor.value;
71
127
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
72
128
  __runInitializers(_classThis, _classExtraInitializers);
73
129
  }
74
- #innerSyntax = '';
75
- #syntax;
130
+ #innerSyntax = (__runInitializers(this, _instanceExtraInitializers), '');
76
131
  /* NOT FOR BROWSER END */
77
132
  get type() {
78
133
  return 'td';
@@ -127,55 +182,7 @@ let TdToken = (() => {
127
182
  this.insertAt(innerToken);
128
183
  }
129
184
  /** 表格语法信息 */
130
- #getSyntax() {
131
- return (0, lint_1.cache)(this.#syntax, () => {
132
- const syntax = this.firstChild.text(),
133
- /* NOT FOR BROWSER */
134
- esc = syntax.includes('{{'),
135
- /* NOT FOR BROWSER END */
136
- char = syntax.slice(-1);
137
- let subtype = 'td';
138
- if (char === '!') {
139
- subtype = 'th';
140
- }
141
- else if (char === '+') {
142
- subtype = 'caption';
143
- }
144
- if (this.isIndependent()) {
145
- return {
146
- subtype,
147
- /* NOT FOR BROWSER */
148
- escape: esc,
149
- correction: false,
150
- };
151
- }
152
- const { previousSibling } = this;
153
- /* NOT FOR BROWSER */
154
- if (!(previousSibling instanceof TdToken)) {
155
- return { subtype, escape: esc, correction: true };
156
- }
157
- /* NOT FOR BROWSER END */
158
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
159
- const result = { ...previousSibling.#getSyntax() };
160
- /* NOT FOR BROWSER */
161
- const str = previousSibling.lastChild.toString();
162
- result.escape ||= esc;
163
- result.correction = str.includes('\n') && debug_1.Shadow.run(() => new index_1.Token(str, this.getAttribute('config'))
164
- .parseOnce(0, this.getAttribute('include'))
165
- .parseOnce()
166
- .parseOnce()
167
- .toString()
168
- .includes('\n'));
169
- if (subtype === 'th' && result.subtype !== 'th') {
170
- result.subtype = 'th';
171
- result.correction = true;
172
- }
173
- /* NOT FOR BROWSER END */
174
- return result;
175
- }, value => {
176
- this.#syntax = value;
177
- });
178
- }
185
+ get #getSyntax() { return _private_getSyntax_descriptor.value; }
179
186
  /** @private */
180
187
  afterBuild() {
181
188
  if (this.#innerSyntax.includes('\0')) {
@@ -1,4 +1,38 @@
1
1
  "use strict";
2
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
3
+ var useValue = arguments.length > 2;
4
+ for (var i = 0; i < initializers.length; i++) {
5
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
6
+ }
7
+ return useValue ? value : void 0;
8
+ };
9
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
10
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
11
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
12
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
13
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
14
+ var _, done = false;
15
+ for (var i = decorators.length - 1; i >= 0; i--) {
16
+ var context = {};
17
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
18
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
19
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
20
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
21
+ if (kind === "accessor") {
22
+ if (result === void 0) continue;
23
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
24
+ if (_ = accept(result.get)) descriptor.get = _;
25
+ if (_ = accept(result.set)) descriptor.set = _;
26
+ if (_ = accept(result.init)) initializers.unshift(_);
27
+ }
28
+ else if (_ = accept(result)) {
29
+ if (kind === "field") initializers.unshift(_);
30
+ else descriptor[key] = _;
31
+ }
32
+ }
33
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
34
+ done = true;
35
+ };
2
36
  Object.defineProperty(exports, "__esModule", { value: true });
3
37
  exports.TrBaseToken = void 0;
4
38
  const lint_1 = require("../../util/lint");
@@ -8,158 +42,174 @@ const td_1 = require("./td");
8
42
  const debug_1 = require("../../util/debug");
9
43
  const constants_1 = require("../../util/constants");
10
44
  const html_1 = require("../../util/html");
45
+ const cached_1 = require("../../mixin/cached");
11
46
  const index_1 = require("../index");
12
47
  /**
13
48
  * table row or table
14
49
  *
15
50
  * 表格行或表格
16
51
  */
17
- class TrBaseToken extends base_1.TableBaseToken {
18
- /** @private */
19
- lint(start = this.getAbsoluteIndex(), re) {
20
- const errors = super.lint(start, re), inter = this.childNodes.find(({ type }) => type === 'table-inter');
21
- if (!inter) {
22
- return errors;
52
+ let TrBaseToken = (() => {
53
+ let _classSuper = base_1.TableBaseToken;
54
+ let _instanceExtraInitializers = [];
55
+ let _toHtmlInternal_decorators;
56
+ return class TrBaseToken extends _classSuper {
57
+ static {
58
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
59
+ _toHtmlInternal_decorators = [(0, cached_1.cached)()];
60
+ __esDecorate(this, null, _toHtmlInternal_decorators, { kind: "method", name: "toHtmlInternal", static: false, private: false, access: { has: obj => "toHtmlInternal" in obj, get: obj => obj.toHtmlInternal }, metadata: _metadata }, null, _instanceExtraInitializers);
61
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
23
62
  }
24
- const severity = (0, lint_1.isFostered)(inter);
25
- if (!severity) {
63
+ /** @private */
64
+ lint(start = this.getAbsoluteIndex(), re) {
65
+ const errors = super.lint(start, re), inter = this.childNodes.find(({ type }) => type === 'table-inter');
66
+ if (!inter) {
67
+ return errors;
68
+ }
69
+ const severity = (0, lint_1.isFostered)(inter);
70
+ if (!severity) {
71
+ return errors;
72
+ }
73
+ const error = (0, lint_1.generateForChild)(inter, { start }, 'fostered-content', 'content to be moved out from the table', severity);
74
+ error.startIndex++;
75
+ error.startLine++;
76
+ error.startCol = 0;
77
+ errors.push(error);
26
78
  return errors;
27
79
  }
28
- const error = (0, lint_1.generateForChild)(inter, { start }, 'fostered-content', 'content to be moved out from the table', severity);
29
- error.startIndex++;
30
- error.startLine++;
31
- error.startCol = 0;
32
- errors.push(error);
33
- return errors;
34
- }
35
- /**
36
- * Get the number of rows
37
- *
38
- * 获取行数
39
- */
40
- getRowCount() {
41
- return Number(this.childNodes.some(child => child instanceof td_1.TdToken
42
- && child.isIndependent()
43
- && !child.firstChild.text().endsWith('+')));
44
- }
45
- getNthCol(n, insert) {
46
- const nCols = this.getColCount();
47
- n += n < 0 ? nCols : 0;
48
- /* istanbul ignore if */
49
- if (n < 0 || n > nCols || n === nCols && !insert) {
50
- throw new RangeError(`There is no cell at position ${n}!`);
80
+ /**
81
+ * Get the number of rows
82
+ *
83
+ * 获取行数
84
+ */
85
+ getRowCount() {
86
+ return Number(this.childNodes.some(child => child instanceof td_1.TdToken
87
+ && child.isIndependent()
88
+ && !child.firstChild.text().endsWith('+')));
51
89
  }
52
- let last = 0;
53
- for (const child of this.childNodes.slice(2)) {
54
- if (child instanceof td_1.TdToken) {
55
- if (child.isIndependent()) {
56
- last = Number(child.subtype !== 'caption');
90
+ getNthCol(n, insert) {
91
+ const nCols = this.getColCount();
92
+ n += n < 0 ? nCols : 0;
93
+ /* istanbul ignore if */
94
+ if (n < 0 || n > nCols || n === nCols && !insert) {
95
+ throw new RangeError(`There is no cell at position ${n}!`);
96
+ }
97
+ let last = 0;
98
+ for (const child of this.childNodes.slice(2)) {
99
+ if (child instanceof td_1.TdToken) {
100
+ if (child.isIndependent()) {
101
+ last = Number(child.subtype !== 'caption');
102
+ }
103
+ n -= last;
104
+ if (n < 0) {
105
+ return child;
106
+ }
57
107
  }
58
- n -= last;
59
- if (n < 0) {
108
+ else if (child.is('tr') || child.is('table-syntax')) {
60
109
  return child;
61
110
  }
62
111
  }
63
- else if (child.is('tr') || child.is('table-syntax')) {
64
- return child;
65
- }
112
+ return undefined;
66
113
  }
67
- return undefined;
68
- }
69
- /** 修复简单的表格语法错误 */
70
- #correct() {
71
- const { childNodes: [, , child] } = this;
72
- if (child?.constructor === index_1.Token) {
73
- const { firstChild } = child;
74
- if (firstChild?.type !== 'text') {
75
- child.prepend('\n');
76
- }
77
- else if (!firstChild.data.startsWith('\n')) {
78
- firstChild.insertData(0, '\n');
114
+ /** 修复简单的表格语法错误 */
115
+ #correct() {
116
+ const { childNodes: [, , child] } = this;
117
+ if (child?.constructor === index_1.Token) {
118
+ const { firstChild } = child;
119
+ if (firstChild?.type !== 'text') {
120
+ child.prepend('\n');
121
+ }
122
+ else if (!firstChild.data.startsWith('\n')) {
123
+ firstChild.insertData(0, '\n');
124
+ }
79
125
  }
80
126
  }
81
- }
82
- /** @private */
83
- text() {
84
- this.#correct();
85
- return super.text();
86
- }
87
- /** @private */
88
- toString(skip) {
89
- this.#correct();
90
- return super.toString(skip);
91
- }
92
- /**
93
- * @override
94
- * @param i position of the child node / 移除位置
95
- */
96
- removeAt(i) {
97
- i += i < 0 ? this.length : 0;
98
- const child = this.childNodes[i];
99
- if (child instanceof td_1.TdToken && child.isIndependent()) {
100
- const { nextSibling } = child;
101
- if (nextSibling?.is('td')) {
102
- nextSibling.independence();
127
+ /** @private */
128
+ text() {
129
+ this.#correct();
130
+ return super.text();
131
+ }
132
+ /** @private */
133
+ toString(skip) {
134
+ this.#correct();
135
+ return super.toString(skip);
136
+ }
137
+ /**
138
+ * @override
139
+ * @param i position of the child node / 移除位置
140
+ */
141
+ removeAt(i) {
142
+ i += i < 0 ? this.length : 0;
143
+ const child = this.childNodes[i];
144
+ if (child instanceof td_1.TdToken && child.isIndependent()) {
145
+ const { nextSibling } = child;
146
+ if (nextSibling?.is('td')) {
147
+ nextSibling.independence();
148
+ }
103
149
  }
150
+ return super.removeAt(i);
104
151
  }
105
- return super.removeAt(i);
106
- }
107
- /**
108
- * @override
109
- * @param token node to be inserted / 待插入的子节点
110
- * @param i position to be inserted at / 插入位置
111
- */
112
- insertAt(token, i = this.length) {
113
- if (!debug_1.Shadow.running && token.type !== 'td') {
114
- /* istanbul ignore next */
115
- if (this.is('tr')) {
116
- this.typeError('insertAt', 'TdToken');
152
+ /**
153
+ * @override
154
+ * @param token node to be inserted / 待插入的子节点
155
+ * @param i position to be inserted at / 插入位置
156
+ */
157
+ insertAt(token, i = this.length) {
158
+ if (!debug_1.Shadow.running && !token.is('td')) {
159
+ /* istanbul ignore next */
160
+ if (this.is('tr')) {
161
+ this.typeError('insertAt', 'TdToken');
162
+ }
163
+ else if (!token.is('tr')) {
164
+ this.typeError('insertAt', 'TrToken', 'TdToken');
165
+ }
117
166
  }
118
- else if (token.type !== 'tr') {
119
- this.typeError('insertAt', 'TrToken', 'TdToken');
167
+ i += i < 0 ? this.length : 0;
168
+ const child = this.childNodes[i];
169
+ if (token instanceof td_1.TdToken && token.isIndependent() && child instanceof td_1.TdToken) {
170
+ child.independence();
120
171
  }
172
+ return super.insertAt(token, i);
121
173
  }
122
- i += i < 0 ? this.length : 0;
123
- const child = this.childNodes[i];
124
- if (token instanceof td_1.TdToken && token.isIndependent() && child instanceof td_1.TdToken) {
125
- child.independence();
126
- }
127
- return super.insertAt(token, i);
128
- }
129
- /**
130
- * Get the number of columns
131
- *
132
- * 获取列数
133
- */
134
- getColCount() {
135
- let count = 0, last = 0;
136
- for (const child of this.childNodes) {
137
- if (child instanceof td_1.TdToken) {
138
- last = child.isIndependent() ? Number(child.subtype !== 'caption') : last;
139
- count += last;
174
+ /**
175
+ * Get the number of columns
176
+ *
177
+ * 获取列数
178
+ */
179
+ getColCount() {
180
+ let count = 0, last = 0;
181
+ for (const child of this.childNodes) {
182
+ if (child instanceof td_1.TdToken) {
183
+ last = child.isIndependent() ? Number(child.subtype !== 'caption') : last;
184
+ count += last;
185
+ }
140
186
  }
187
+ return count;
141
188
  }
142
- return count;
143
- }
144
- /**
145
- * Insert a new cell
146
- *
147
- * 插入新的单元格
148
- * @param inner inner wikitext of the cell / 单元格内部wikitext
149
- * @param {TableCoords} coord table coordinates of the cell / 单元格坐标
150
- * @param subtype cell type / 单元格类型
151
- * @param attr cell attribute / 单元格属性
152
- */
153
- insertTableCell(inner, { column }, subtype = 'td', attr = {}) {
154
- return this.insertBefore((0, td_1.createTd)(inner, subtype, attr, this.getAttribute('include'), this.getAttribute('config')), this.getNthCol(column, true));
155
- }
156
- /** @private */
157
- toHtmlInternal(opt) {
158
- const { childNodes, type } = this, td = childNodes.filter((0, debug_1.isToken)('td'));
159
- return td.some(({ subtype }) => subtype !== 'caption')
160
- ? `<tr${type === 'tr' ? childNodes[1].toHtmlInternal() : ''}>${(0, html_1.html)(td, '', opt)}</tr>`
161
- : (0, html_1.html)(td, '', opt);
162
- }
163
- }
189
+ /**
190
+ * Insert a new cell
191
+ *
192
+ * 插入新的单元格
193
+ * @param inner inner wikitext of the cell / 单元格内部wikitext
194
+ * @param {TableCoords} coord table coordinates of the cell / 单元格坐标
195
+ * @param subtype cell type / 单元格类型
196
+ * @param attr cell attribute / 单元格属性
197
+ */
198
+ insertTableCell(inner, { column }, subtype = 'td', attr = {}) {
199
+ return this.insertBefore((0, td_1.createTd)(inner, subtype, attr, this.getAttribute('include'), this.getAttribute('config')), this.getNthCol(column, true));
200
+ }
201
+ /** @private */
202
+ toHtmlInternal(opt) {
203
+ const { childNodes, type } = this, td = childNodes.filter((0, debug_1.isToken)('td'));
204
+ return td.some(({ subtype }) => subtype !== 'caption')
205
+ ? `<tr${type === 'tr' ? childNodes[1].toHtmlInternal() : ''}>${(0, html_1.html)(td, '', opt)}</tr>`
206
+ : (0, html_1.html)(td, '', opt);
207
+ }
208
+ constructor() {
209
+ super(...arguments);
210
+ __runInitializers(this, _instanceExtraInitializers);
211
+ }
212
+ };
213
+ })();
164
214
  exports.TrBaseToken = TrBaseToken;
165
215
  constants_1.classes['TrBaseToken'] = __filename;
@@ -1,4 +1,11 @@
1
1
  "use strict";
2
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
3
+ var useValue = arguments.length > 2;
4
+ for (var i = 0; i < initializers.length; i++) {
5
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
6
+ }
7
+ return useValue ? value : void 0;
8
+ };
2
9
  var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
10
  function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
11
  var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
@@ -26,13 +33,6 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
26
33
  if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
34
  done = true;
28
35
  };
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
- };
36
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
@@ -49,6 +49,7 @@ const attributes_1 = require("../attributes");
49
49
  const debug_1 = require("../../util/debug");
50
50
  const constants_1 = require("../../util/constants");
51
51
  const string_1 = require("../../util/string");
52
+ const cached_1 = require("../../mixin/cached");
52
53
  /**
53
54
  * extension tag
54
55
  *
@@ -61,10 +62,14 @@ let ExtToken = (() => {
61
62
  let _classExtraInitializers = [];
62
63
  let _classThis;
63
64
  let _classSuper = index_3.TagPairToken;
65
+ let _instanceExtraInitializers = [];
66
+ let _toHtmlInternal_decorators;
64
67
  var ExtToken = class extends _classSuper {
65
68
  static { _classThis = this; }
66
69
  static {
67
70
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
71
+ _toHtmlInternal_decorators = [(0, cached_1.cached)()];
72
+ __esDecorate(this, null, _toHtmlInternal_decorators, { kind: "method", name: "toHtmlInternal", static: false, private: false, access: { has: obj => "toHtmlInternal" in obj, get: obj => obj.toHtmlInternal }, metadata: _metadata }, null, _instanceExtraInitializers);
68
73
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
69
74
  ExtToken = _classThis = _classDescriptor.value;
70
75
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
@@ -186,6 +191,7 @@ let ExtToken = (() => {
186
191
  innerToken.type = 'ext-inner';
187
192
  }
188
193
  super(name, attrToken, innerToken, closed, config, accum);
194
+ __runInitializers(this, _instanceExtraInitializers);
189
195
  /* PRINT ONLY */
190
196
  this.seal('closed', true);
191
197
  }
@@ -198,8 +204,9 @@ let ExtToken = (() => {
198
204
  errors.push((0, lint_1.generateForSelf)(this, rect, 'parsing-order', 'extension tag in HTML tag attributes', s));
199
205
  }
200
206
  }
201
- if (this.name === 'ref' && this.closest('heading-title')) {
202
- errors.push((0, lint_1.generateForSelf)(this, rect, 'var-anchor', 'variable anchor in a section header'));
207
+ const rule = 'var-anchor', s = index_1.default.lintConfig.getSeverity(rule, 'ref');
208
+ if (s && this.name === 'ref' && this.closest('heading-title')) {
209
+ errors.push((0, lint_1.generateForSelf)(this, rect, rule, 'variable anchor in a section header', s));
203
210
  }
204
211
  return errors;
205
212
  }
@@ -217,20 +224,25 @@ let ExtToken = (() => {
217
224
  toHtmlInternal(opt) {
218
225
  const { name, firstChild, lastChild } = this;
219
226
  switch (name) {
220
- case 'nowiki':
221
- return (0, string_1.newline)(lastChild.toHtmlInternal());
222
- case 'pre':
223
- return `<pre${firstChild.toHtmlInternal()}>${(0, string_1.newline)(lastChild.toHtmlInternal({
227
+ case 'nowiki': {
228
+ const html = lastChild.toHtmlInternal();
229
+ return this.closest('ext#poem') ? html : (0, string_1.newline)(html);
230
+ }
231
+ case 'pre': {
232
+ const html = lastChild.toHtmlInternal({
224
233
  ...opt,
225
234
  nowrap: false,
226
- }))}</pre>`;
227
- case 'poem':
235
+ });
236
+ return `<pre${firstChild.toHtmlInternal()}>${this.closest('ext#poem') ? html : (0, string_1.newline)(html)}</pre>`;
237
+ }
238
+ case 'poem': {
239
+ const padding = firstChild.hasAttr('compact') ? '' : '\n';
228
240
  firstChild.classList.add('poem');
229
- return `<div${firstChild.toHtmlInternal()}>${lastChild.toHtmlInternal({
230
- ...opt,
231
- nowrap: false,
232
- }).replace(/(?<!^|<hr>)\n(?!$)/gu, '<br>\n')
233
- .replace(/^ +/gmu, p => '&nbsp;'.repeat(p.length))}</div>`;
241
+ return `<div${firstChild.toHtmlInternal()}>${padding}${lastChild.toHtmlInternal({ ...opt, nowrap: false })
242
+ .replace(/(?<!^|<hr>)\n(?!$)/gu, '<br>\n')
243
+ .replace(/^ +/gmu, p => '&nbsp;'.repeat(p.length))
244
+ .trim()}${padding}</div>`;
245
+ }
234
246
  case 'gallery': {
235
247
  const caption = firstChild.getAttrToken('caption'), perrow = parseInt(String(firstChild.getAttr('perrow'))), mode = firstChild.getAttr('mode'), nolines = typeof mode === 'string' && mode.toLowerCase() === 'nolines', padding = nolines ? 9 : 43;
236
248
  firstChild.classList.add('gallery');
@@ -101,14 +101,14 @@ let IncludeToken = (() => {
101
101
  }
102
102
  /** @private */
103
103
  lint(start = this.getAbsoluteIndex()) {
104
- const errors = [], { firstChild, closed, name } = this, rect = new rect_1.BoundingRect(this, start);
105
- if (firstChild.data.trim()) {
106
- const e = (0, lint_1.generateForChild)(firstChild, rect, 'no-ignored', 'useless attribute', 'warning');
104
+ const errors = [], { firstChild, closed, name } = this, rect = new rect_1.BoundingRect(this, start), rules = ['no-ignored', 'unclosed-comment'], s = rules.map(rule => index_1.default.lintConfig.getSeverity(rule, 'include'));
105
+ if (s[0] && firstChild.data.trim()) {
106
+ const e = (0, lint_1.generateForChild)(firstChild, rect, rules[0], 'useless attribute', s[0]);
107
107
  e.suggestions = [{ desc: 'remove', range: [e.startIndex, e.endIndex], text: '' }];
108
108
  errors.push(e);
109
109
  }
110
- if (!closed) {
111
- const e = (0, lint_1.generateForSelf)(this, rect, 'unclosed-comment', index_1.default.msg('unclosed $1', `<${name}>`));
110
+ if (s[1] && !closed) {
111
+ const e = (0, lint_1.generateForSelf)(this, rect, rules[1], index_1.default.msg('unclosed $1', `<${name}>`), s[1]);
112
112
  e.suggestions = [{ desc: 'close', range: [e.endIndex, e.endIndex], text: `</${name}>` }];
113
113
  errors.push(e);
114
114
  }