wikiparser-node 1.4.1-b → 1.4.1

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 (162) hide show
  1. package/config/.schema.json +172 -0
  2. package/config/enwiki.json +814 -1
  3. package/config/llwiki.json +35 -1
  4. package/config/moegirl.json +44 -1
  5. package/config/zhwiki.json +466 -1
  6. package/dist/addon/table.d.ts +6 -0
  7. package/dist/addon/table.js +560 -0
  8. package/dist/base.d.ts +53 -0
  9. package/dist/index.d.ts +32 -0
  10. package/dist/index.js +208 -0
  11. package/dist/internal.d.ts +44 -0
  12. package/dist/lib/element.d.ts +154 -0
  13. package/dist/lib/element.js +635 -0
  14. package/dist/lib/node.d.ts +146 -0
  15. package/dist/lib/node.js +419 -0
  16. package/dist/lib/range.d.ts +104 -0
  17. package/dist/lib/range.js +385 -0
  18. package/dist/lib/ranges.d.ts +26 -0
  19. package/dist/lib/ranges.js +118 -0
  20. package/dist/lib/text.d.ts +62 -0
  21. package/dist/lib/text.js +265 -0
  22. package/dist/lib/title.d.ts +38 -0
  23. package/dist/lib/title.js +163 -0
  24. package/dist/mixin/attributesParent.d.ts +20 -0
  25. package/dist/mixin/attributesParent.js +89 -0
  26. package/dist/mixin/fixed.d.ts +5 -0
  27. package/dist/mixin/fixed.js +28 -0
  28. package/dist/mixin/flagsParent.d.ts +61 -0
  29. package/dist/mixin/flagsParent.js +70 -0
  30. package/dist/mixin/hidden.d.ts +5 -0
  31. package/dist/mixin/hidden.js +24 -0
  32. package/dist/mixin/magicLinkParent.d.ts +34 -0
  33. package/dist/mixin/magicLinkParent.js +41 -0
  34. package/dist/mixin/singleLine.d.ts +5 -0
  35. package/dist/mixin/singleLine.js +25 -0
  36. package/dist/mixin/sol.d.ts +8 -0
  37. package/dist/mixin/sol.js +43 -0
  38. package/dist/mixin/syntax.d.ts +6 -0
  39. package/dist/mixin/syntax.js +54 -0
  40. package/dist/parser/braces.js +131 -0
  41. package/dist/parser/commentAndExt.js +90 -0
  42. package/dist/parser/converter.js +41 -0
  43. package/dist/parser/externalLinks.js +32 -0
  44. package/dist/parser/hrAndDoubleUnderscore.js +41 -0
  45. package/dist/parser/html.js +39 -0
  46. package/dist/parser/links.js +95 -0
  47. package/dist/parser/list.js +68 -0
  48. package/dist/parser/magicLinks.js +43 -0
  49. package/dist/parser/quotes.js +68 -0
  50. package/dist/parser/selector.js +162 -0
  51. package/dist/parser/table.js +124 -0
  52. package/dist/src/arg.d.ts +58 -0
  53. package/dist/src/arg.js +195 -0
  54. package/dist/src/atom.d.ts +12 -0
  55. package/dist/src/atom.js +27 -0
  56. package/dist/src/attribute.d.ts +67 -0
  57. package/dist/src/attribute.js +423 -0
  58. package/dist/src/attributes.d.ts +109 -0
  59. package/dist/src/attributes.js +347 -0
  60. package/dist/src/converter.d.ts +28 -0
  61. package/dist/src/converter.js +86 -0
  62. package/dist/src/converterFlags.d.ts +87 -0
  63. package/dist/src/converterFlags.js +225 -0
  64. package/dist/src/converterRule.d.ts +77 -0
  65. package/dist/src/converterRule.js +209 -0
  66. package/dist/src/extLink.d.ts +38 -0
  67. package/dist/src/extLink.js +133 -0
  68. package/dist/src/gallery.d.ts +54 -0
  69. package/dist/src/gallery.js +127 -0
  70. package/dist/src/heading.d.ts +47 -0
  71. package/dist/src/heading.js +144 -0
  72. package/dist/src/hidden.d.ts +7 -0
  73. package/dist/src/hidden.js +23 -0
  74. package/dist/src/html.d.ts +62 -0
  75. package/dist/src/html.js +285 -0
  76. package/dist/src/imageParameter.d.ts +65 -0
  77. package/dist/src/imageParameter.js +248 -0
  78. package/dist/src/imagemap.d.ts +56 -0
  79. package/dist/src/imagemap.js +152 -0
  80. package/dist/src/imagemapLink.d.ts +28 -0
  81. package/dist/src/imagemapLink.js +44 -0
  82. package/dist/src/index.d.ts +143 -0
  83. package/dist/src/index.js +791 -0
  84. package/dist/src/link/base.d.ts +52 -0
  85. package/dist/src/link/base.js +209 -0
  86. package/dist/src/link/category.d.ts +13 -0
  87. package/dist/src/link/category.js +28 -0
  88. package/dist/src/link/file.d.ts +96 -0
  89. package/dist/src/link/file.js +262 -0
  90. package/dist/src/link/galleryImage.d.ts +31 -0
  91. package/dist/src/link/galleryImage.js +105 -0
  92. package/dist/src/link/index.d.ts +56 -0
  93. package/dist/src/link/index.js +134 -0
  94. package/dist/src/magicLink.d.ts +51 -0
  95. package/dist/src/magicLink.js +148 -0
  96. package/dist/src/nested.d.ts +43 -0
  97. package/dist/src/nested.js +90 -0
  98. package/dist/src/nowiki/base.d.ts +27 -0
  99. package/dist/src/nowiki/base.js +42 -0
  100. package/dist/src/nowiki/comment.d.ts +27 -0
  101. package/dist/src/nowiki/comment.js +74 -0
  102. package/dist/src/nowiki/dd.d.ts +8 -0
  103. package/dist/src/nowiki/dd.js +24 -0
  104. package/dist/src/nowiki/doubleUnderscore.d.ts +18 -0
  105. package/dist/src/nowiki/doubleUnderscore.js +50 -0
  106. package/dist/src/nowiki/hr.d.ts +8 -0
  107. package/dist/src/nowiki/hr.js +13 -0
  108. package/dist/src/nowiki/index.d.ts +16 -0
  109. package/dist/src/nowiki/index.js +20 -0
  110. package/dist/src/nowiki/list.d.ts +19 -0
  111. package/dist/src/nowiki/list.js +47 -0
  112. package/dist/src/nowiki/listBase.d.ts +5 -0
  113. package/dist/src/nowiki/listBase.js +11 -0
  114. package/dist/src/nowiki/noinclude.d.ts +10 -0
  115. package/dist/src/nowiki/noinclude.js +23 -0
  116. package/dist/src/nowiki/quote.d.ts +14 -0
  117. package/dist/src/nowiki/quote.js +68 -0
  118. package/dist/src/onlyinclude.d.ts +16 -0
  119. package/dist/src/onlyinclude.js +57 -0
  120. package/dist/src/paramTag/index.d.ts +37 -0
  121. package/dist/src/paramTag/index.js +68 -0
  122. package/dist/src/paramTag/inputbox.d.ts +8 -0
  123. package/dist/src/paramTag/inputbox.js +22 -0
  124. package/dist/src/parameter.d.ts +67 -0
  125. package/dist/src/parameter.js +215 -0
  126. package/dist/src/pre.d.ts +28 -0
  127. package/dist/src/pre.js +54 -0
  128. package/dist/src/syntax.d.ts +14 -0
  129. package/dist/src/syntax.js +34 -0
  130. package/dist/src/table/base.d.ts +27 -0
  131. package/dist/src/table/base.js +80 -0
  132. package/dist/src/table/index.d.ts +230 -0
  133. package/dist/src/table/index.js +385 -0
  134. package/dist/src/table/td.d.ts +88 -0
  135. package/dist/src/table/td.js +273 -0
  136. package/dist/src/table/tr.d.ts +32 -0
  137. package/dist/src/table/tr.js +57 -0
  138. package/dist/src/table/trBase.d.ts +53 -0
  139. package/dist/src/table/trBase.js +154 -0
  140. package/dist/src/tagPair/ext.d.ts +29 -0
  141. package/dist/src/tagPair/ext.js +151 -0
  142. package/dist/src/tagPair/include.d.ts +37 -0
  143. package/dist/src/tagPair/include.js +71 -0
  144. package/dist/src/tagPair/index.d.ts +27 -0
  145. package/dist/src/tagPair/index.js +76 -0
  146. package/dist/src/transclude.d.ts +167 -0
  147. package/dist/src/transclude.js +700 -0
  148. package/dist/util/constants.js +113 -0
  149. package/dist/util/debug.js +83 -0
  150. package/dist/util/diff.js +72 -0
  151. package/dist/util/lint.js +30 -0
  152. package/dist/util/string.js +53 -0
  153. package/errors/README +1 -0
  154. package/package.json +14 -30
  155. package/printed/README +1 -0
  156. package/bundle/bundle.min.js +0 -36
  157. package/extensions/dist/base.js +0 -64
  158. package/extensions/dist/editor.js +0 -159
  159. package/extensions/dist/highlight.js +0 -59
  160. package/extensions/dist/lint.js +0 -48
  161. package/extensions/editor.css +0 -63
  162. package/extensions/ui.css +0 -141
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.flagsParent = void 0;
4
+ const constants_1 = require("../util/constants");
5
+ /**
6
+ * ConverterToken
7
+ * @param constructor 基类
8
+ */
9
+ const flagsParent = (constructor) => {
10
+ /** 子节点含有ConverterFlagsToken的类 */
11
+ class FlagsParent extends constructor {
12
+ /** 所有转换类型标记 */
13
+ get flags() {
14
+ return this.firstChild.flags;
15
+ }
16
+ set flags(value) {
17
+ this.firstChild.flags = value;
18
+ }
19
+ /** 获取所有转换类型标记 */
20
+ getAllFlags() {
21
+ return this.firstChild.getAllFlags();
22
+ }
23
+ /** 获取有效的转换类型标记 */
24
+ getEffectiveFlags() {
25
+ return this.firstChild.getEffectiveFlags();
26
+ }
27
+ /** 获取未知的转换类型标记 */
28
+ getUnknownFlags() {
29
+ return this.firstChild.getUnknownFlags();
30
+ }
31
+ /**
32
+ * 是否具有某转换类型标记
33
+ * @param flag 转换类型标记
34
+ */
35
+ hasFlag(flag) {
36
+ return this.firstChild.hasFlag(flag);
37
+ }
38
+ /**
39
+ * 是否具有某有效的转换类型标记
40
+ * @param flag 转换类型标记
41
+ */
42
+ hasEffectiveFlag(flag) {
43
+ return this.firstChild.hasEffectiveFlag(flag);
44
+ }
45
+ /**
46
+ * 移除转换类型标记
47
+ * @param flag 转换类型标记
48
+ */
49
+ removeFlag(flag) {
50
+ this.firstChild.removeFlag(flag);
51
+ }
52
+ /**
53
+ * 设置转换类型标记
54
+ * @param flag 转换类型标记
55
+ */
56
+ setFlag(flag) {
57
+ this.firstChild.setFlag(flag);
58
+ }
59
+ /**
60
+ * 开关某转换类型标记
61
+ * @param flag 转换类型标记
62
+ */
63
+ toggleFlag(flag) {
64
+ this.firstChild.toggleFlag(flag);
65
+ }
66
+ }
67
+ return FlagsParent;
68
+ };
69
+ exports.flagsParent = flagsParent;
70
+ constants_1.mixins['flagsParent'] = __filename;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 解析后不可见的类
3
+ * @param constructor 基类
4
+ */
5
+ export declare const hiddenToken: <T extends AstConstructor>(constructor: T) => T;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hiddenToken = void 0;
4
+ const constants_1 = require("../util/constants");
5
+ /**
6
+ * 解析后不可见的类
7
+ * @param constructor 基类
8
+ */
9
+ const hiddenToken = (constructor) => {
10
+ /** 解析后不可见的类 */
11
+ class AnyHiddenToken extends constructor {
12
+ /** 没有可见部分 */
13
+ text() {
14
+ return '';
15
+ }
16
+ /** @override */
17
+ lint() {
18
+ return [];
19
+ }
20
+ }
21
+ return AnyHiddenToken;
22
+ };
23
+ exports.hiddenToken = hiddenToken;
24
+ constants_1.mixins['hiddenToken'] = __filename;
@@ -0,0 +1,34 @@
1
+ import type { MagicLinkToken } from '../src/magicLink';
2
+ export interface MagicLinkParentBase {
3
+ protocol: string | undefined;
4
+ link: string;
5
+ getUrl(): URL;
6
+ setTarget(url: string): void;
7
+ }
8
+ /**
9
+ * ExtLinkToken
10
+ * @param constructor 基类
11
+ */
12
+ export declare const magicLinkParent: <T extends AstConstructor>(constructor: T) => (abstract new (...args: any[]) => {
13
+ readonly firstChild: MagicLinkToken;
14
+ readonly firstElementChild: MagicLinkToken;
15
+ /** 协议 */
16
+ protocol: string | undefined;
17
+ /** 和内链保持一致 */
18
+ link: string;
19
+ /** 获取网址 */
20
+ getUrl(): URL;
21
+ /**
22
+ * 设置链接目标
23
+ * @param url 网址
24
+ */
25
+ setTarget(url: string): void;
26
+ toString(omit?: Set<string> | undefined, separator?: string | undefined): string;
27
+ text(separator?: string | undefined): string;
28
+ insertAt(token: unknown, i?: number | undefined): unknown;
29
+ getAttribute<T_1 extends string>(key: T_1): TokenAttributeGetter<T_1>;
30
+ setAttribute<T_2 extends string>(key: T_2, value: TokenAttributeSetter<T_2>): void;
31
+ addEventListener(events: string | string[], listener: AstListener): void;
32
+ replaceChildren(...elements: (string | import("..").AstNodes)[]): void;
33
+ constructorError(msg: string): never;
34
+ }) & T;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.magicLinkParent = void 0;
4
+ const constants_1 = require("../util/constants");
5
+ /**
6
+ * ExtLinkToken
7
+ * @param constructor 基类
8
+ */
9
+ const magicLinkParent = (constructor) => {
10
+ /** 子节点含有MagicLinkParent的类 */
11
+ class MagicLinkParent extends constructor {
12
+ /** 协议 */
13
+ get protocol() {
14
+ return this.firstChild.protocol;
15
+ }
16
+ set protocol(value) {
17
+ this.firstChild.protocol = value;
18
+ }
19
+ /** 和内链保持一致 */
20
+ get link() {
21
+ return this.firstChild.link;
22
+ }
23
+ set link(url) {
24
+ this.firstChild.link = url;
25
+ }
26
+ /** 获取网址 */
27
+ getUrl() {
28
+ return this.firstChild.getUrl();
29
+ }
30
+ /**
31
+ * 设置链接目标
32
+ * @param url 网址
33
+ */
34
+ setTarget(url) {
35
+ this.firstChild.setTarget(url);
36
+ }
37
+ }
38
+ return MagicLinkParent;
39
+ };
40
+ exports.magicLinkParent = magicLinkParent;
41
+ constants_1.mixins['magicLinkParent'] = __filename;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 不可包含换行符的类
3
+ * @param constructor 基类
4
+ */
5
+ export declare const singleLine: <T extends AstConstructor>(constructor: T) => T;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.singleLine = void 0;
4
+ const constants_1 = require("../util/constants");
5
+ /**
6
+ * 不可包含换行符的类
7
+ * @param constructor 基类
8
+ */
9
+ const singleLine = (constructor) => {
10
+ /** 不可包含换行符的类 */
11
+ class SingleLineToken extends constructor {
12
+ /** @private */
13
+ toString(omit) {
14
+ return super.toString(omit).replace(/\n/gu, ' ');
15
+ }
16
+ /** @override */
17
+ text() {
18
+ return super.text().replace(/\n/gu, ' ');
19
+ }
20
+ }
21
+ Object.defineProperty(SingleLineToken, 'name', { value: `SingleLine${constructor.name}` });
22
+ return SingleLineToken;
23
+ };
24
+ exports.singleLine = singleLine;
25
+ constants_1.mixins['singleLine'] = __filename;
@@ -0,0 +1,8 @@
1
+ export interface SolTokenBase {
2
+ prependNewLine(): string;
3
+ }
4
+ /**
5
+ * 只能位于行首的类
6
+ * @param constructor 基类
7
+ */
8
+ export declare const sol: <T extends AstConstructor>(constructor: T) => T;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sol = void 0;
4
+ const constants_1 = require("../util/constants");
5
+ /**
6
+ * 只能位于行首的类
7
+ * @param constructor 基类
8
+ */
9
+ const sol = (constructor) => {
10
+ /** 只能位于行首的类 */
11
+ class SolToken extends constructor {
12
+ /** 在前方插入newline */
13
+ prependNewLine() {
14
+ const { previousVisibleSibling, parentNode, type } = this;
15
+ if (previousVisibleSibling) {
16
+ return String(previousVisibleSibling).endsWith('\n') ? '' : '\n';
17
+ }
18
+ return parentNode?.type === 'root'
19
+ || type !== 'heading' && parentNode?.type === 'ext-inner' && parentNode.name === 'poem'
20
+ ? ''
21
+ : '\n';
22
+ }
23
+ /** @private */
24
+ toString(omit) {
25
+ return omit && this.matchesTypes(omit)
26
+ ? ''
27
+ : `${this.prependNewLine()}${super.toString(omit)}`;
28
+ }
29
+ /** @private */
30
+ getAttribute(key) {
31
+ return key === 'padding'
32
+ ? this.prependNewLine().length
33
+ : super.getAttribute(key);
34
+ }
35
+ /** @override */
36
+ text() {
37
+ return `${this.prependNewLine()}${super.text()}`;
38
+ }
39
+ }
40
+ return SolToken;
41
+ };
42
+ exports.sol = sol;
43
+ constants_1.mixins['sol'] = __filename;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 满足特定语法格式的Token
3
+ * @param constructor 基类
4
+ * @param pattern 语法正则
5
+ */
6
+ export declare const syntax: <S extends AstConstructor>(constructor: S, pattern?: RegExp) => S;
@@ -0,0 +1,54 @@
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 constructor 基类
10
+ * @param pattern 语法正则
11
+ */
12
+ const syntax = (constructor, pattern) => {
13
+ /** 满足特定语法格式的Token */
14
+ class SyntaxToken extends constructor {
15
+ #pattern = pattern;
16
+ /** @private */
17
+ afterBuild() {
18
+ const /** @implements */ syntaxListener = (e, data) => {
19
+ if (!debug_1.Shadow.running && !this.#pattern.test(this.text())) {
20
+ (0, debug_1.undo)(e, data);
21
+ this.constructorError('不可修改语法');
22
+ }
23
+ };
24
+ this.addEventListener(['remove', 'insert', 'replace', 'text'], syntaxListener);
25
+ }
26
+ /** @private */
27
+ getAttribute(key) {
28
+ return key === 'pattern' ? this.#pattern : super.getAttribute(key);
29
+ }
30
+ /** @private */
31
+ setAttribute(key, value) {
32
+ if (key === 'pattern') {
33
+ this.#pattern = value;
34
+ }
35
+ else {
36
+ super.setAttribute(key, value);
37
+ }
38
+ }
39
+ /**
40
+ * @override
41
+ * @param elements 待替换的子节点
42
+ */
43
+ replaceChildren(...elements) {
44
+ if (debug_1.Shadow.running || this.#pattern.test((0, string_1.text)(elements))) {
45
+ debug_1.Shadow.run(() => {
46
+ super.replaceChildren(...elements);
47
+ });
48
+ }
49
+ }
50
+ }
51
+ return SyntaxToken;
52
+ };
53
+ exports.syntax = syntax;
54
+ constants_1.mixins['syntax'] = __filename;
@@ -0,0 +1,131 @@
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 Parser = require("../index");
7
+ const heading_1 = require("../src/heading");
8
+ const transclude_1 = require("../src/transclude");
9
+ const arg_1 = require("../src/arg");
10
+ /**
11
+ * 解析花括号
12
+ * @param wikitext
13
+ * @param config
14
+ * @param accum
15
+ * @throws TranscludeToken.constructor()
16
+ */
17
+ const parseBraces = (wikitext, config = Parser.getConfig(), accum = []) => {
18
+ const source = `${config.excludes?.includes('heading') ? '' : '^(\0\\d+c\x7F)*={1,6}|'}\\[\\[|\\{{2,}|-\\{(?!\\{)`, { parserFunction: [, , , subst] } = config, stack = [], closes = { '=': '\n', '{': '\\}{2,}|\\|', '-': '\\}-', '[': '\\]\\]' }, marks = new Map([['!', '!'], ['!!', '+'], ['(!', '{'], ['!)', '}'], ['!-', '-'], ['=', '~']]);
19
+ let regex = new RegExp(source, 'gmu'), mt = regex.exec(wikitext), moreBraces = wikitext.includes('}}'), lastIndex;
20
+ while (mt
21
+ || lastIndex !== undefined && lastIndex <= wikitext.length && stack[stack.length - 1]?.[0]?.startsWith('=')) {
22
+ if (mt?.[1]) {
23
+ const [, { length }] = mt;
24
+ mt[0] = mt[0].slice(length);
25
+ mt.index += length;
26
+ }
27
+ 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;
28
+ /**
29
+ * 填入模板内容
30
+ * @param text wikitext全文
31
+ */
32
+ const push = (text) => {
33
+ parts[parts.length - 1].push(text.slice(topPos, curIndex));
34
+ };
35
+ if (syntax === ']]' || syntax === '}-') { // 情形1:闭合内链或转换
36
+ lastIndex = curIndex + 2;
37
+ }
38
+ else if (syntax === '\n') { // 情形2:闭合标题或文末
39
+ lastIndex = curIndex + 1;
40
+ const { pos, findEqual } = stack[stack.length - 1] ?? {};
41
+ if (pos === undefined || findEqual || (0, string_1.removeComment)(wikitext.slice(pos, index)) !== '') {
42
+ const rmt = /^(={1,6})(.+)\1((?:\s|\0\d+c\x7F)*)$/u
43
+ .exec(wikitext.slice(index, curIndex));
44
+ if (rmt) {
45
+ wikitext = `${wikitext.slice(0, index)}\0${accum.length}h\x7F${wikitext.slice(curIndex)}`;
46
+ lastIndex = index + 4 + String(accum.length).length;
47
+ // @ts-expect-error abstract class
48
+ new heading_1.HeadingToken(rmt[1].length, rmt.slice(2), config, accum);
49
+ }
50
+ }
51
+ }
52
+ else if (syntax === '|' || innerEqual) { // 情形3:模板内部,含行首单个'='
53
+ lastIndex = curIndex + 1;
54
+ push(wikitext);
55
+ if (syntax === '|') {
56
+ parts.push([]);
57
+ }
58
+ top.pos = lastIndex;
59
+ top.findEqual = syntax === '|';
60
+ stack.push(top);
61
+ }
62
+ else if (syntax.startsWith('}}')) { // 情形4:闭合模板
63
+ const close = syntax.slice(0, Math.min(open.length, 3)), rest = open.length - close.length, { length } = accum;
64
+ lastIndex = curIndex + close.length; // 这不是最终的lastIndex
65
+ push(wikitext);
66
+ let skip = false, ch = 't';
67
+ if (close.length === 3) {
68
+ const argParts = parts.map(part => part.join('=')), str = argParts.length > 1 && (0, string_1.removeComment)(argParts[1]).trim();
69
+ // @ts-expect-error abstract class
70
+ new arg_1.ArgToken(argParts, config, accum);
71
+ if (str && str.endsWith(':') && subst.includes(str.slice(0, -1).toLowerCase())) {
72
+ ch = 's';
73
+ }
74
+ }
75
+ else {
76
+ try {
77
+ // @ts-expect-error abstract class
78
+ new transclude_1.TranscludeToken(parts[0][0], parts.slice(1), config, accum);
79
+ const name = (0, string_1.removeComment)(parts[0][0]).trim();
80
+ if (marks.has(name)) {
81
+ ch = marks.get(name); // 标记{{!}}等
82
+ }
83
+ else if (/^(?:filepath|(?:full|canonical)urle?):.|^server$/iu.test(name)) {
84
+ ch = 'm';
85
+ }
86
+ else if (/^#vardefine:./iu.test(name)) {
87
+ ch = 'c';
88
+ }
89
+ }
90
+ catch (e) {
91
+ if (e instanceof SyntaxError && e.message === '非法的模板名称') {
92
+ skip = true;
93
+ }
94
+ else {
95
+ throw e;
96
+ }
97
+ }
98
+ }
99
+ if (!skip) {
100
+ wikitext = `${wikitext.slice(0, index + rest)}\0${length}${ch}\x7F${wikitext.slice(lastIndex)}`;
101
+ lastIndex = index + rest + 3 + String(length).length;
102
+ if (rest > 1) {
103
+ stack.push({ 0: open.slice(0, rest), index: index, pos: index + rest, parts: [[]] });
104
+ }
105
+ else if (rest === 1 && wikitext[index - 1] === '-') {
106
+ stack.push({ 0: '-{', index: index - 1, pos: index + 1, parts: [[]] });
107
+ }
108
+ }
109
+ }
110
+ else { // 情形5:开启
111
+ lastIndex = curIndex + syntax.length;
112
+ if (syntax.startsWith('{')) {
113
+ mt.pos = lastIndex;
114
+ mt.parts = [[]];
115
+ }
116
+ stack.push(...'0' in top ? [top] : [], mt);
117
+ }
118
+ moreBraces &&= wikitext.slice(lastIndex).includes('}}');
119
+ let curTop = stack[stack.length - 1];
120
+ if (!moreBraces && curTop?.[0]?.startsWith('{')) {
121
+ stack.pop();
122
+ curTop = stack[stack.length - 1];
123
+ }
124
+ regex = new RegExp(source + (curTop ? `|${closes[curTop[0][0]]}${curTop.findEqual ? '|=' : ''}` : ''), 'gmu');
125
+ regex.lastIndex = lastIndex;
126
+ mt = regex.exec(wikitext);
127
+ }
128
+ return wikitext;
129
+ };
130
+ exports.parseBraces = parseBraces;
131
+ constants_1.parsers['parseBraces'] = __filename;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseCommentAndExt = void 0;
4
+ const constants_1 = require("../util/constants");
5
+ const Parser = require("../index");
6
+ const onlyinclude_1 = require("../src/onlyinclude");
7
+ const noinclude_1 = require("../src/nowiki/noinclude");
8
+ const include_1 = require("../src/tagPair/include");
9
+ const ext_1 = require("../src/tagPair/ext");
10
+ const comment_1 = require("../src/nowiki/comment");
11
+ /**
12
+ * 解析HTML注释和扩展标签
13
+ * @param wikitext
14
+ * @param config
15
+ * @param accum
16
+ * @param includeOnly 是否嵌入
17
+ */
18
+ const parseCommentAndExt = (wikitext, config = Parser.getConfig(), accum = [], includeOnly = false) => {
19
+ const onlyincludeLeft = '<onlyinclude>', onlyincludeRight = '</onlyinclude>', { length } = onlyincludeLeft;
20
+ /** 更新`<onlyinclude>`和`</onlyinclude>`的位置 */
21
+ const update = () => {
22
+ const i = wikitext.indexOf(onlyincludeLeft);
23
+ return { i, j: wikitext.indexOf(onlyincludeRight, i + length) };
24
+ };
25
+ if (includeOnly) {
26
+ let { i, j } = update();
27
+ if (i !== -1 && j !== -1) { // `<onlyinclude>`拥有最高优先级
28
+ let str = '';
29
+ /**
30
+ * 忽略未被`<onlyinclude>`和`</onlyinclude>`包裹的内容
31
+ * @param text 未被包裹的内容
32
+ */
33
+ const noinclude = (text) => {
34
+ // @ts-expect-error abstract class
35
+ new noinclude_1.NoincludeToken(text, config, accum);
36
+ str += `\0${accum.length - 1}c\x7F`;
37
+ };
38
+ while (i !== -1 && j !== -1) {
39
+ const token = `\0${accum.length}e\x7F`;
40
+ new onlyinclude_1.OnlyincludeToken(wikitext.slice(i + length, j), config, accum);
41
+ if (i > 0) {
42
+ noinclude(wikitext.slice(0, i));
43
+ }
44
+ str += token;
45
+ wikitext = wikitext.slice(j + length + 1);
46
+ ({ i, j } = update());
47
+ }
48
+ if (wikitext) {
49
+ noinclude(wikitext);
50
+ }
51
+ return str;
52
+ }
53
+ }
54
+ /* eslint-disable @typescript-eslint/no-unused-expressions */
55
+ /<foo(?:\s[^>]*)?>|<\/foo\s*>/giu;
56
+ /<(bar)(\s[^>]*?)?(?:\/>|>(.*?)<\/(\1\s*)>)/gisu;
57
+ /<(baz)(\s[^>]*?)?(?:\/>|>(.*?)(?:<\/(baz\s*)>|$))/gisu;
58
+ /* eslint-enable @typescript-eslint/no-unused-expressions */
59
+ const ext = config.ext.join('|'), noincludeRegex = includeOnly ? 'includeonly' : '(?:no|only)include', includeRegex = includeOnly ? 'noinclude' : 'includeonly', regex = new RegExp('<!--.*?(?:-->|$)' // comment
60
+ + '|'
61
+ + `<${noincludeRegex}(?:\\s[^>]*)?>|</${noincludeRegex}\\s*>` // <noinclude>
62
+ + '|'
63
+ + `<(${ext})(\\s[^>]*?)?(?:/>|>(.*?)</(\\1\\s*)>)` // 扩展标签
64
+ + '|'
65
+ + `<(${includeRegex})(\\s[^>]*?)?(?:/>|>(.*?)(?:</(${includeRegex}\\s*)>|$))`, // <includeonly>
66
+ 'gisu');
67
+ return wikitext.replace(regex, (substr, name, attr, inner, closing, include, includeAttr, includeInner, includeClosing) => {
68
+ const str = `\0${accum.length}${name ? 'e' : 'c'}\x7F`;
69
+ if (name) {
70
+ // @ts-expect-error abstract class
71
+ new ext_1.ExtToken(name, attr, inner, closing, config, accum);
72
+ }
73
+ else if (substr.startsWith('<!--')) {
74
+ const closed = substr.endsWith('-->');
75
+ // @ts-expect-error abstract class
76
+ new comment_1.CommentToken(substr.slice(4, closed ? -3 : undefined), closed, config, accum);
77
+ }
78
+ else if (include) {
79
+ // @ts-expect-error abstract class
80
+ new include_1.IncludeToken(include, includeAttr, includeInner, includeClosing, config, accum);
81
+ }
82
+ else {
83
+ // @ts-expect-error abstract class
84
+ new noinclude_1.NoincludeToken(substr, config, accum);
85
+ }
86
+ return str;
87
+ });
88
+ };
89
+ exports.parseCommentAndExt = parseCommentAndExt;
90
+ constants_1.parsers['parseCommentAndExt'] = __filename;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseConverter = void 0;
4
+ const constants_1 = require("../util/constants");
5
+ const Parser = require("../index");
6
+ const converter_1 = require("../src/converter");
7
+ /**
8
+ * 解析语言变体转换
9
+ * @param text
10
+ * @param config
11
+ * @param accum
12
+ */
13
+ const parseConverter = (text, config = Parser.getConfig(), accum = []) => {
14
+ const regex1 = /-\{/gu, regex2 = /-\{|\}-/gu, stack = [];
15
+ let regex = regex1, mt = regex.exec(text);
16
+ while (mt) {
17
+ const { 0: syntax, index } = mt;
18
+ if (syntax === '}-') {
19
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
20
+ /;(?=(?:[^;]*?=>)?\s*foo\s*:|(?:\s|\0\d+c\x7F)*$)/u;
21
+ const top = stack.pop(), { length } = accum, str = text.slice(top.index + 2, index), i = str.indexOf('|'), [flags, raw] = i === -1 ? [[], str] : [str.slice(0, i).split(';'), str.slice(i + 1)], temp = raw.replace(/(&[#a-z\d]+);/giu, '$1\x01'), variants = `(?:${config.variants.join('|')})`, rules = temp.split(new RegExp(`;(?=(?:[^;]*?=>)?\\s*${variants}\\s*:|(?:\\s|\0\\d+c\x7F)*$)`, 'u'))
22
+ .map(rule => rule.replace(/\x01/gu, ';'));
23
+ // @ts-expect-error abstract class
24
+ new converter_1.ConverterToken(flags, rules, config, accum);
25
+ text = `${text.slice(0, top.index)}\0${length}v\x7F${text.slice(index + 2)}`;
26
+ if (stack.length === 0) {
27
+ regex = regex1;
28
+ }
29
+ regex.lastIndex = top.index + 3 + String(length).length;
30
+ }
31
+ else {
32
+ stack.push(mt);
33
+ regex = regex2;
34
+ regex.lastIndex = index + 2;
35
+ }
36
+ mt = regex.exec(text);
37
+ }
38
+ return text;
39
+ };
40
+ exports.parseConverter = parseConverter;
41
+ constants_1.parsers['parseConverter'] = __filename;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseExternalLinks = void 0;
4
+ const string_1 = require("../util/string");
5
+ const constants_1 = require("../util/constants");
6
+ const Parser = require("../index");
7
+ const extLink_1 = require("../src/extLink");
8
+ /**
9
+ * 解析外部链接
10
+ * @param wikitext
11
+ * @param config
12
+ * @param accum
13
+ */
14
+ const parseExternalLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
15
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
16
+ /\[((?:\[[\da-f:.]+\]|[^[\]\t\n\p{Zs}])[^[\]\t\n\p{Zs}]*(?=[[\]\t\p{Zs}]|\0\d))(\p{Zs}*(?=\P{Zs}))([^\]\n]*)\]/giu;
17
+ const regex = new RegExp(`\\[((?:(?:${config.protocol}|//)${string_1.extUrlCharFirst}|\0\\d+m\x7F)${string_1.extUrlChar}(?=[[\\]<>"\\t\\p{Zs}]|\0\\d))`
18
+ + '(\\p{Zs}*(?=\\P{Zs}))([^\\]\x01-\x08\x0A-\x1F\uFFFD]*)\\]', 'giu');
19
+ return wikitext.replace(regex, (_, url, space, text) => {
20
+ const { length } = accum, mt = /&[lg]t;/u.exec(url);
21
+ if (mt) {
22
+ url = url.slice(0, mt.index);
23
+ space = '';
24
+ text = `${url.slice(mt.index)}${space}${text}`;
25
+ }
26
+ // @ts-expect-error abstract class
27
+ new extLink_1.ExtLinkToken(url, space, text, config, accum);
28
+ return `\0${length}w\x7F`;
29
+ });
30
+ };
31
+ exports.parseExternalLinks = parseExternalLinks;
32
+ constants_1.parsers['parseExternalLinks'] = __filename;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseHrAndDoubleUnderscore = void 0;
4
+ const constants_1 = require("../util/constants");
5
+ const Parser = require("../index");
6
+ const hr_1 = require("../src/nowiki/hr");
7
+ const doubleUnderscore_1 = require("../src/nowiki/doubleUnderscore");
8
+ const heading_1 = require("../src/heading");
9
+ /**
10
+ * 解析`<hr>`和状态开关
11
+ * @param {Token} root 根节点
12
+ * @param config
13
+ * @param accum
14
+ */
15
+ const parseHrAndDoubleUnderscore = ({ firstChild: { data }, type, name }, config = Parser.getConfig(), accum = []) => {
16
+ const { doubleUnderscore } = config, insensitive = new Set(doubleUnderscore[0]), sensitive = new Set(doubleUnderscore[1]);
17
+ if (type !== 'root' && (type !== 'ext-inner' || name !== 'poem')) {
18
+ data = `\0${data}`;
19
+ }
20
+ data = data.replace(/^((?:\0\d+c\x7F)*)(-{4,})/gmu, (_, lead, m) => {
21
+ // @ts-expect-error abstract class
22
+ new hr_1.HrToken(m, config, accum);
23
+ return `${lead}\0${accum.length - 1}r\x7F`;
24
+ }).replace(new RegExp(`__(${doubleUnderscore.flat().join('|')})__`, 'giu'), (m, p1) => {
25
+ const caseSensitive = sensitive.has(p1);
26
+ if (caseSensitive || insensitive.has(p1.toLowerCase())) {
27
+ // @ts-expect-error abstract class
28
+ new doubleUnderscore_1.DoubleUnderscoreToken(p1, caseSensitive, config, accum);
29
+ return `\0${accum.length - 1}u\x7F`;
30
+ }
31
+ return m;
32
+ }).replace(/^((?:\0\d+c\x7F)*)(={1,6})(.+)\2((?:[^\S\n]|\0\d+c\x7F)*)$/gmu, (_, lead, equals, heading, trail) => {
33
+ const text = `${lead}\0${accum.length}h\x7F`;
34
+ // @ts-expect-error abstract class
35
+ new heading_1.HeadingToken(equals.length, [heading, trail], config, accum);
36
+ return text;
37
+ });
38
+ return type === 'root' || type === 'ext-inner' && name === 'poem' ? data : data.slice(1);
39
+ };
40
+ exports.parseHrAndDoubleUnderscore = parseHrAndDoubleUnderscore;
41
+ constants_1.parsers['parseHrAndDoubleUnderscore'] = __filename;