wikiparser-node 1.10.0 → 1.11.0-b

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 (173) hide show
  1. package/bundle/bundle.min.js +38 -0
  2. package/config/enwiki.json +1 -814
  3. package/config/llwiki.json +1 -35
  4. package/config/moegirl.json +1 -44
  5. package/config/zhwiki.json +1 -466
  6. package/extensions/dist/base.js +64 -0
  7. package/extensions/dist/editor.js +159 -0
  8. package/extensions/dist/highlight.js +56 -0
  9. package/extensions/dist/lint.js +72 -0
  10. package/extensions/editor.css +64 -0
  11. package/extensions/ui.css +144 -0
  12. package/i18n/zh-hans.json +1 -1
  13. package/i18n/zh-hant.json +1 -1
  14. package/package.json +43 -33
  15. package/config/.schema.json +0 -186
  16. package/dist/addon/table.js +0 -486
  17. package/dist/addon/token.js +0 -324
  18. package/dist/addon/transclude.js +0 -185
  19. package/dist/base.d.ts +0 -81
  20. package/dist/base.js +0 -39
  21. package/dist/index.d.ts +0 -33
  22. package/dist/index.js +0 -231
  23. package/dist/internal.d.ts +0 -46
  24. package/dist/lib/element.d.ts +0 -125
  25. package/dist/lib/element.js +0 -374
  26. package/dist/lib/node.d.ts +0 -173
  27. package/dist/lib/node.js +0 -478
  28. package/dist/lib/range.d.ts +0 -105
  29. package/dist/lib/range.js +0 -406
  30. package/dist/lib/ranges.d.ts +0 -28
  31. package/dist/lib/ranges.js +0 -126
  32. package/dist/lib/rect.d.ts +0 -18
  33. package/dist/lib/rect.js +0 -34
  34. package/dist/lib/text.d.ts +0 -58
  35. package/dist/lib/text.js +0 -361
  36. package/dist/lib/title.d.ts +0 -42
  37. package/dist/lib/title.js +0 -205
  38. package/dist/mixin/attributesParent.d.ts +0 -49
  39. package/dist/mixin/attributesParent.js +0 -79
  40. package/dist/mixin/fixed.d.ts +0 -5
  41. package/dist/mixin/fixed.js +0 -32
  42. package/dist/mixin/flagsParent.d.ts +0 -41
  43. package/dist/mixin/flagsParent.js +0 -60
  44. package/dist/mixin/hidden.d.ts +0 -7
  45. package/dist/mixin/hidden.js +0 -37
  46. package/dist/mixin/magicLinkParent.d.ts +0 -19
  47. package/dist/mixin/magicLinkParent.js +0 -43
  48. package/dist/mixin/singleLine.d.ts +0 -5
  49. package/dist/mixin/singleLine.js +0 -25
  50. package/dist/mixin/sol.d.ts +0 -6
  51. package/dist/mixin/sol.js +0 -44
  52. package/dist/mixin/syntax.d.ts +0 -8
  53. package/dist/mixin/syntax.js +0 -46
  54. package/dist/parser/braces.js +0 -150
  55. package/dist/parser/commentAndExt.js +0 -79
  56. package/dist/parser/converter.js +0 -39
  57. package/dist/parser/externalLinks.js +0 -37
  58. package/dist/parser/hrAndDoubleUnderscore.js +0 -42
  59. package/dist/parser/html.js +0 -38
  60. package/dist/parser/links.js +0 -101
  61. package/dist/parser/list.js +0 -99
  62. package/dist/parser/magicLinks.js +0 -53
  63. package/dist/parser/quotes.js +0 -67
  64. package/dist/parser/redirect.js +0 -26
  65. package/dist/parser/selector.js +0 -394
  66. package/dist/parser/table.js +0 -123
  67. package/dist/src/arg.d.ts +0 -51
  68. package/dist/src/arg.js +0 -214
  69. package/dist/src/atom.d.ts +0 -14
  70. package/dist/src/atom.js +0 -52
  71. package/dist/src/attribute.d.ts +0 -64
  72. package/dist/src/attribute.js +0 -483
  73. package/dist/src/attributes.d.ts +0 -101
  74. package/dist/src/attributes.js +0 -382
  75. package/dist/src/converter.d.ts +0 -28
  76. package/dist/src/converter.js +0 -147
  77. package/dist/src/converterFlags.d.ts +0 -80
  78. package/dist/src/converterFlags.js +0 -242
  79. package/dist/src/converterRule.d.ts +0 -71
  80. package/dist/src/converterRule.js +0 -216
  81. package/dist/src/extLink.d.ts +0 -36
  82. package/dist/src/extLink.js +0 -198
  83. package/dist/src/gallery.d.ts +0 -47
  84. package/dist/src/gallery.js +0 -142
  85. package/dist/src/heading.d.ts +0 -40
  86. package/dist/src/heading.js +0 -191
  87. package/dist/src/hidden.d.ts +0 -9
  88. package/dist/src/hidden.js +0 -80
  89. package/dist/src/html.d.ts +0 -57
  90. package/dist/src/html.js +0 -343
  91. package/dist/src/imageParameter.d.ts +0 -58
  92. package/dist/src/imageParameter.js +0 -247
  93. package/dist/src/imagemap.d.ts +0 -47
  94. package/dist/src/imagemap.js +0 -146
  95. package/dist/src/imagemapLink.d.ts +0 -31
  96. package/dist/src/imagemapLink.js +0 -97
  97. package/dist/src/index.d.ts +0 -141
  98. package/dist/src/index.js +0 -795
  99. package/dist/src/link/base.d.ts +0 -54
  100. package/dist/src/link/base.js +0 -263
  101. package/dist/src/link/category.d.ts +0 -22
  102. package/dist/src/link/category.js +0 -34
  103. package/dist/src/link/file.d.ts +0 -96
  104. package/dist/src/link/file.js +0 -276
  105. package/dist/src/link/galleryImage.d.ts +0 -29
  106. package/dist/src/link/galleryImage.js +0 -132
  107. package/dist/src/link/index.d.ts +0 -39
  108. package/dist/src/link/index.js +0 -99
  109. package/dist/src/link/redirectTarget.d.ts +0 -27
  110. package/dist/src/link/redirectTarget.js +0 -72
  111. package/dist/src/magicLink.d.ts +0 -61
  112. package/dist/src/magicLink.js +0 -261
  113. package/dist/src/nested.d.ts +0 -40
  114. package/dist/src/nested.js +0 -106
  115. package/dist/src/nowiki/base.d.ts +0 -30
  116. package/dist/src/nowiki/base.js +0 -89
  117. package/dist/src/nowiki/comment.d.ts +0 -14
  118. package/dist/src/nowiki/comment.js +0 -124
  119. package/dist/src/nowiki/dd.d.ts +0 -8
  120. package/dist/src/nowiki/dd.js +0 -72
  121. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -15
  122. package/dist/src/nowiki/doubleUnderscore.js +0 -97
  123. package/dist/src/nowiki/hr.d.ts +0 -5
  124. package/dist/src/nowiki/hr.js +0 -70
  125. package/dist/src/nowiki/index.d.ts +0 -14
  126. package/dist/src/nowiki/index.js +0 -31
  127. package/dist/src/nowiki/list.d.ts +0 -5
  128. package/dist/src/nowiki/list.js +0 -65
  129. package/dist/src/nowiki/listBase.d.ts +0 -17
  130. package/dist/src/nowiki/listBase.js +0 -75
  131. package/dist/src/nowiki/noinclude.d.ts +0 -6
  132. package/dist/src/nowiki/noinclude.js +0 -75
  133. package/dist/src/nowiki/quote.d.ts +0 -14
  134. package/dist/src/nowiki/quote.js +0 -135
  135. package/dist/src/onlyinclude.d.ts +0 -13
  136. package/dist/src/onlyinclude.js +0 -58
  137. package/dist/src/paramTag/index.d.ts +0 -30
  138. package/dist/src/paramTag/index.js +0 -78
  139. package/dist/src/paramTag/inputbox.d.ts +0 -8
  140. package/dist/src/paramTag/inputbox.js +0 -22
  141. package/dist/src/parameter.d.ts +0 -60
  142. package/dist/src/parameter.js +0 -268
  143. package/dist/src/pre.d.ts +0 -28
  144. package/dist/src/pre.js +0 -60
  145. package/dist/src/redirect.d.ts +0 -30
  146. package/dist/src/redirect.js +0 -126
  147. package/dist/src/syntax.d.ts +0 -17
  148. package/dist/src/syntax.js +0 -87
  149. package/dist/src/table/base.d.ts +0 -28
  150. package/dist/src/table/base.js +0 -81
  151. package/dist/src/table/index.d.ts +0 -230
  152. package/dist/src/table/index.js +0 -505
  153. package/dist/src/table/td.d.ts +0 -72
  154. package/dist/src/table/td.js +0 -370
  155. package/dist/src/table/tr.d.ts +0 -30
  156. package/dist/src/table/tr.js +0 -59
  157. package/dist/src/table/trBase.d.ts +0 -49
  158. package/dist/src/table/trBase.js +0 -164
  159. package/dist/src/tagPair/ext.d.ts +0 -29
  160. package/dist/src/tagPair/ext.js +0 -220
  161. package/dist/src/tagPair/include.d.ts +0 -33
  162. package/dist/src/tagPair/include.js +0 -130
  163. package/dist/src/tagPair/index.d.ts +0 -23
  164. package/dist/src/tagPair/index.js +0 -128
  165. package/dist/src/transclude.d.ts +0 -159
  166. package/dist/src/transclude.js +0 -587
  167. package/dist/util/constants.js +0 -25
  168. package/dist/util/debug.js +0 -95
  169. package/dist/util/diff.js +0 -83
  170. package/dist/util/lint.js +0 -32
  171. package/dist/util/string.js +0 -84
  172. package/errors/README +0 -3
  173. package/printed/README +0 -3
@@ -1,79 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.attributesParent = void 0;
4
- const debug_1 = require("../util/debug");
5
- const constants_1 = require("../util/constants");
6
- /**
7
- * 子节点含有AttributesToken的类
8
- * @param i AttributesToken子节点的位置
9
- * @param constructor 基类
10
- * @param _ context
11
- */
12
- const attributesParent = (i = 0) => (constructor, _) => {
13
- /** 子节点含有AttributesToken的类 */
14
- class AttributesParent extends constructor {
15
- /** AttributesToken子节点 */
16
- get #attributesChild() {
17
- return this.childNodes[i];
18
- }
19
- /* NOT FOR BROWSER */
20
- /** @implements */
21
- get attributes() {
22
- return this.#attributesChild.attributes;
23
- }
24
- set attributes(attributes) {
25
- this.#attributesChild.attributes = attributes;
26
- }
27
- /** @implements */
28
- get className() {
29
- return this.#attributesChild.className;
30
- }
31
- set className(className) {
32
- this.#attributesChild.className = className;
33
- }
34
- /** @implements */
35
- get classList() {
36
- return this.#attributesChild.classList;
37
- }
38
- /** @implements */
39
- get id() {
40
- return this.#attributesChild.id;
41
- }
42
- set id(id) {
43
- this.#attributesChild.id = id;
44
- }
45
- /* NOT FOR BROWSER END */
46
- /** @implements */
47
- getAttr(key) {
48
- return this.#attributesChild.getAttr(key);
49
- }
50
- /* NOT FOR BROWSER */
51
- /** @implements */
52
- hasAttr(key) {
53
- return this.#attributesChild.hasAttr(key);
54
- }
55
- /** @implements */
56
- getAttrNames() {
57
- return this.#attributesChild.getAttrNames();
58
- }
59
- /** @implements */
60
- getAttrs() {
61
- return this.#attributesChild.getAttrs();
62
- }
63
- setAttr(keyOrProp, value) {
64
- this.#attributesChild.setAttr(keyOrProp, value);
65
- }
66
- /** @implements */
67
- removeAttr(key) {
68
- this.#attributesChild.removeAttr(key);
69
- }
70
- /** @implements */
71
- toggleAttr(key, force) {
72
- this.#attributesChild.toggleAttr(key, force);
73
- }
74
- }
75
- (0, debug_1.mixin)(AttributesParent, constructor);
76
- return AttributesParent;
77
- };
78
- exports.attributesParent = attributesParent;
79
- constants_1.mixins['attributesParent'] = __filename;
@@ -1,5 +0,0 @@
1
- /**
2
- * 不可增删子节点的类
3
- * @param constructor 基类
4
- * @param _ context
5
- */
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fixedToken = void 0;
4
- const debug_1 = require("../util/debug");
5
- const constants_1 = require("../util/constants");
6
- /**
7
- * 不可增删子节点的类
8
- * @param constructor 基类
9
- * @param _ context
10
- */
11
- const fixedToken = (constructor, _) => {
12
- /** 不可增删子节点的类 */
13
- class FixedToken extends constructor {
14
- /** @private */
15
- get fixed() {
16
- return true;
17
- }
18
- /** @override */
19
- removeAt() {
20
- this.constructorError('cannot remove child nodes');
21
- }
22
- insertAt(token, i) {
23
- return debug_1.Shadow.running
24
- ? super.insertAt(token, i)
25
- : this.constructorError('cannot insert child nodes');
26
- }
27
- }
28
- (0, debug_1.mixin)(FixedToken, constructor);
29
- return FixedToken;
30
- };
31
- exports.fixedToken = fixedToken;
32
- constants_1.mixins['fixedToken'] = __filename;
@@ -1,41 +0,0 @@
1
- import type { ConverterFlagsToken } from '../src/converterFlags';
2
- export interface FlagsParentBase {
3
- /** 所有转换类型标记 */
4
- flags: Set<string>;
5
- /** 获取所有转换类型标记 */
6
- getAllFlags(): Set<string>;
7
- /** 获取有效的转换类型标记 */
8
- getEffectiveFlags(): Set<string>;
9
- /** 获取未知的转换类型标记 */
10
- getUnknownFlags(): Set<string>;
11
- /**
12
- * 是否具有某转换类型标记
13
- * @param flag 转换类型标记
14
- */
15
- hasFlag(flag: string): boolean;
16
- /**
17
- * 是否具有某有效的转换类型标记
18
- * @param flag 转换类型标记
19
- */
20
- hasEffectiveFlag(flag: string): boolean;
21
- /**
22
- * 移除转换类型标记
23
- * @param flag 转换类型标记
24
- */
25
- removeFlag(flag: string): void;
26
- /**
27
- * 设置转换类型标记
28
- * @param flag 转换类型标记
29
- */
30
- setFlag(flag: string): void;
31
- /**
32
- * 开关某转换类型标记
33
- * @param flag 转换类型标记
34
- */
35
- toggleFlag(flag: string): void;
36
- }
37
- /**
38
- * ConverterToken
39
- * @param constructor 基类
40
- * @param _ context
41
- */
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.flagsParent = void 0;
4
- const debug_1 = require("../util/debug");
5
- const constants_1 = require("../util/constants");
6
- /* NOT FOR BROWSER END */
7
- /**
8
- * ConverterToken
9
- * @param constructor 基类
10
- * @param _ context
11
- */
12
- const flagsParent = (constructor, _) => {
13
- /** 子节点含有ConverterFlagsToken的类 */
14
- class FlagsParent extends constructor {
15
- /* NOT FOR BROWSER */
16
- /** @implements */
17
- get flags() {
18
- return this.firstChild.flags;
19
- }
20
- set flags(value) {
21
- this.firstChild.flags = value;
22
- }
23
- /** @implements */
24
- getAllFlags() {
25
- return this.firstChild.getAllFlags();
26
- }
27
- /** @implements */
28
- getEffectiveFlags() {
29
- return this.firstChild.getEffectiveFlags();
30
- }
31
- /** @implements */
32
- getUnknownFlags() {
33
- return this.firstChild.getUnknownFlags();
34
- }
35
- /** @implements */
36
- hasFlag(flag) {
37
- return this.firstChild.hasFlag(flag);
38
- }
39
- /** @implements */
40
- hasEffectiveFlag(flag) {
41
- return this.firstChild.hasEffectiveFlag(flag);
42
- }
43
- /** @implements */
44
- removeFlag(flag) {
45
- this.firstChild.removeFlag(flag);
46
- }
47
- /** @implements */
48
- setFlag(flag) {
49
- this.firstChild.setFlag(flag);
50
- }
51
- /** @implements */
52
- toggleFlag(flag) {
53
- this.firstChild.toggleFlag(flag);
54
- }
55
- }
56
- (0, debug_1.mixin)(FlagsParent, constructor);
57
- return FlagsParent;
58
- };
59
- exports.flagsParent = flagsParent;
60
- constants_1.mixins['flagsParent'] = __filename;
@@ -1,7 +0,0 @@
1
- /**
2
- * 解析后不可见的类
3
- * @param linter 是否覆写 lint 方法
4
- * @param html 是否覆写 toHtml 方法
5
- * @param constructor 基类
6
- * @param _ context
7
- */
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hiddenToken = void 0;
4
- const debug_1 = require("../util/debug");
5
- const constants_1 = require("../util/constants");
6
- /**
7
- * 解析后不可见的类
8
- * @param linter 是否覆写 lint 方法
9
- * @param html 是否覆写 toHtml 方法
10
- * @param constructor 基类
11
- * @param _ context
12
- */
13
- const hiddenToken = (linter = true, html = true) => (constructor, _) => {
14
- /** 解析后不可见的类 */
15
- class AnyHiddenToken extends constructor {
16
- /** 没有可见部分 */
17
- text() {
18
- return '';
19
- }
20
- lint(start) {
21
- // @ts-expect-error private argument
22
- return linter ? [] : super.lint(start);
23
- }
24
- /* NOT FOR BROWSER */
25
- /** @private */
26
- dispatchEvent() {
27
- //
28
- }
29
- toHtml(nowrap) {
30
- return html ? '' : super.toHtml(nowrap);
31
- }
32
- }
33
- (0, debug_1.mixin)(AnyHiddenToken, constructor);
34
- return AnyHiddenToken;
35
- };
36
- exports.hiddenToken = hiddenToken;
37
- constants_1.mixins['hiddenToken'] = __filename;
@@ -1,19 +0,0 @@
1
- import type { MagicLinkToken } from '../src/magicLink';
2
- export interface MagicLinkParentBase {
3
- /** 协议 */
4
- protocol: string | undefined;
5
- /** 和内链保持一致 */
6
- link: string;
7
- /** 获取网址 */
8
- getUrl(): URL;
9
- /**
10
- * 设置链接目标
11
- * @param url 网址
12
- */
13
- setTarget(url: string): void;
14
- }
15
- /**
16
- * ExtLinkToken
17
- * @param constructor 基类
18
- * @param _ context
19
- */
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.magicLinkParent = void 0;
4
- const debug_1 = require("../util/debug");
5
- const constants_1 = require("../util/constants");
6
- /* NOT FOR BROWSER END */
7
- /**
8
- * ExtLinkToken
9
- * @param constructor 基类
10
- * @param _ context
11
- */
12
- const magicLinkParent = (constructor, _) => {
13
- /** 子节点含有MagicLinkParent的类 */
14
- class MagicLinkParent extends constructor {
15
- /* NOT FOR BROWSER */
16
- /** @implements */
17
- get protocol() {
18
- return this.firstChild.protocol;
19
- }
20
- set protocol(value) {
21
- this.firstChild.protocol = value;
22
- }
23
- /** @implements */
24
- get link() {
25
- return this.firstChild.link;
26
- }
27
- set link(url) {
28
- this.firstChild.link = url;
29
- }
30
- /** @implements */
31
- getUrl() {
32
- return this.firstChild.getUrl();
33
- }
34
- /** @implements */
35
- setTarget(url) {
36
- this.firstChild.setTarget(url);
37
- }
38
- }
39
- (0, debug_1.mixin)(MagicLinkParent, constructor);
40
- return MagicLinkParent;
41
- };
42
- exports.magicLinkParent = magicLinkParent;
43
- constants_1.mixins['magicLinkParent'] = __filename;
@@ -1,5 +0,0 @@
1
- /**
2
- * 不可包含换行符的类
3
- * @param constructor 基类
4
- * @param _ context
5
- */
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.singleLine = void 0;
4
- const debug_1 = require("../util/debug");
5
- const constants_1 = require("../util/constants");
6
- /**
7
- * 不可包含换行符的类
8
- * @param constructor 基类
9
- * @param _ context
10
- */
11
- const singleLine = (constructor, _) => {
12
- /** 不可包含换行符的类 */
13
- class SingleLineToken extends constructor {
14
- toString(skip) {
15
- return super.toString(skip).replace(/\n/gu, ' ');
16
- }
17
- text() {
18
- return super.text().replace(/\n/gu, ' ');
19
- }
20
- }
21
- (0, debug_1.mixin)(SingleLineToken, constructor);
22
- return SingleLineToken;
23
- };
24
- exports.singleLine = singleLine;
25
- constants_1.mixins['singleLine'] = __filename;
@@ -1,6 +0,0 @@
1
- /**
2
- * 只能位于行首的类
3
- * @param self 是否允许同类节点相邻
4
- * @param constructor 基类
5
- * @param _ context
6
- */
package/dist/mixin/sol.js DELETED
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sol = void 0;
4
- const debug_1 = require("../util/debug");
5
- const constants_1 = require("../util/constants");
6
- /**
7
- * 只能位于行首的类
8
- * @param self 是否允许同类节点相邻
9
- * @param constructor 基类
10
- * @param _ context
11
- */
12
- const sol = (self) => (constructor, _) => {
13
- /** 只能位于行首的类 */
14
- class SolToken extends constructor {
15
- /** @implements */
16
- #prependNewLine() {
17
- const { previousVisibleSibling, parentNode, type } = this;
18
- if (previousVisibleSibling) {
19
- return self && previousVisibleSibling.type === type || previousVisibleSibling.toString().endsWith('\n')
20
- ? ''
21
- : '\n';
22
- }
23
- return parentNode?.type === 'root'
24
- || type !== 'heading' && parentNode?.type === 'ext-inner' && parentNode.name === 'poem'
25
- ? ''
26
- : '\n';
27
- }
28
- toString(skip) {
29
- return this.#prependNewLine() + super.toString(skip);
30
- }
31
- getAttribute(key) {
32
- return key === 'padding'
33
- ? this.#prependNewLine().length + super.getAttribute('padding')
34
- : super.getAttribute(key);
35
- }
36
- text() {
37
- return this.#prependNewLine() + super.text();
38
- }
39
- }
40
- (0, debug_1.mixin)(SolToken, constructor);
41
- return SolToken;
42
- };
43
- exports.sol = sol;
44
- constants_1.mixins['sol'] = __filename;
@@ -1,8 +0,0 @@
1
- export interface SyntaxBase {
2
- }
3
- /**
4
- * 满足特定语法格式的Token
5
- * @param pattern 语法正则
6
- * @param constructor 基类
7
- * @param _ context
8
- */
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.syntax = void 0;
4
- const debug_1 = require("../util/debug");
5
- const constants_1 = require("../util/constants");
6
- const string_1 = require("../util/string");
7
- /**
8
- * 满足特定语法格式的Token
9
- * @param pattern 语法正则
10
- * @param constructor 基类
11
- * @param _ context
12
- */
13
- const syntax = (pattern) => (constructor, _) => {
14
- /** 满足特定语法格式的Token */
15
- class SyntaxToken extends constructor {
16
- /** @class */
17
- constructor(...args) {
18
- super(...args); // eslint-disable-line @typescript-eslint/no-unsafe-argument
19
- if (pattern) {
20
- this.pattern = pattern;
21
- }
22
- this.seal('pattern', true);
23
- }
24
- afterBuild() {
25
- super.afterBuild();
26
- const /** @implements */ syntaxListener = (e, data) => {
27
- if (!debug_1.Shadow.running && !this.pattern.test((0, string_1.text)(this.childNodes))) {
28
- (0, debug_1.undo)(e, data);
29
- this.constructorError('cannot modify the syntax pattern');
30
- }
31
- };
32
- this.addEventListener(['remove', 'insert', 'replace', 'text'], syntaxListener);
33
- }
34
- replaceChildren(...elements) {
35
- if (debug_1.Shadow.running || this.pattern.test((0, string_1.text)(elements))) {
36
- debug_1.Shadow.run(() => {
37
- super.replaceChildren(...elements);
38
- });
39
- }
40
- }
41
- }
42
- (0, debug_1.mixin)(SyntaxToken, constructor);
43
- return SyntaxToken;
44
- };
45
- exports.syntax = syntax;
46
- constants_1.mixins['syntax'] = __filename;
@@ -1,150 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseBraces = void 0;
4
- const string_1 = require("../util/string");
5
- const constants_1 = require("../util/constants");
6
- const heading_1 = require("../src/heading");
7
- const transclude_1 = require("../src/transclude");
8
- const arg_1 = require("../src/arg");
9
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
10
- /\{\{\s*([!=]|!!|\(!|!\)|!-)\s*\}\}(?!\})/gu;
11
- const closes = {
12
- '=': '\n',
13
- '{': String.raw `\}{2,}|\|`,
14
- '-': String.raw `\}-`,
15
- '[': String.raw `\]\]`,
16
- }, marks = new Map([['!', '!'], ['!!', '+'], ['(!', '{'], ['!)', '}'], ['!-', '-'], ['=', '~']]), re = new RegExp(String.raw `\{\{\s*(${[...marks.keys()].map(string_1.escapeRegExp).join('|')})\s*\}\}(?!\})`, 'gu');
17
- /**
18
- * 解析花括号
19
- * @param wikitext
20
- * @param config
21
- * @param accum
22
- * @throws TranscludeToken.constructor()
23
- */
24
- const parseBraces = (wikitext, config, accum) => {
25
- const source = String.raw `${config.excludes?.includes('heading') ? '' : String.raw `^(\0\d+c\x7F)*={1,6}|`}\[\[|-\{(?!\{)`, openBraces = String.raw `|\{{2,}`, { parserFunction: [, , , subst] } = config, stack = [];
26
- wikitext = wikitext.replace(re, (m, p1) => {
27
- // @ts-expect-error abstract class
28
- new transclude_1.TranscludeToken(m.slice(2, -2), [], config, accum);
29
- return `\0${accum.length - 2}${marks.get(p1)}\x7F`;
30
- });
31
- const lastBraces = wikitext.lastIndexOf('}}') - wikitext.length;
32
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
33
- /^(\0\d+c\x7F)*={1,6}|\[\[|-\{(?!\{)|\{{2,}|[\n|=]|\}{2,}|\}-|\]\]/gmu;
34
- let moreBraces = lastBraces + wikitext.length !== -1, regex = new RegExp(source + (moreBraces ? openBraces : ''), 'gmu'), mt = regex.exec(wikitext), lastIndex;
35
- while (mt
36
- || lastIndex !== undefined && lastIndex <= wikitext.length && stack[stack.length - 1]?.[0]?.startsWith('=')) {
37
- if (mt?.[1]) {
38
- const [, { length }] = mt;
39
- mt[0] = mt[0].slice(length);
40
- mt.index += length;
41
- }
42
- const { 0: syntax, index: curIndex } = mt ?? { 0: '\n', index: wikitext.length }, top = stack.pop() ?? {}, { 0: open, index, parts, findEqual: topFindEqual, pos: topPos } = top, innerEqual = syntax === '=' && topFindEqual;
43
- /**
44
- * 填入模板内容
45
- * @param text wikitext全文
46
- */
47
- const push = (text) => {
48
- parts[parts.length - 1].push(text.slice(topPos, curIndex));
49
- };
50
- if (syntax === ']]' || syntax === '}-') { // 情形1:闭合内链或转换
51
- lastIndex = curIndex + 2;
52
- }
53
- else if (syntax === '\n') { // 情形2:闭合标题或文末
54
- lastIndex = curIndex + 1;
55
- const { pos, findEqual } = stack[stack.length - 1] ?? {};
56
- if (pos === undefined || findEqual || (0, string_1.removeComment)(wikitext.slice(pos, index)) !== '') {
57
- const rmt = /^(={1,6})(.+)\1((?:\s|\0\d+c\x7F)*)$/u
58
- .exec(wikitext.slice(index, curIndex));
59
- if (rmt) {
60
- wikitext = `${wikitext.slice(0, index)}\0${accum.length}h\x7F${wikitext.slice(curIndex)}`;
61
- lastIndex = index + 4 + String(accum.length).length;
62
- // @ts-expect-error abstract class
63
- new heading_1.HeadingToken(rmt[1].length, rmt.slice(2), config, accum);
64
- }
65
- }
66
- }
67
- else if (syntax === '|' || innerEqual) { // 情形3:模板内部,含行首单个'='
68
- lastIndex = curIndex + 1;
69
- push(wikitext);
70
- if (syntax === '|') {
71
- parts.push([]);
72
- }
73
- top.pos = lastIndex;
74
- top.findEqual = syntax === '|';
75
- stack.push(top);
76
- }
77
- else if (syntax.startsWith('}}')) { // 情形4:闭合模板
78
- const close = syntax.slice(0, Math.min(open.length, 3)), rest = open.length - close.length, { length } = accum;
79
- lastIndex = curIndex + close.length; // 这不是最终的lastIndex
80
- push(wikitext);
81
- let skip = false, ch = 't';
82
- if (close.length === 3) {
83
- const argParts = parts.map(part => part.join('=')), str = argParts.length > 1 && (0, string_1.removeComment)(argParts[1]).trim();
84
- // @ts-expect-error abstract class
85
- new arg_1.ArgToken(argParts, config, accum);
86
- if (str && str.endsWith(':') && subst.includes(str.slice(0, -1).toLowerCase())) {
87
- ch = 's';
88
- }
89
- }
90
- else {
91
- try {
92
- // @ts-expect-error abstract class
93
- new transclude_1.TranscludeToken(parts[0][0], parts.slice(1), config, accum);
94
- const name = (0, string_1.removeComment)(parts[0][0]).trim();
95
- if (marks.has(name)) {
96
- ch = marks.get(name); // 标记{{!}}等
97
- }
98
- else if (/^(?:filepath|(?:full|canonical)urle?):.|^server$/iu.test(name)) {
99
- ch = 'm';
100
- }
101
- else if (/^#vardefine:./iu.test(name)) {
102
- ch = 'c';
103
- }
104
- }
105
- catch (e) {
106
- if (e instanceof SyntaxError && e.message === 'Invalid template name') {
107
- skip = true;
108
- }
109
- else {
110
- throw e;
111
- }
112
- }
113
- }
114
- if (!skip) {
115
- wikitext = `${wikitext.slice(0, index + rest)}\0${length}${ch}\x7F${wikitext.slice(lastIndex)}`;
116
- lastIndex = index + rest + 3 + String(length).length;
117
- if (rest > 1) {
118
- stack.push({ 0: open.slice(0, rest), index: index, pos: index + rest, parts: [[]] });
119
- }
120
- else if (rest === 1 && wikitext[index - 1] === '-') {
121
- stack.push({ 0: '-{', index: index - 1, pos: index + 1, parts: [[]] });
122
- }
123
- }
124
- }
125
- else { // 情形5:开启
126
- lastIndex = curIndex + syntax.length;
127
- if (syntax.startsWith('{')) {
128
- mt.pos = lastIndex;
129
- mt.parts = [[]];
130
- }
131
- stack.push(...'0' in top ? [top] : [], mt);
132
- }
133
- let curTop = stack[stack.length - 1];
134
- if (moreBraces && lastBraces + wikitext.length < lastIndex) {
135
- moreBraces = false;
136
- while (curTop?.[0]?.startsWith('{')) {
137
- stack.pop();
138
- curTop = stack[stack.length - 1];
139
- }
140
- }
141
- regex = new RegExp(source
142
- + (moreBraces ? openBraces : '')
143
- + (curTop ? `|${closes[curTop[0][0]]}${curTop.findEqual ? '|=' : ''}` : ''), 'gmu');
144
- regex.lastIndex = lastIndex;
145
- mt = regex.exec(wikitext);
146
- }
147
- return wikitext;
148
- };
149
- exports.parseBraces = parseBraces;
150
- constants_1.parsers['parseBraces'] = __filename;