wikiparser-node 1.9.1 → 1.9.2-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 (171) 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 +58 -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/package.json +30 -20
  13. package/config/.schema.json +0 -181
  14. package/dist/addon/table.js +0 -486
  15. package/dist/addon/token.js +0 -239
  16. package/dist/addon/transclude.js +0 -185
  17. package/dist/base.d.ts +0 -73
  18. package/dist/base.js +0 -39
  19. package/dist/index.d.ts +0 -31
  20. package/dist/index.js +0 -221
  21. package/dist/internal.d.ts +0 -46
  22. package/dist/lib/element.d.ts +0 -124
  23. package/dist/lib/element.js +0 -600
  24. package/dist/lib/node.d.ts +0 -166
  25. package/dist/lib/node.js +0 -480
  26. package/dist/lib/range.d.ts +0 -105
  27. package/dist/lib/range.js +0 -406
  28. package/dist/lib/ranges.d.ts +0 -28
  29. package/dist/lib/ranges.js +0 -126
  30. package/dist/lib/rect.d.ts +0 -18
  31. package/dist/lib/rect.js +0 -34
  32. package/dist/lib/text.d.ts +0 -54
  33. package/dist/lib/text.js +0 -345
  34. package/dist/lib/title.d.ts +0 -40
  35. package/dist/lib/title.js +0 -197
  36. package/dist/mixin/attributesParent.d.ts +0 -49
  37. package/dist/mixin/attributesParent.js +0 -82
  38. package/dist/mixin/fixed.d.ts +0 -5
  39. package/dist/mixin/fixed.js +0 -32
  40. package/dist/mixin/flagsParent.d.ts +0 -41
  41. package/dist/mixin/flagsParent.js +0 -60
  42. package/dist/mixin/hidden.d.ts +0 -6
  43. package/dist/mixin/hidden.js +0 -29
  44. package/dist/mixin/magicLinkParent.d.ts +0 -19
  45. package/dist/mixin/magicLinkParent.js +0 -43
  46. package/dist/mixin/singleLine.d.ts +0 -5
  47. package/dist/mixin/singleLine.js +0 -27
  48. package/dist/mixin/sol.d.ts +0 -5
  49. package/dist/mixin/sol.js +0 -44
  50. package/dist/mixin/syntax.d.ts +0 -8
  51. package/dist/mixin/syntax.js +0 -47
  52. package/dist/parser/braces.js +0 -146
  53. package/dist/parser/commentAndExt.js +0 -79
  54. package/dist/parser/converter.js +0 -39
  55. package/dist/parser/externalLinks.js +0 -37
  56. package/dist/parser/hrAndDoubleUnderscore.js +0 -42
  57. package/dist/parser/html.js +0 -38
  58. package/dist/parser/links.js +0 -101
  59. package/dist/parser/list.js +0 -97
  60. package/dist/parser/magicLinks.js +0 -53
  61. package/dist/parser/quotes.js +0 -67
  62. package/dist/parser/redirect.js +0 -26
  63. package/dist/parser/selector.js +0 -190
  64. package/dist/parser/table.js +0 -123
  65. package/dist/src/arg.d.ts +0 -52
  66. package/dist/src/arg.js +0 -213
  67. package/dist/src/atom.d.ts +0 -12
  68. package/dist/src/atom.js +0 -26
  69. package/dist/src/attribute.d.ts +0 -65
  70. package/dist/src/attribute.js +0 -490
  71. package/dist/src/attributes.d.ts +0 -103
  72. package/dist/src/attributes.js +0 -350
  73. package/dist/src/converter.d.ts +0 -29
  74. package/dist/src/converter.js +0 -134
  75. package/dist/src/converterFlags.d.ts +0 -81
  76. package/dist/src/converterFlags.js +0 -243
  77. package/dist/src/converterRule.d.ts +0 -73
  78. package/dist/src/converterRule.js +0 -210
  79. package/dist/src/extLink.d.ts +0 -37
  80. package/dist/src/extLink.js +0 -191
  81. package/dist/src/gallery.d.ts +0 -48
  82. package/dist/src/gallery.js +0 -139
  83. package/dist/src/heading.d.ts +0 -41
  84. package/dist/src/heading.js +0 -185
  85. package/dist/src/hidden.d.ts +0 -10
  86. package/dist/src/hidden.js +0 -79
  87. package/dist/src/html.d.ts +0 -58
  88. package/dist/src/html.js +0 -339
  89. package/dist/src/imageParameter.d.ts +0 -59
  90. package/dist/src/imageParameter.js +0 -261
  91. package/dist/src/imagemap.d.ts +0 -48
  92. package/dist/src/imagemap.js +0 -145
  93. package/dist/src/imagemapLink.d.ts +0 -31
  94. package/dist/src/imagemapLink.js +0 -93
  95. package/dist/src/index.d.ts +0 -130
  96. package/dist/src/index.js +0 -717
  97. package/dist/src/link/base.d.ts +0 -46
  98. package/dist/src/link/base.js +0 -224
  99. package/dist/src/link/category.d.ts +0 -22
  100. package/dist/src/link/category.js +0 -30
  101. package/dist/src/link/file.d.ts +0 -96
  102. package/dist/src/link/file.js +0 -274
  103. package/dist/src/link/galleryImage.d.ts +0 -30
  104. package/dist/src/link/galleryImage.js +0 -157
  105. package/dist/src/link/index.d.ts +0 -52
  106. package/dist/src/link/index.js +0 -133
  107. package/dist/src/link/redirectTarget.d.ts +0 -37
  108. package/dist/src/link/redirectTarget.js +0 -95
  109. package/dist/src/magicLink.d.ts +0 -60
  110. package/dist/src/magicLink.js +0 -271
  111. package/dist/src/nested.d.ts +0 -41
  112. package/dist/src/nested.js +0 -105
  113. package/dist/src/nowiki/base.d.ts +0 -31
  114. package/dist/src/nowiki/base.js +0 -92
  115. package/dist/src/nowiki/comment.d.ts +0 -15
  116. package/dist/src/nowiki/comment.js +0 -123
  117. package/dist/src/nowiki/dd.d.ts +0 -8
  118. package/dist/src/nowiki/dd.js +0 -24
  119. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -16
  120. package/dist/src/nowiki/doubleUnderscore.js +0 -100
  121. package/dist/src/nowiki/hr.d.ts +0 -5
  122. package/dist/src/nowiki/hr.js +0 -63
  123. package/dist/src/nowiki/index.d.ts +0 -14
  124. package/dist/src/nowiki/index.js +0 -29
  125. package/dist/src/nowiki/list.d.ts +0 -16
  126. package/dist/src/nowiki/list.js +0 -109
  127. package/dist/src/nowiki/listBase.d.ts +0 -5
  128. package/dist/src/nowiki/listBase.js +0 -61
  129. package/dist/src/nowiki/noinclude.d.ts +0 -10
  130. package/dist/src/nowiki/noinclude.js +0 -73
  131. package/dist/src/nowiki/quote.d.ts +0 -17
  132. package/dist/src/nowiki/quote.js +0 -131
  133. package/dist/src/onlyinclude.d.ts +0 -14
  134. package/dist/src/onlyinclude.js +0 -57
  135. package/dist/src/paramTag/index.d.ts +0 -31
  136. package/dist/src/paramTag/index.js +0 -77
  137. package/dist/src/paramTag/inputbox.d.ts +0 -8
  138. package/dist/src/paramTag/inputbox.js +0 -22
  139. package/dist/src/parameter.d.ts +0 -66
  140. package/dist/src/parameter.js +0 -265
  141. package/dist/src/pre.d.ts +0 -29
  142. package/dist/src/pre.js +0 -59
  143. package/dist/src/redirect.d.ts +0 -31
  144. package/dist/src/redirect.js +0 -121
  145. package/dist/src/syntax.d.ts +0 -17
  146. package/dist/src/syntax.js +0 -85
  147. package/dist/src/table/base.d.ts +0 -27
  148. package/dist/src/table/base.js +0 -81
  149. package/dist/src/table/index.d.ts +0 -239
  150. package/dist/src/table/index.js +0 -499
  151. package/dist/src/table/td.d.ts +0 -78
  152. package/dist/src/table/td.js +0 -368
  153. package/dist/src/table/tr.d.ts +0 -30
  154. package/dist/src/table/tr.js +0 -57
  155. package/dist/src/table/trBase.d.ts +0 -49
  156. package/dist/src/table/trBase.js +0 -156
  157. package/dist/src/tagPair/ext.d.ts +0 -30
  158. package/dist/src/tagPair/ext.js +0 -201
  159. package/dist/src/tagPair/include.d.ts +0 -35
  160. package/dist/src/tagPair/include.js +0 -124
  161. package/dist/src/tagPair/index.d.ts +0 -23
  162. package/dist/src/tagPair/index.js +0 -128
  163. package/dist/src/transclude.d.ts +0 -160
  164. package/dist/src/transclude.js +0 -582
  165. package/dist/util/constants.js +0 -27
  166. package/dist/util/debug.js +0 -90
  167. package/dist/util/diff.js +0 -83
  168. package/dist/util/lint.js +0 -32
  169. package/dist/util/string.js +0 -60
  170. package/errors/README +0 -1
  171. package/printed/README +0 -1
@@ -1,49 +0,0 @@
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
- */
@@ -1,82 +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
- 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;
@@ -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,6 +0,0 @@
1
- /**
2
- * 解析后不可见的类
3
- * @param linter 是否覆写 lint 方法
4
- * @param constructor 基类
5
- * @param _ context
6
- */
@@ -1,29 +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 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;
@@ -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,27 +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
- /** @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;
@@ -1,5 +0,0 @@
1
- /**
2
- * 只能位于行首的类
3
- * @param constructor 基类
4
- * @param _ context
5
- */
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 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;
@@ -1,8 +0,0 @@
1
- export interface SyntaxBase {
2
- }
3
- /**
4
- * 满足特定语法格式的Token
5
- * @param pattern 语法正则
6
- * @param constructor 基类
7
- * @param _ context
8
- */
@@ -1,47 +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
- /** @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;
@@ -1,146 +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}|`}\[\[|\{{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 regex = new RegExp(source, 'gmu'), mt = regex.exec(wikitext), moreBraces = lastBraces + wikitext.length !== -1, 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
- moreBraces &&= lastBraces + wikitext.length >= lastIndex;
134
- let curTop = stack[stack.length - 1];
135
- if (!moreBraces && curTop?.[0]?.startsWith('{')) {
136
- stack.pop();
137
- curTop = stack[stack.length - 1];
138
- }
139
- regex = new RegExp(source + (curTop ? `|${closes[curTop[0][0]]}${curTop.findEqual ? '|=' : ''}` : ''), 'gmu');
140
- regex.lastIndex = lastIndex;
141
- mt = regex.exec(wikitext);
142
- }
143
- return wikitext;
144
- };
145
- exports.parseBraces = parseBraces;
146
- constants_1.parsers['parseBraces'] = __filename;