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.TableBaseToken = void 0;
4
38
  const debug_1 = require("../../util/debug");
@@ -24,58 +58,75 @@ const escapeTable = (syntax) => {
24
58
  * 表格行,含开头的换行,不含结尾的换行
25
59
  * @classdesc `{childNodes: [SyntaxToken, AttributesToken, ...Token]}`
26
60
  */
27
- class TableBaseToken extends (0, attributesParent_1.attributesParent)(index_2.Token, 1) {
28
- /**
29
- * @param pattern 表格语法正则
30
- * @param syntax 表格语法
31
- * @param attr 表格属性
32
- */
33
- constructor(pattern, syntax, attr, config = index_1.default.getConfig(), accum = [], acceptable = {}) {
34
- super(undefined, config, accum, acceptable);
35
- this.append(new syntax_1.SyntaxToken(syntax, pattern, 'table-syntax', config, accum, {
36
- 'Stage-1': ':', '!ExtToken': '', TranscludeToken: ':',
37
- }),
38
- // @ts-expect-error abstract class
39
- new attributes_1.AttributesToken(attr, 'table-attrs', this.type, config, accum));
61
+ let TableBaseToken = (() => {
62
+ let _classDecorators = [(0, attributesParent_1.attributesParent)(1)];
63
+ let _classDescriptor;
64
+ let _classExtraInitializers = [];
65
+ let _classThis;
66
+ let _classSuper = index_2.Token;
67
+ var TableBaseToken = class extends _classSuper {
68
+ static { _classThis = this; }
69
+ static {
70
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
71
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
72
+ TableBaseToken = _classThis = _classDescriptor.value;
73
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
74
+ __runInitializers(_classThis, _classExtraInitializers);
75
+ }
76
+ /* NOT FOR BROWSER END */
77
+ /**
78
+ * @param pattern 表格语法正则
79
+ * @param syntax 表格语法
80
+ * @param attr 表格属性
81
+ */
82
+ constructor(pattern, syntax, attr, config = index_1.default.getConfig(), accum = [], acceptable = {}) {
83
+ super(undefined, config, accum, acceptable);
84
+ this.append(new syntax_1.SyntaxToken(syntax, pattern, 'table-syntax', config, accum, {
85
+ 'Stage-1': ':', '!ExtToken': '', TranscludeToken: ':',
86
+ }),
87
+ // @ts-expect-error abstract class
88
+ new attributes_1.AttributesToken(attr, 'table-attrs', this.type, config, accum));
89
+ /* NOT FOR BROWSER */
90
+ this.protectChildren(0, 1);
91
+ }
40
92
  /* NOT FOR BROWSER */
41
- this.protectChildren(0, 1);
42
- }
43
- /* NOT FOR BROWSER */
44
- /** @override */
45
- cloneNode() {
46
- const [syntax, attr, ...cloned] = this.cloneChildNodes();
47
- return debug_1.Shadow.run(() => {
48
- const { constructor } = this, token = new constructor(undefined, undefined, this.getAttribute('config'));
49
- token.firstChild.safeReplaceWith(syntax);
50
- token.childNodes[1].safeReplaceWith(attr);
51
- if (token.type === 'td') { // TdToken
52
- token.childNodes[2].safeReplaceWith(cloned[0]);
53
- }
54
- else {
55
- token.append(...cloned);
56
- }
57
- return token;
58
- });
59
- }
60
- /** 转义表格语法 */
61
- escape() {
62
- for (const child of this.childNodes) {
63
- if (child instanceof syntax_1.SyntaxToken) {
64
- escapeTable(child);
65
- }
66
- else if (child instanceof TableBaseToken) {
67
- child.escape();
93
+ /** @override */
94
+ cloneNode() {
95
+ const [syntax, attr, ...cloned] = this.cloneChildNodes();
96
+ return debug_1.Shadow.run(() => {
97
+ const { constructor } = this, token = new constructor(undefined, undefined, this.getAttribute('config'));
98
+ token.firstChild.safeReplaceWith(syntax);
99
+ token.childNodes[1].safeReplaceWith(attr);
100
+ if (token.type === 'td') { // TdToken
101
+ token.childNodes[2].safeReplaceWith(cloned[0]);
102
+ }
103
+ else {
104
+ token.append(...cloned);
105
+ }
106
+ return token;
107
+ });
108
+ }
109
+ /** 转义表格语法 */
110
+ escape() {
111
+ for (const child of this.childNodes) {
112
+ if (child instanceof syntax_1.SyntaxToken) {
113
+ escapeTable(child);
114
+ }
115
+ else if (child instanceof TableBaseToken) {
116
+ child.escape();
117
+ }
68
118
  }
69
119
  }
70
- }
71
- /** @private */
72
- setSyntax(syntax, esc = false) {
73
- const { firstChild } = this;
74
- firstChild.replaceChildren(syntax);
75
- if (esc) {
76
- escapeTable(firstChild);
120
+ /** @private */
121
+ setSyntax(syntax, esc = false) {
122
+ const { firstChild } = this;
123
+ firstChild.replaceChildren(syntax);
124
+ if (esc) {
125
+ escapeTable(firstChild);
126
+ }
77
127
  }
78
- }
79
- }
128
+ };
129
+ return TableBaseToken = _classThis;
130
+ })();
80
131
  exports.TableBaseToken = TableBaseToken;
81
132
  constants_1.classes['TableBaseToken'] = __filename;
@@ -1,7 +1,8 @@
1
1
  import Parser from '../../index';
2
2
  import { TrBaseToken } from './trBase';
3
3
  import { SyntaxToken } from '../syntax';
4
- import type { LintError } from '../../base';
4
+ import type { LintError, AST } from '../../base';
5
+ import type { SyntaxBase } from '../../mixin/syntax';
5
6
  import type { AttributesToken, TdToken, TrToken, Token } from '../../internal';
6
7
  import type { TableCoords } from './trBase';
7
8
  import type { TdAttrs, TdSubtypes, TdSpanAttrs } from './td';
@@ -12,6 +13,8 @@ export interface TableRenderedCoords {
12
13
  readonly x: number;
13
14
  readonly y: number;
14
15
  }
16
+ export interface TableToken extends SyntaxBase {
17
+ }
15
18
  /**
16
19
  * 表格
17
20
  * @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken, ...TrToken, ?SyntaxToken]}`
@@ -19,8 +22,8 @@ export interface TableRenderedCoords {
19
22
  export declare abstract class TableToken extends TrBaseToken {
20
23
  readonly type = "table";
21
24
  readonly childNodes: readonly [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[], SyntaxToken] | readonly [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[]];
22
- abstract get children(): [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[], SyntaxToken] | [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[]];
23
25
  abstract get lastChild(): AttributesToken | TdToken | TrToken | SyntaxToken;
26
+ abstract get children(): [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[], SyntaxToken] | [SyntaxToken, AttributesToken, ...(TdToken | TrToken)[]];
24
27
  abstract get lastElementChild(): AttributesToken | TdToken | TrToken | SyntaxToken;
25
28
  /** 表格是否闭合 */
26
29
  get closed(): boolean;
@@ -39,7 +42,7 @@ export declare abstract class TableToken extends TrBaseToken {
39
42
  */
40
43
  close(syntax?: string, halfParsed?: boolean): void;
41
44
  /** @override */
42
- json(): object;
45
+ json(): AST;
43
46
  /**
44
47
  * @override
45
48
  * @param token 待插入的子节点
@@ -16,6 +16,7 @@ const closingPattern = /^\n[^\S\n]*(?:\|\}|\{\{\s*!\s*\}\}\}|\{\{\s*!\)\s*\}\})$
16
16
  */
17
17
  class TableToken extends trBase_1.TrBaseToken {
18
18
  type = 'table';
19
+ /* NOT FOR BROWSER END */
19
20
  /** 表格是否闭合 */
20
21
  get closed() {
21
22
  return this.lastChild.type === 'table-syntax';
@@ -51,26 +52,21 @@ class TableToken extends trBase_1.TrBaseToken {
51
52
  */
52
53
  close(syntax = '\n|}', halfParsed = false) {
53
54
  const config = this.getAttribute('config'), accum = this.getAttribute('accum'), inner = halfParsed ? [syntax] : index_1.default.parse(syntax, this.getAttribute('include'), 2, config).childNodes;
54
- /* NOT FOR BROWSER */
55
55
  if (this.lastChild.type !== 'table-syntax') {
56
- /* NOT FOR BROWSER END */
57
56
  const token = debug_1.Shadow.run(() => super.insertAt(new syntax_1.SyntaxToken(undefined, closingPattern, 'table-syntax', config, accum, {
58
57
  'Stage-1': ':', '!ExtToken': '', TranscludeToken: ':',
59
58
  })));
60
- /* NOT FOR BROWSER */
61
59
  if (!halfParsed) {
62
60
  token.afterBuild();
63
61
  }
64
- /* NOT FOR BROWSER END */
65
62
  }
66
63
  this.lastChild.replaceChildren(...inner);
67
64
  }
68
65
  /** @override */
69
66
  json() {
70
- return {
71
- ...super.json(),
72
- closed: this.closed,
73
- };
67
+ const json = super.json();
68
+ json['closed'] = this.closed;
69
+ return json;
74
70
  }
75
71
  /* NOT FOR BROWSER */
76
72
  /**
@@ -86,7 +82,7 @@ class TableToken extends trBase_1.TrBaseToken {
86
82
  index_1.default.warn('改为将单元格插入当前行。');
87
83
  return previous.insertAt(token);
88
84
  }
89
- else if (i > 0 && token instanceof syntax_1.SyntaxToken && token.getAttribute('pattern') !== closingPattern) {
85
+ else if (i > 0 && token instanceof syntax_1.SyntaxToken && token.pattern !== closingPattern) {
90
86
  throw new SyntaxError(`表格的闭合部分不符合语法:${(0, string_1.noWrap)(String(token))}`);
91
87
  }
92
88
  return super.insertAt(token, i);
@@ -1,7 +1,7 @@
1
1
  import Parser from '../../index';
2
2
  import { Token } from '../index';
3
3
  import { TableBaseToken } from './base';
4
- import type { LintError } from '../../base';
4
+ import type { LintError, AST } from '../../base';
5
5
  import type { SyntaxToken, AttributesToken, TrToken, TableToken } from '../../internal';
6
6
  export type TdSubtypes = 'td' | 'th' | 'caption';
7
7
  export interface TdSpanAttrs {
@@ -11,16 +11,20 @@ export interface TdSpanAttrs {
11
11
  declare type TdAttrGetter<T extends string> = T extends keyof TdSpanAttrs ? number : string | true | undefined;
12
12
  declare type TdAttrSetter<T extends string> = T extends keyof TdSpanAttrs ? number : string | boolean;
13
13
  export type TdAttrs = Record<string, string | true> & TdSpanAttrs;
14
+ /**
15
+ * `<td>`、`<th>`和`<caption>`
16
+ * @classdesc `{childNodes: [SyntaxToken, AttributesToken, Token]}`
17
+ */
14
18
  export declare abstract class TdToken extends TableBaseToken {
15
19
  #private;
16
20
  readonly type = "td";
17
21
  readonly childNodes: readonly [SyntaxToken, AttributesToken, Token];
18
- abstract get children(): [SyntaxToken, AttributesToken, Token];
19
22
  abstract get parentNode(): TrToken | TableToken | undefined;
20
- abstract get parentElement(): TrToken | TableToken | undefined;
21
23
  abstract get nextSibling(): this | TrToken | SyntaxToken | undefined;
22
- abstract get nextElementSibling(): this | TrToken | SyntaxToken | undefined;
23
24
  abstract get previousSibling(): Token | undefined;
25
+ abstract get children(): [SyntaxToken, AttributesToken, Token];
26
+ abstract get parentElement(): TrToken | TableToken | undefined;
27
+ abstract get nextElementSibling(): this | TrToken | SyntaxToken | undefined;
24
28
  /** 单元格类型 */
25
29
  get subtype(): TdSubtypes;
26
30
  set subtype(subtype: TdSubtypes);
@@ -45,7 +49,7 @@ export declare abstract class TdToken extends TableBaseToken {
45
49
  /** @override */
46
50
  print(): string;
47
51
  /** @override */
48
- json(): object;
52
+ json(): AST;
49
53
  /** 是否位于行首 */
50
54
  isIndependent(): boolean;
51
55
  /** @override */