wikiparser-node 1.9.2-b → 1.9.2

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/README.md +18 -18
  2. package/config/.schema.json +181 -0
  3. package/config/enwiki.json +814 -1
  4. package/config/llwiki.json +35 -1
  5. package/config/moegirl.json +44 -1
  6. package/config/zhwiki.json +466 -1
  7. package/dist/addon/table.js +486 -0
  8. package/dist/addon/token.js +240 -0
  9. package/dist/addon/transclude.js +185 -0
  10. package/dist/base.d.ts +73 -0
  11. package/dist/base.js +39 -0
  12. package/dist/index.d.ts +31 -0
  13. package/dist/index.js +232 -0
  14. package/dist/internal.d.ts +46 -0
  15. package/dist/lib/element.d.ts +124 -0
  16. package/dist/lib/element.js +600 -0
  17. package/dist/lib/node.d.ts +166 -0
  18. package/dist/lib/node.js +472 -0
  19. package/dist/lib/range.d.ts +105 -0
  20. package/dist/lib/range.js +406 -0
  21. package/dist/lib/ranges.d.ts +28 -0
  22. package/dist/lib/ranges.js +126 -0
  23. package/dist/lib/rect.d.ts +18 -0
  24. package/dist/lib/rect.js +34 -0
  25. package/dist/lib/text.d.ts +54 -0
  26. package/dist/lib/text.js +345 -0
  27. package/dist/lib/title.d.ts +40 -0
  28. package/dist/lib/title.js +197 -0
  29. package/dist/mixin/attributesParent.d.ts +49 -0
  30. package/dist/mixin/attributesParent.js +82 -0
  31. package/dist/mixin/fixed.d.ts +5 -0
  32. package/dist/mixin/fixed.js +32 -0
  33. package/dist/mixin/flagsParent.d.ts +41 -0
  34. package/dist/mixin/flagsParent.js +60 -0
  35. package/dist/mixin/hidden.d.ts +6 -0
  36. package/dist/mixin/hidden.js +29 -0
  37. package/dist/mixin/magicLinkParent.d.ts +19 -0
  38. package/dist/mixin/magicLinkParent.js +43 -0
  39. package/dist/mixin/singleLine.d.ts +5 -0
  40. package/dist/mixin/singleLine.js +27 -0
  41. package/dist/mixin/sol.d.ts +5 -0
  42. package/dist/mixin/sol.js +44 -0
  43. package/dist/mixin/syntax.d.ts +8 -0
  44. package/dist/mixin/syntax.js +47 -0
  45. package/dist/parser/braces.js +150 -0
  46. package/dist/parser/commentAndExt.js +79 -0
  47. package/dist/parser/converter.js +39 -0
  48. package/dist/parser/externalLinks.js +37 -0
  49. package/dist/parser/hrAndDoubleUnderscore.js +42 -0
  50. package/dist/parser/html.js +38 -0
  51. package/dist/parser/links.js +101 -0
  52. package/dist/parser/list.js +97 -0
  53. package/dist/parser/magicLinks.js +53 -0
  54. package/dist/parser/quotes.js +67 -0
  55. package/dist/parser/redirect.js +26 -0
  56. package/dist/parser/selector.js +190 -0
  57. package/dist/parser/table.js +123 -0
  58. package/dist/src/arg.d.ts +52 -0
  59. package/dist/src/arg.js +213 -0
  60. package/dist/src/atom.d.ts +12 -0
  61. package/dist/src/atom.js +26 -0
  62. package/dist/src/attribute.d.ts +65 -0
  63. package/dist/src/attribute.js +483 -0
  64. package/dist/src/attributes.d.ts +103 -0
  65. package/dist/src/attributes.js +350 -0
  66. package/dist/src/converter.d.ts +29 -0
  67. package/dist/src/converter.js +134 -0
  68. package/dist/src/converterFlags.d.ts +81 -0
  69. package/dist/src/converterFlags.js +239 -0
  70. package/dist/src/converterRule.d.ts +73 -0
  71. package/dist/src/converterRule.js +210 -0
  72. package/dist/src/extLink.d.ts +37 -0
  73. package/dist/src/extLink.js +191 -0
  74. package/dist/src/gallery.d.ts +48 -0
  75. package/dist/src/gallery.js +139 -0
  76. package/dist/src/heading.d.ts +41 -0
  77. package/dist/src/heading.js +185 -0
  78. package/dist/src/hidden.d.ts +10 -0
  79. package/dist/src/hidden.js +79 -0
  80. package/dist/src/html.d.ts +58 -0
  81. package/dist/src/html.js +334 -0
  82. package/dist/src/imageParameter.d.ts +59 -0
  83. package/dist/src/imageParameter.js +246 -0
  84. package/dist/src/imagemap.d.ts +48 -0
  85. package/dist/src/imagemap.js +145 -0
  86. package/dist/src/imagemapLink.d.ts +31 -0
  87. package/dist/src/imagemapLink.js +93 -0
  88. package/dist/src/index.d.ts +130 -0
  89. package/dist/src/index.js +721 -0
  90. package/dist/src/link/base.d.ts +46 -0
  91. package/dist/src/link/base.js +224 -0
  92. package/dist/src/link/category.d.ts +22 -0
  93. package/dist/src/link/category.js +30 -0
  94. package/dist/src/link/file.d.ts +96 -0
  95. package/dist/src/link/file.js +274 -0
  96. package/dist/src/link/galleryImage.d.ts +30 -0
  97. package/dist/src/link/galleryImage.js +158 -0
  98. package/dist/src/link/index.d.ts +52 -0
  99. package/dist/src/link/index.js +133 -0
  100. package/dist/src/link/redirectTarget.d.ts +37 -0
  101. package/dist/src/link/redirectTarget.js +95 -0
  102. package/dist/src/magicLink.d.ts +60 -0
  103. package/dist/src/magicLink.js +270 -0
  104. package/dist/src/nested.d.ts +41 -0
  105. package/dist/src/nested.js +105 -0
  106. package/dist/src/nowiki/base.d.ts +31 -0
  107. package/dist/src/nowiki/base.js +91 -0
  108. package/dist/src/nowiki/comment.d.ts +15 -0
  109. package/dist/src/nowiki/comment.js +123 -0
  110. package/dist/src/nowiki/dd.d.ts +8 -0
  111. package/dist/src/nowiki/dd.js +24 -0
  112. package/dist/src/nowiki/doubleUnderscore.d.ts +16 -0
  113. package/dist/src/nowiki/doubleUnderscore.js +96 -0
  114. package/dist/src/nowiki/hr.d.ts +5 -0
  115. package/dist/src/nowiki/hr.js +63 -0
  116. package/dist/src/nowiki/index.d.ts +14 -0
  117. package/dist/src/nowiki/index.js +29 -0
  118. package/dist/src/nowiki/list.d.ts +16 -0
  119. package/dist/src/nowiki/list.js +109 -0
  120. package/dist/src/nowiki/listBase.d.ts +5 -0
  121. package/dist/src/nowiki/listBase.js +61 -0
  122. package/dist/src/nowiki/noinclude.d.ts +10 -0
  123. package/dist/src/nowiki/noinclude.js +73 -0
  124. package/dist/src/nowiki/quote.d.ts +17 -0
  125. package/dist/src/nowiki/quote.js +131 -0
  126. package/dist/src/onlyinclude.d.ts +14 -0
  127. package/dist/src/onlyinclude.js +57 -0
  128. package/dist/src/paramTag/index.d.ts +31 -0
  129. package/dist/src/paramTag/index.js +77 -0
  130. package/dist/src/paramTag/inputbox.d.ts +8 -0
  131. package/dist/src/paramTag/inputbox.js +22 -0
  132. package/dist/src/parameter.d.ts +66 -0
  133. package/dist/src/parameter.js +265 -0
  134. package/dist/src/pre.d.ts +29 -0
  135. package/dist/src/pre.js +59 -0
  136. package/dist/src/redirect.d.ts +31 -0
  137. package/dist/src/redirect.js +121 -0
  138. package/dist/src/syntax.d.ts +17 -0
  139. package/dist/src/syntax.js +84 -0
  140. package/dist/src/table/base.d.ts +29 -0
  141. package/dist/src/table/base.js +82 -0
  142. package/dist/src/table/index.d.ts +239 -0
  143. package/dist/src/table/index.js +502 -0
  144. package/dist/src/table/td.d.ts +78 -0
  145. package/dist/src/table/td.js +368 -0
  146. package/dist/src/table/tr.d.ts +30 -0
  147. package/dist/src/table/tr.js +57 -0
  148. package/dist/src/table/trBase.d.ts +49 -0
  149. package/dist/src/table/trBase.js +156 -0
  150. package/dist/src/tagPair/ext.d.ts +30 -0
  151. package/dist/src/tagPair/ext.js +201 -0
  152. package/dist/src/tagPair/include.d.ts +35 -0
  153. package/dist/src/tagPair/include.js +124 -0
  154. package/dist/src/tagPair/index.d.ts +23 -0
  155. package/dist/src/tagPair/index.js +128 -0
  156. package/dist/src/transclude.d.ts +160 -0
  157. package/dist/src/transclude.js +579 -0
  158. package/dist/util/constants.js +25 -0
  159. package/dist/util/debug.js +97 -0
  160. package/dist/util/diff.js +83 -0
  161. package/dist/util/lint.js +32 -0
  162. package/dist/util/string.js +60 -0
  163. package/errors/README +1 -0
  164. package/package.json +20 -30
  165. package/printed/README +1 -0
  166. package/README.en.md +0 -57
  167. package/bundle/bundle.min.js +0 -38
  168. package/extensions/dist/base.js +0 -64
  169. package/extensions/dist/editor.js +0 -159
  170. package/extensions/dist/highlight.js +0 -58
  171. package/extensions/dist/lint.js +0 -72
  172. package/extensions/editor.css +0 -64
  173. package/extensions/ui.css +0 -144
@@ -0,0 +1,49 @@
1
+ export interface AttributesParentBase {
2
+ /** getAttrs()方法的getter写法 */
3
+ attributes: Record<string, string | true>;
4
+ /** 以字符串表示的class属性 */
5
+ className: string;
6
+ /** 以Set表示的class属性 */
7
+ classList: Set<string>;
8
+ /** id属性 */
9
+ id: string;
10
+ /**
11
+ * 获取AttributesToken子节点的属性
12
+ * @param key 属性键
13
+ */
14
+ getAttr(key: string): string | true | undefined;
15
+ /**
16
+ * AttributesToken子节点是否具有某属性
17
+ * @param key 属性键
18
+ */
19
+ hasAttr(key: string): boolean;
20
+ /** 列举AttributesToken子节点的属性键 */
21
+ getAttrNames(): Set<string>;
22
+ /** 获取AttributesToken子节点的全部标签属性 */
23
+ getAttrs(): Record<string, string | true>;
24
+ /**
25
+ * 对AttributesToken子节点设置属性
26
+ * @param key 属性键
27
+ * @param value 属性值
28
+ * @param prop 属性对象
29
+ */
30
+ setAttr(key: string, value: string | boolean): void;
31
+ setAttr(prop: Record<string, string | boolean>): void;
32
+ /**
33
+ * 移除AttributesToken子节点的某属性
34
+ * @param key 属性键
35
+ */
36
+ removeAttr(key: string): void;
37
+ /**
38
+ * 开关AttributesToken子节点的某属性
39
+ * @param key 属性键
40
+ * @param force 强制开启或关闭
41
+ */
42
+ toggleAttr(key: string, force?: boolean): void;
43
+ }
44
+ /**
45
+ * 子节点含有AttributesToken的类
46
+ * @param i AttributesToken子节点的位置
47
+ * @param constructor 基类
48
+ * @param _ context
49
+ */
@@ -0,0 +1,82 @@
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
+ set classList(classList) {
39
+ this.#attributesChild.classList = classList;
40
+ }
41
+ /** @implements */
42
+ get id() {
43
+ return this.#attributesChild.id;
44
+ }
45
+ set id(id) {
46
+ this.#attributesChild.id = id;
47
+ }
48
+ /* NOT FOR BROWSER END */
49
+ /** @implements */
50
+ getAttr(key) {
51
+ return this.#attributesChild.getAttr(key);
52
+ }
53
+ /* NOT FOR BROWSER */
54
+ /** @implements */
55
+ hasAttr(key) {
56
+ return this.#attributesChild.hasAttr(key);
57
+ }
58
+ /** @implements */
59
+ getAttrNames() {
60
+ return this.#attributesChild.getAttrNames();
61
+ }
62
+ /** @implements */
63
+ getAttrs() {
64
+ return this.#attributesChild.getAttrs();
65
+ }
66
+ setAttr(keyOrProp, value) {
67
+ this.#attributesChild.setAttr(keyOrProp, value);
68
+ }
69
+ /** @implements */
70
+ removeAttr(key) {
71
+ this.#attributesChild.removeAttr(key);
72
+ }
73
+ /** @implements */
74
+ toggleAttr(key, force) {
75
+ this.#attributesChild.toggleAttr(key, force);
76
+ }
77
+ }
78
+ (0, debug_1.mixin)(AttributesParent, constructor);
79
+ return AttributesParent;
80
+ };
81
+ exports.attributesParent = attributesParent;
82
+ constants_1.mixins['attributesParent'] = __filename;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 不可增删子节点的类
3
+ * @param constructor 基类
4
+ * @param _ context
5
+ */
@@ -0,0 +1,32 @@
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;
@@ -0,0 +1,41 @@
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
+ */
@@ -0,0 +1,60 @@
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;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 解析后不可见的类
3
+ * @param linter 是否覆写 lint 方法
4
+ * @param constructor 基类
5
+ * @param _ context
6
+ */
@@ -0,0 +1,29 @@
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 constructor 基类
10
+ * @param _ context
11
+ */
12
+ const hiddenToken = (linter) => (constructor, _) => {
13
+ /** 解析后不可见的类 */
14
+ class AnyHiddenToken extends constructor {
15
+ /** 没有可见部分 */
16
+ text() {
17
+ return '';
18
+ }
19
+ /** @private */
20
+ lint(start) {
21
+ // @ts-expect-error private argument
22
+ return linter ? [] : super.lint(start);
23
+ }
24
+ }
25
+ (0, debug_1.mixin)(AnyHiddenToken, constructor);
26
+ return AnyHiddenToken;
27
+ };
28
+ exports.hiddenToken = hiddenToken;
29
+ constants_1.mixins['hiddenToken'] = __filename;
@@ -0,0 +1,19 @@
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
+ */
@@ -0,0 +1,43 @@
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;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 不可包含换行符的类
3
+ * @param constructor 基类
4
+ * @param _ context
5
+ */
@@ -0,0 +1,27 @@
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
+ /** @private */
15
+ toString() {
16
+ return super.toString().replace(/\n/gu, ' ');
17
+ }
18
+ /** @private */
19
+ text() {
20
+ return super.text().replace(/\n/gu, ' ');
21
+ }
22
+ }
23
+ (0, debug_1.mixin)(SingleLineToken, constructor);
24
+ return SingleLineToken;
25
+ };
26
+ exports.singleLine = singleLine;
27
+ constants_1.mixins['singleLine'] = __filename;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 只能位于行首的类
3
+ * @param constructor 基类
4
+ * @param _ context
5
+ */
@@ -0,0 +1,44 @@
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 constructor 基类
9
+ * @param _ context
10
+ */
11
+ const sol = (constructor, _) => {
12
+ /** 只能位于行首的类 */
13
+ class SolToken extends constructor {
14
+ /** @implements */
15
+ #prependNewLine() {
16
+ const { previousVisibleSibling, parentNode, type } = this;
17
+ if (previousVisibleSibling) {
18
+ return previousVisibleSibling.toString().endsWith('\n') ? '' : '\n';
19
+ }
20
+ return parentNode?.type === 'root'
21
+ || type !== 'heading' && parentNode?.type === 'ext-inner' && parentNode.name === 'poem'
22
+ ? ''
23
+ : '\n';
24
+ }
25
+ /** @private */
26
+ toString() {
27
+ return this.#prependNewLine() + super.toString();
28
+ }
29
+ /** @private */
30
+ getAttribute(key) {
31
+ return key === 'padding'
32
+ ? this.#prependNewLine().length + super.getAttribute('padding')
33
+ : super.getAttribute(key);
34
+ }
35
+ /** @private */
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;
@@ -0,0 +1,8 @@
1
+ export interface SyntaxBase {
2
+ }
3
+ /**
4
+ * 满足特定语法格式的Token
5
+ * @param pattern 语法正则
6
+ * @param constructor 基类
7
+ * @param _ context
8
+ */
@@ -0,0 +1,47 @@
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
+ /** @private */
25
+ afterBuild() {
26
+ const /** @implements */ syntaxListener = (e, data) => {
27
+ if (!debug_1.Shadow.running && !this.pattern.test(this.text())) {
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
+ /** @private */
35
+ replaceChildren(...elements) {
36
+ if (debug_1.Shadow.running || this.pattern.test((0, string_1.text)(elements))) {
37
+ debug_1.Shadow.run(() => {
38
+ super.replaceChildren(...elements);
39
+ });
40
+ }
41
+ }
42
+ }
43
+ (0, debug_1.mixin)(SyntaxToken, constructor);
44
+ return SyntaxToken;
45
+ };
46
+ exports.syntax = syntax;
47
+ constants_1.mixins['syntax'] = __filename;
@@ -0,0 +1,150 @@
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;