wikiparser-node 1.11.1 → 1.12.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 (175) hide show
  1. package/bundle/bundle.min.js +37 -0
  2. package/config/default.json +28 -28
  3. package/config/enwiki.json +14 -827
  4. package/config/llwiki.json +20 -54
  5. package/config/minimum.json +1 -1
  6. package/config/moegirl.json +20 -63
  7. package/config/zhwiki.json +27 -492
  8. package/extensions/dist/base.js +162 -0
  9. package/extensions/dist/codejar.js +52 -0
  10. package/extensions/dist/editor.js +159 -0
  11. package/extensions/dist/highlight.js +30 -0
  12. package/extensions/dist/lint.js +72 -0
  13. package/extensions/editor.css +59 -0
  14. package/extensions/ui.css +159 -0
  15. package/package.json +29 -21
  16. package/config/.schema.json +0 -186
  17. package/dist/addon/table.js +0 -486
  18. package/dist/addon/token.js +0 -304
  19. package/dist/addon/transclude.js +0 -184
  20. package/dist/base.d.ts +0 -81
  21. package/dist/base.js +0 -39
  22. package/dist/index.d.ts +0 -33
  23. package/dist/index.js +0 -235
  24. package/dist/internal.d.ts +0 -46
  25. package/dist/lib/element.d.ts +0 -125
  26. package/dist/lib/element.js +0 -375
  27. package/dist/lib/node.d.ts +0 -173
  28. package/dist/lib/node.js +0 -477
  29. package/dist/lib/range.d.ts +0 -105
  30. package/dist/lib/range.js +0 -406
  31. package/dist/lib/ranges.d.ts +0 -28
  32. package/dist/lib/ranges.js +0 -126
  33. package/dist/lib/rect.d.ts +0 -18
  34. package/dist/lib/rect.js +0 -34
  35. package/dist/lib/text.d.ts +0 -58
  36. package/dist/lib/text.js +0 -400
  37. package/dist/lib/title.d.ts +0 -42
  38. package/dist/lib/title.js +0 -208
  39. package/dist/mixin/attributesParent.d.ts +0 -49
  40. package/dist/mixin/attributesParent.js +0 -79
  41. package/dist/mixin/fixed.d.ts +0 -5
  42. package/dist/mixin/fixed.js +0 -32
  43. package/dist/mixin/flagsParent.d.ts +0 -43
  44. package/dist/mixin/flagsParent.js +0 -64
  45. package/dist/mixin/hidden.d.ts +0 -7
  46. package/dist/mixin/hidden.js +0 -37
  47. package/dist/mixin/magicLinkParent.d.ts +0 -19
  48. package/dist/mixin/magicLinkParent.js +0 -43
  49. package/dist/mixin/singleLine.d.ts +0 -5
  50. package/dist/mixin/singleLine.js +0 -25
  51. package/dist/mixin/sol.d.ts +0 -6
  52. package/dist/mixin/sol.js +0 -45
  53. package/dist/mixin/syntax.d.ts +0 -8
  54. package/dist/mixin/syntax.js +0 -46
  55. package/dist/parser/braces.js +0 -150
  56. package/dist/parser/commentAndExt.js +0 -79
  57. package/dist/parser/converter.js +0 -39
  58. package/dist/parser/externalLinks.js +0 -37
  59. package/dist/parser/hrAndDoubleUnderscore.js +0 -42
  60. package/dist/parser/html.js +0 -38
  61. package/dist/parser/links.js +0 -101
  62. package/dist/parser/list.js +0 -114
  63. package/dist/parser/magicLinks.js +0 -52
  64. package/dist/parser/quotes.js +0 -67
  65. package/dist/parser/redirect.js +0 -26
  66. package/dist/parser/selector.js +0 -394
  67. package/dist/parser/table.js +0 -123
  68. package/dist/src/arg.d.ts +0 -51
  69. package/dist/src/arg.js +0 -214
  70. package/dist/src/atom.d.ts +0 -14
  71. package/dist/src/atom.js +0 -52
  72. package/dist/src/attribute.d.ts +0 -64
  73. package/dist/src/attribute.js +0 -480
  74. package/dist/src/attributes.d.ts +0 -101
  75. package/dist/src/attributes.js +0 -381
  76. package/dist/src/converter.d.ts +0 -28
  77. package/dist/src/converter.js +0 -148
  78. package/dist/src/converterFlags.d.ts +0 -80
  79. package/dist/src/converterFlags.js +0 -239
  80. package/dist/src/converterRule.d.ts +0 -71
  81. package/dist/src/converterRule.js +0 -216
  82. package/dist/src/extLink.d.ts +0 -36
  83. package/dist/src/extLink.js +0 -218
  84. package/dist/src/gallery.d.ts +0 -47
  85. package/dist/src/gallery.js +0 -143
  86. package/dist/src/heading.d.ts +0 -40
  87. package/dist/src/heading.js +0 -192
  88. package/dist/src/hidden.d.ts +0 -9
  89. package/dist/src/hidden.js +0 -80
  90. package/dist/src/html.d.ts +0 -61
  91. package/dist/src/html.js +0 -343
  92. package/dist/src/imageParameter.d.ts +0 -60
  93. package/dist/src/imageParameter.js +0 -260
  94. package/dist/src/imagemap.d.ts +0 -47
  95. package/dist/src/imagemap.js +0 -146
  96. package/dist/src/imagemapLink.d.ts +0 -31
  97. package/dist/src/imagemapLink.js +0 -97
  98. package/dist/src/index.d.ts +0 -136
  99. package/dist/src/index.js +0 -834
  100. package/dist/src/link/base.d.ts +0 -52
  101. package/dist/src/link/base.js +0 -256
  102. package/dist/src/link/category.d.ts +0 -22
  103. package/dist/src/link/category.js +0 -34
  104. package/dist/src/link/file.d.ts +0 -102
  105. package/dist/src/link/file.js +0 -333
  106. package/dist/src/link/galleryImage.d.ts +0 -29
  107. package/dist/src/link/galleryImage.js +0 -132
  108. package/dist/src/link/index.d.ts +0 -39
  109. package/dist/src/link/index.js +0 -98
  110. package/dist/src/link/redirectTarget.d.ts +0 -27
  111. package/dist/src/link/redirectTarget.js +0 -69
  112. package/dist/src/magicLink.d.ts +0 -58
  113. package/dist/src/magicLink.js +0 -256
  114. package/dist/src/nested.d.ts +0 -40
  115. package/dist/src/nested.js +0 -106
  116. package/dist/src/nowiki/base.d.ts +0 -28
  117. package/dist/src/nowiki/base.js +0 -89
  118. package/dist/src/nowiki/comment.d.ts +0 -14
  119. package/dist/src/nowiki/comment.js +0 -121
  120. package/dist/src/nowiki/dd.d.ts +0 -8
  121. package/dist/src/nowiki/dd.js +0 -72
  122. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -15
  123. package/dist/src/nowiki/doubleUnderscore.js +0 -97
  124. package/dist/src/nowiki/hr.d.ts +0 -5
  125. package/dist/src/nowiki/hr.js +0 -70
  126. package/dist/src/nowiki/index.d.ts +0 -14
  127. package/dist/src/nowiki/index.js +0 -28
  128. package/dist/src/nowiki/list.d.ts +0 -5
  129. package/dist/src/nowiki/list.js +0 -65
  130. package/dist/src/nowiki/listBase.d.ts +0 -23
  131. package/dist/src/nowiki/listBase.js +0 -99
  132. package/dist/src/nowiki/noinclude.d.ts +0 -6
  133. package/dist/src/nowiki/noinclude.js +0 -75
  134. package/dist/src/nowiki/quote.d.ts +0 -14
  135. package/dist/src/nowiki/quote.js +0 -140
  136. package/dist/src/onlyinclude.d.ts +0 -13
  137. package/dist/src/onlyinclude.js +0 -58
  138. package/dist/src/paramTag/index.d.ts +0 -28
  139. package/dist/src/paramTag/index.js +0 -78
  140. package/dist/src/paramTag/inputbox.d.ts +0 -8
  141. package/dist/src/paramTag/inputbox.js +0 -22
  142. package/dist/src/parameter.d.ts +0 -60
  143. package/dist/src/parameter.js +0 -264
  144. package/dist/src/pre.d.ts +0 -28
  145. package/dist/src/pre.js +0 -60
  146. package/dist/src/redirect.d.ts +0 -30
  147. package/dist/src/redirect.js +0 -126
  148. package/dist/src/syntax.d.ts +0 -17
  149. package/dist/src/syntax.js +0 -87
  150. package/dist/src/table/base.d.ts +0 -28
  151. package/dist/src/table/base.js +0 -81
  152. package/dist/src/table/index.d.ts +0 -230
  153. package/dist/src/table/index.js +0 -506
  154. package/dist/src/table/td.d.ts +0 -72
  155. package/dist/src/table/td.js +0 -370
  156. package/dist/src/table/tr.d.ts +0 -30
  157. package/dist/src/table/tr.js +0 -59
  158. package/dist/src/table/trBase.d.ts +0 -49
  159. package/dist/src/table/trBase.js +0 -164
  160. package/dist/src/tagPair/ext.d.ts +0 -29
  161. package/dist/src/tagPair/ext.js +0 -220
  162. package/dist/src/tagPair/include.d.ts +0 -33
  163. package/dist/src/tagPair/include.js +0 -130
  164. package/dist/src/tagPair/index.d.ts +0 -23
  165. package/dist/src/tagPair/index.js +0 -128
  166. package/dist/src/transclude.d.ts +0 -159
  167. package/dist/src/transclude.js +0 -587
  168. package/dist/util/constants.js +0 -25
  169. package/dist/util/debug.js +0 -95
  170. package/dist/util/diff.js +0 -83
  171. package/dist/util/html.js +0 -143
  172. package/dist/util/lint.js +0 -32
  173. package/dist/util/string.js +0 -87
  174. package/errors/README +0 -3
  175. 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,43 +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
- getVariantFlags(): Set<string>;
13
- /**
14
- * 是否具有某转换类型标记
15
- * @param flag 转换类型标记
16
- */
17
- hasFlag(flag: string): boolean;
18
- /**
19
- * 是否具有某有效的转换类型标记
20
- * @param flag 转换类型标记
21
- */
22
- hasEffectiveFlag(flag: string): boolean;
23
- /**
24
- * 移除转换类型标记
25
- * @param flag 转换类型标记
26
- */
27
- removeFlag(flag: string): void;
28
- /**
29
- * 设置转换类型标记
30
- * @param flag 转换类型标记
31
- */
32
- setFlag(flag: string): void;
33
- /**
34
- * 开关某转换类型标记
35
- * @param flag 转换类型标记
36
- */
37
- toggleFlag(flag: string): void;
38
- }
39
- /**
40
- * ConverterToken
41
- * @param constructor 基类
42
- * @param _ context
43
- */
@@ -1,64 +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
- getVariantFlags() {
37
- return this.firstChild.getVariantFlags();
38
- }
39
- /** @implements */
40
- hasFlag(flag) {
41
- return this.firstChild.hasFlag(flag);
42
- }
43
- /** @implements */
44
- hasEffectiveFlag(flag) {
45
- return this.firstChild.hasEffectiveFlag(flag);
46
- }
47
- /** @implements */
48
- removeFlag(flag) {
49
- this.firstChild.removeFlag(flag);
50
- }
51
- /** @implements */
52
- setFlag(flag) {
53
- this.firstChild.setFlag(flag);
54
- }
55
- /** @implements */
56
- toggleFlag(flag) {
57
- this.firstChild.toggleFlag(flag);
58
- }
59
- }
60
- (0, debug_1.mixin)(FlagsParent, constructor);
61
- return FlagsParent;
62
- };
63
- exports.flagsParent = flagsParent;
64
- 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
- toHtmlInternal(nowrap) {
30
- return html ? '' : super.toHtmlInternal(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).replaceAll('\n', ' ');
16
- }
17
- text() {
18
- return super.text().replaceAll('\n', ' ');
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,45 +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 === 'list' && parentNode?.type === 'list-range'
25
- || type !== 'heading' && parentNode?.type === 'ext-inner' && parentNode.name === 'poem'
26
- ? ''
27
- : '\n';
28
- }
29
- toString(skip) {
30
- return this.#prependNewLine() + super.toString(skip);
31
- }
32
- getAttribute(key) {
33
- return key === 'padding'
34
- ? this.#prependNewLine().length + super.getAttribute('padding')
35
- : super.getAttribute(key);
36
- }
37
- text() {
38
- return this.#prependNewLine() + super.text();
39
- }
40
- }
41
- (0, debug_1.mixin)(SolToken, constructor);
42
- return SolToken;
43
- };
44
- exports.sol = sol;
45
- 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;