wikiparser-node 1.2.0-b → 1.2.0

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 (154) hide show
  1. package/config/.schema.json +172 -0
  2. package/config/llwiki.json +35 -1
  3. package/config/moegirl.json +44 -1
  4. package/config/zhwiki.json +466 -1
  5. package/dist/addon/table.d.ts +6 -0
  6. package/dist/addon/table.js +564 -0
  7. package/dist/base.d.ts +46 -0
  8. package/dist/bin/toc.js +18 -0
  9. package/dist/index.d.ts +31 -0
  10. package/dist/index.js +209 -0
  11. package/dist/internal.d.ts +44 -0
  12. package/dist/lib/element.d.ts +155 -0
  13. package/dist/lib/element.js +654 -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 +117 -0
  20. package/dist/lib/text.d.ts +62 -0
  21. package/dist/lib/text.js +235 -0
  22. package/dist/lib/title.d.ts +38 -0
  23. package/dist/lib/title.js +162 -0
  24. package/dist/mixin/attributesParent.js +94 -0
  25. package/dist/mixin/fixed.js +32 -0
  26. package/dist/mixin/flagsParent.js +70 -0
  27. package/dist/mixin/hidden.js +22 -0
  28. package/dist/mixin/magicLinkParent.js +41 -0
  29. package/dist/mixin/singleLine.js +25 -0
  30. package/dist/mixin/sol.js +43 -0
  31. package/dist/mixin/syntax.js +56 -0
  32. package/dist/parser/braces.js +123 -0
  33. package/dist/parser/commentAndExt.js +69 -0
  34. package/dist/parser/converter.js +40 -0
  35. package/dist/parser/externalLinks.js +28 -0
  36. package/dist/parser/hrAndDoubleUnderscore.js +38 -0
  37. package/dist/parser/html.js +36 -0
  38. package/dist/parser/links.js +94 -0
  39. package/dist/parser/list.js +59 -0
  40. package/dist/parser/magicLinks.js +40 -0
  41. package/dist/parser/quotes.js +67 -0
  42. package/dist/parser/selector.js +162 -0
  43. package/dist/parser/table.js +112 -0
  44. package/dist/src/arg.d.ts +58 -0
  45. package/dist/src/arg.js +190 -0
  46. package/dist/src/atom.d.ts +12 -0
  47. package/dist/src/atom.js +27 -0
  48. package/dist/src/attribute.d.ts +86 -0
  49. package/dist/src/attribute.js +392 -0
  50. package/dist/src/attributes.d.ts +107 -0
  51. package/dist/src/attributes.js +344 -0
  52. package/dist/src/converter.d.ts +51 -0
  53. package/dist/src/converter.js +79 -0
  54. package/dist/src/converterFlags.d.ts +87 -0
  55. package/dist/src/converterFlags.js +223 -0
  56. package/dist/src/converterRule.d.ts +81 -0
  57. package/dist/src/converterRule.js +212 -0
  58. package/dist/src/extLink.d.ts +53 -0
  59. package/dist/src/extLink.js +121 -0
  60. package/dist/src/gallery.d.ts +55 -0
  61. package/dist/src/gallery.js +123 -0
  62. package/dist/src/heading.d.ts +72 -0
  63. package/dist/src/heading.js +128 -0
  64. package/dist/src/hidden.d.ts +21 -0
  65. package/dist/src/hidden.js +23 -0
  66. package/dist/src/html.d.ts +103 -0
  67. package/dist/src/html.js +230 -0
  68. package/dist/src/imageParameter.d.ts +66 -0
  69. package/dist/src/imageParameter.js +247 -0
  70. package/dist/src/imagemap.d.ts +57 -0
  71. package/dist/src/imagemap.js +148 -0
  72. package/dist/src/imagemapLink.d.ts +57 -0
  73. package/dist/src/imagemapLink.js +40 -0
  74. package/dist/src/index.d.ts +146 -0
  75. package/dist/src/index.js +777 -0
  76. package/dist/src/link/base.d.ts +52 -0
  77. package/dist/src/link/base.js +207 -0
  78. package/dist/src/link/category.d.ts +13 -0
  79. package/dist/src/link/category.js +29 -0
  80. package/dist/src/link/file.d.ts +96 -0
  81. package/dist/src/link/file.js +253 -0
  82. package/dist/src/link/galleryImage.d.ts +43 -0
  83. package/dist/src/link/galleryImage.js +106 -0
  84. package/dist/src/link/index.d.ts +53 -0
  85. package/dist/src/link/index.js +123 -0
  86. package/dist/src/magicLink.d.ts +69 -0
  87. package/dist/src/magicLink.js +148 -0
  88. package/dist/src/nested.d.ts +44 -0
  89. package/dist/src/nested.js +87 -0
  90. package/dist/src/nowiki/base.d.ts +46 -0
  91. package/dist/src/nowiki/base.js +42 -0
  92. package/dist/src/nowiki/comment.d.ts +39 -0
  93. package/dist/src/nowiki/comment.js +67 -0
  94. package/dist/src/nowiki/dd.d.ts +8 -0
  95. package/dist/src/nowiki/dd.js +25 -0
  96. package/dist/src/nowiki/doubleUnderscore.d.ts +43 -0
  97. package/dist/src/nowiki/doubleUnderscore.js +50 -0
  98. package/dist/src/nowiki/hr.d.ts +29 -0
  99. package/dist/src/nowiki/hr.js +14 -0
  100. package/dist/src/nowiki/index.d.ts +16 -0
  101. package/dist/src/nowiki/index.js +21 -0
  102. package/dist/src/nowiki/list.d.ts +29 -0
  103. package/dist/src/nowiki/list.js +48 -0
  104. package/dist/src/nowiki/listBase.d.ts +18 -0
  105. package/dist/src/nowiki/listBase.js +12 -0
  106. package/dist/src/nowiki/noinclude.d.ts +25 -0
  107. package/dist/src/nowiki/noinclude.js +25 -0
  108. package/dist/src/nowiki/quote.d.ts +22 -0
  109. package/dist/src/nowiki/quote.js +50 -0
  110. package/dist/src/onlyinclude.d.ts +16 -0
  111. package/dist/src/onlyinclude.js +57 -0
  112. package/dist/src/paramTag/index.d.ts +37 -0
  113. package/dist/src/paramTag/index.js +68 -0
  114. package/dist/src/paramTag/inputbox.d.ts +8 -0
  115. package/dist/src/paramTag/inputbox.js +23 -0
  116. package/dist/src/parameter.d.ts +84 -0
  117. package/dist/src/parameter.js +206 -0
  118. package/dist/src/pre.d.ts +28 -0
  119. package/dist/src/pre.js +51 -0
  120. package/dist/src/syntax.d.ts +24 -0
  121. package/dist/src/syntax.js +30 -0
  122. package/dist/src/table/base.d.ts +52 -0
  123. package/dist/src/table/base.js +78 -0
  124. package/dist/src/table/index.d.ts +229 -0
  125. package/dist/src/table/index.js +380 -0
  126. package/dist/src/table/td.d.ts +103 -0
  127. package/dist/src/table/td.js +261 -0
  128. package/dist/src/table/tr.d.ts +32 -0
  129. package/dist/src/table/tr.js +56 -0
  130. package/dist/src/table/trBase.d.ts +54 -0
  131. package/dist/src/table/trBase.js +159 -0
  132. package/dist/src/tagPair/ext.d.ts +58 -0
  133. package/dist/src/tagPair/ext.js +142 -0
  134. package/dist/src/tagPair/include.d.ts +52 -0
  135. package/dist/src/tagPair/include.js +58 -0
  136. package/dist/src/tagPair/index.d.ts +47 -0
  137. package/dist/src/tagPair/index.js +93 -0
  138. package/dist/src/transclude.d.ts +167 -0
  139. package/dist/src/transclude.js +689 -0
  140. package/dist/util/constants.js +108 -0
  141. package/dist/util/debug.js +64 -0
  142. package/dist/util/diff.js +72 -0
  143. package/dist/util/lint.js +48 -0
  144. package/dist/util/string.js +61 -0
  145. package/errors/README +1 -0
  146. package/package.json +12 -32
  147. package/printed/README +1 -0
  148. package/bundle/bundle.min.js +0 -36
  149. package/extensions/dist/base.js +0 -68
  150. package/extensions/dist/editor.js +0 -159
  151. package/extensions/dist/highlight.js +0 -30
  152. package/extensions/dist/lint.js +0 -48
  153. package/extensions/editor.css +0 -63
  154. package/extensions/ui.css +0 -117
@@ -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).replaceAll('\n', ' ');
15
+ }
16
+ /** @override */
17
+ text() {
18
+ return super.text().replaceAll('\n', ' ');
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,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,56 @@
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
+ const Parser = require("../index");
8
+ /**
9
+ * 满足特定语法格式的Token
10
+ * @param constructor 基类
11
+ * @param pattern 语法正则
12
+ */
13
+ const syntax = (constructor, pattern) => {
14
+ /** 满足特定语法格式的Token */
15
+ class SyntaxToken extends constructor {
16
+ #pattern = pattern;
17
+ /** @private */
18
+ afterBuild() {
19
+ const /** @implements */ syntaxListener = (e, data) => {
20
+ if (!debug_1.Shadow.running && !this.#pattern.test(this.text())) {
21
+ (0, debug_1.undo)(e, data);
22
+ Parser.error(`不可修改 ${this.constructor.name} 的语法!`, this.#pattern);
23
+ throw new Error(`不可修改 ${this.constructor.name} 的语法!`);
24
+ }
25
+ };
26
+ this.addEventListener(['remove', 'insert', 'replace', 'text'], syntaxListener);
27
+ }
28
+ /** @private */
29
+ getAttribute(key) {
30
+ return key === 'pattern' ? this.#pattern : super.getAttribute(key);
31
+ }
32
+ /** @private */
33
+ setAttribute(key, value) {
34
+ if (key === 'pattern') {
35
+ this.#pattern = value;
36
+ }
37
+ else {
38
+ super.setAttribute(key, value);
39
+ }
40
+ }
41
+ /**
42
+ * @override
43
+ * @param elements 待替换的子节点
44
+ */
45
+ replaceChildren(...elements) {
46
+ if (debug_1.Shadow.running || this.#pattern.test((0, string_1.text)(elements))) {
47
+ debug_1.Shadow.run(() => {
48
+ super.replaceChildren(...elements);
49
+ });
50
+ }
51
+ }
52
+ }
53
+ return SyntaxToken;
54
+ };
55
+ exports.syntax = syntax;
56
+ constants_1.mixins['syntax'] = __filename;
@@ -0,0 +1,123 @@
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
22
+ && stack.at(-1)?.[0]?.startsWith('=')) {
23
+ if (mt?.[1]) {
24
+ const [, { length }] = mt;
25
+ mt[0] = mt[0].slice(length);
26
+ mt.index += length;
27
+ }
28
+ 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;
29
+ if (syntax === ']]' || syntax === '}-') { // 情形1:闭合内链或转换
30
+ lastIndex = curIndex + 2;
31
+ }
32
+ else if (syntax === '\n') { // 情形2:闭合标题或文末
33
+ lastIndex = curIndex + 1;
34
+ const { pos, findEqual } = stack.at(-1) ?? {};
35
+ if (pos === undefined || findEqual || (0, string_1.removeComment)(wikitext.slice(pos, index)) !== '') {
36
+ const rmt = /^(={1,6})(.+)\1((?:\s|\0\d+c\x7F)*)$/u
37
+ .exec(wikitext.slice(index, curIndex));
38
+ if (rmt) {
39
+ wikitext = `${wikitext.slice(0, index)}\0${accum.length}h\x7F${wikitext.slice(curIndex)}`;
40
+ lastIndex = index + 4 + String(accum.length).length;
41
+ new heading_1.HeadingToken(rmt[1].length, rmt.slice(2), config, accum);
42
+ }
43
+ }
44
+ }
45
+ else if (syntax === '|' || innerEqual) { // 情形3:模板内部,含行首单个'='
46
+ lastIndex = curIndex + 1;
47
+ parts.at(-1).push(wikitext.slice(topPos, curIndex));
48
+ if (syntax === '|') {
49
+ parts.push([]);
50
+ }
51
+ top.pos = lastIndex;
52
+ top.findEqual = syntax === '|';
53
+ stack.push(top);
54
+ }
55
+ else if (syntax.startsWith('}}')) { // 情形4:闭合模板
56
+ const close = syntax.slice(0, Math.min(open.length, 3)), rest = open.length - close.length, { length } = accum;
57
+ lastIndex = curIndex + close.length; // 这不是最终的lastIndex
58
+ parts.at(-1).push(wikitext.slice(topPos, curIndex));
59
+ let skip = false, ch = 't';
60
+ if (close.length === 3) {
61
+ const argParts = parts.map(part => part.join('=')), str = argParts.length > 1 && (0, string_1.removeComment)(argParts[1]).trim();
62
+ new arg_1.ArgToken(argParts, config, accum);
63
+ if (str && str.endsWith(':') && subst.includes(str.slice(0, -1).toLowerCase())) {
64
+ ch = 's';
65
+ }
66
+ }
67
+ else {
68
+ try {
69
+ new transclude_1.TranscludeToken(parts[0][0], parts.slice(1), config, accum);
70
+ const name = (0, string_1.removeComment)(parts[0][0]).trim();
71
+ if (marks.has(name)) {
72
+ ch = marks.get(name); // 标记{{!}}等
73
+ }
74
+ else if (/^(?:filepath|(?:full|canonical)urle?):.|^server$/iu.test(name)) {
75
+ ch = 'm';
76
+ }
77
+ else if (/^#vardefine:./iu.test(name)) {
78
+ ch = 'c';
79
+ }
80
+ }
81
+ catch (e) {
82
+ if (e instanceof SyntaxError && e.message.startsWith('非法的模板名称:')) {
83
+ lastIndex = index + open.length;
84
+ skip = true;
85
+ }
86
+ else {
87
+ throw e;
88
+ }
89
+ }
90
+ }
91
+ if (!skip) {
92
+ wikitext = `${wikitext.slice(0, index + rest)}\0${length}${ch}\x7F${wikitext.slice(lastIndex)}`;
93
+ lastIndex = index + rest + 3 + String(length).length;
94
+ if (rest > 1) {
95
+ stack.push({ 0: open.slice(0, rest), index: index, pos: index + rest, parts: [[]] });
96
+ }
97
+ else if (rest === 1 && wikitext[index - 1] === '-') {
98
+ stack.push({ 0: '-{', index: index - 1, pos: index + 1, parts: [[]] });
99
+ }
100
+ }
101
+ }
102
+ else { // 情形5:开启
103
+ lastIndex = curIndex + syntax.length;
104
+ if (syntax.startsWith('{')) {
105
+ mt.pos = lastIndex;
106
+ mt.parts = [[]];
107
+ }
108
+ stack.push(...'0' in top ? [top] : [], mt);
109
+ }
110
+ moreBraces &&= wikitext.slice(lastIndex).includes('}}');
111
+ let curTop = stack.at(-1);
112
+ if (!moreBraces && curTop?.[0]?.startsWith('{')) {
113
+ stack.pop();
114
+ curTop = stack.at(-1);
115
+ }
116
+ regex = new RegExp(source + (curTop ? `|${closes[curTop[0][0]]}${curTop.findEqual ? '|=' : ''}` : ''), 'gmu');
117
+ regex.lastIndex = lastIndex;
118
+ mt = regex.exec(wikitext);
119
+ }
120
+ return wikitext;
121
+ };
122
+ exports.parseBraces = parseBraces;
123
+ constants_1.parsers['parseBraces'] = __filename;
@@ -0,0 +1,69 @@
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
+ if (includeOnly) {
21
+ let i = wikitext.indexOf(onlyincludeLeft), j = wikitext.indexOf(onlyincludeRight, i + length);
22
+ if (i !== -1 && j !== -1) { // `<onlyinclude>`拥有最高优先级
23
+ let str = '';
24
+ while (i !== -1 && j !== -1) {
25
+ const token = `\0${accum.length}e\x7F`;
26
+ new onlyinclude_1.OnlyincludeToken(wikitext.slice(i + length, j), config, accum);
27
+ if (i > 0) {
28
+ new noinclude_1.NoincludeToken(wikitext.slice(0, i), config, accum);
29
+ str += `\0${accum.length - 1}c\x7F${token}`;
30
+ }
31
+ else {
32
+ str += token;
33
+ }
34
+ wikitext = wikitext.slice(j + length + 1);
35
+ i = wikitext.indexOf(onlyincludeLeft);
36
+ j = wikitext.indexOf(onlyincludeRight, i + length);
37
+ }
38
+ if (wikitext) {
39
+ new noinclude_1.NoincludeToken(wikitext, config, accum);
40
+ str += `\0${accum.length - 1}c\x7F`;
41
+ }
42
+ return str;
43
+ }
44
+ }
45
+ const ext = config.ext.join('|'), includeRegex = includeOnly ? 'includeonly' : '(?:no|only)include', noincludeRegex = includeOnly ? 'noinclude' : 'includeonly', regex = new RegExp('<!--.*?(?:-->|$)|' // comment
46
+ + `<${includeRegex}(?:\\s[^>]*?)?>|</${includeRegex}\\s*>|` // <includeonly>
47
+ + `<(${ext})(\\s[^>]*?)?(?:/>|>(.*?)</(\\1\\s*)>)|` // 扩展标签
48
+ + `<(${noincludeRegex})(\\s[^>]*?)?(?:/>|>(.*?)(?:</(\\5\\s*)>|$))`, // <noinclude>
49
+ 'gisu');
50
+ return wikitext.replace(regex, (substr, name, attr, inner, closing, include, includeAttr, includeInner, includeClosing) => {
51
+ const str = `\0${accum.length}${name ? 'e' : 'c'}\x7F`;
52
+ if (name) {
53
+ new ext_1.ExtToken(name, attr, inner, closing, config, accum);
54
+ }
55
+ else if (substr.startsWith('<!--')) {
56
+ const closed = substr.endsWith('-->');
57
+ new comment_1.CommentToken(substr.slice(4, closed ? -3 : undefined), closed, config, accum);
58
+ }
59
+ else if (include) {
60
+ new include_1.IncludeToken(include, includeAttr, includeInner, includeClosing, config, accum);
61
+ }
62
+ else {
63
+ new noinclude_1.NoincludeToken(substr, config, accum);
64
+ }
65
+ return str;
66
+ });
67
+ };
68
+ exports.parseCommentAndExt = parseCommentAndExt;
69
+ constants_1.parsers['parseCommentAndExt'] = __filename;
@@ -0,0 +1,40 @@
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
+ 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)],
20
+ // eslint-disable-next-line regexp/prefer-lookaround
21
+ temp = raw.replace(/(&[#a-z\d]+);/giu, '$1\x01'), variants = `(?:${config.variants.join('|')})`, rules = temp.split(new RegExp(`;(?=\\s*(?:${variants}|[^;]*?=>\\s*${variants})\\s*:)`, 'u'))
22
+ .map(rule => rule.replaceAll('\x01', ';'));
23
+ new converter_1.ConverterToken(flags, rules, config, accum);
24
+ text = `${text.slice(0, top.index)}\0${length}v\x7F${text.slice(index + 2)}`;
25
+ if (stack.length === 0) {
26
+ regex = regex1;
27
+ }
28
+ regex.lastIndex = top.index + 3 + String(length).length;
29
+ }
30
+ else {
31
+ stack.push(mt);
32
+ regex = regex2;
33
+ regex.lastIndex = index + 2;
34
+ }
35
+ mt = regex.exec(text);
36
+ }
37
+ return text;
38
+ };
39
+ exports.parseConverter = parseConverter;
40
+ constants_1.parsers['parseConverter'] = __filename;
@@ -0,0 +1,28 @@
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
+ const regex = new RegExp(`\\[((?:(?:${config.protocol}|//)${string_1.extUrlCharFirst}|\0\\d+m\x7F)${string_1.extUrlChar})(\\p{Zs}*)([^\\]\x01-\x08\x0A-\x1F\uFFFD]*)\\]`, 'giu');
16
+ return wikitext.replace(regex, (_, url, space, text) => {
17
+ const { length } = accum, mt = /&[lg]t;/u.exec(url);
18
+ if (mt) {
19
+ url = url.slice(0, mt.index);
20
+ space = '';
21
+ text = `${url.slice(mt.index)}${space}${text}`;
22
+ }
23
+ new extLink_1.ExtLinkToken(url, space, text, config, accum);
24
+ return `\0${length}w\x7F`;
25
+ });
26
+ };
27
+ exports.parseExternalLinks = parseExternalLinks;
28
+ constants_1.parsers['parseExternalLinks'] = __filename;
@@ -0,0 +1,38 @@
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
+ new hr_1.HrToken(m, config, accum);
22
+ return `${lead}\0${accum.length - 1}r\x7F`;
23
+ }).replace(new RegExp(`__(${doubleUnderscore.flat().join('|')})__`, 'giu'), (m, p1) => {
24
+ const fixed = sensitive.has(p1);
25
+ if (fixed || insensitive.has(p1.toLowerCase())) {
26
+ new doubleUnderscore_1.DoubleUnderscoreToken(p1, fixed, config, accum);
27
+ return `\0${accum.length - 1}u\x7F`;
28
+ }
29
+ return m;
30
+ }).replace(/^((?:\0\d+c\x7F)*)(={1,6})(.+)\2((?:[^\S\n]|\0\d+c\x7F)*)$/gmu, (_, lead, equals, heading, trail) => {
31
+ const text = `${lead}\0${accum.length}h\x7F`;
32
+ new heading_1.HeadingToken(equals.length, [heading, trail], config, accum);
33
+ return text;
34
+ });
35
+ return type === 'root' || type === 'ext-inner' && name === 'poem' ? data : data.slice(1);
36
+ };
37
+ exports.parseHrAndDoubleUnderscore = parseHrAndDoubleUnderscore;
38
+ constants_1.parsers['parseHrAndDoubleUnderscore'] = __filename;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseHtml = void 0;
4
+ const constants_1 = require("../util/constants");
5
+ const Parser = require("../index");
6
+ const attributes_1 = require("../src/attributes");
7
+ const html_1 = require("../src/html");
8
+ /**
9
+ * 解析HTML标签
10
+ * @param wikitext
11
+ * @param config
12
+ * @param accum
13
+ */
14
+ const parseHtml = (wikitext, config = Parser.getConfig(), accum = []) => {
15
+ const regex = /^(\/?)([a-z][^\s/>]*)((?:\s|\/(?!>))[^>]*?)?(\/?>)([^<]*)$/iu, elements = new Set(config.html.flat()), bits = wikitext.split('<');
16
+ let text = bits.shift();
17
+ for (const x of bits) {
18
+ const mt = regex.exec(x), t = mt?.[2], name = t?.toLowerCase();
19
+ if (!mt || !elements.has(name)) {
20
+ text += `<${x}`;
21
+ continue;
22
+ }
23
+ const [, slash, , params = '', brace, rest] = mt, attr = new attributes_1.AttributesToken(params, 'html-attrs', name, config, accum), itemprop = attr.getAttr('itemprop');
24
+ if (name === 'meta' && (itemprop === undefined || attr.getAttr('content') === undefined)
25
+ || name === 'link' && (itemprop === undefined || attr.getAttr('href') === undefined)) {
26
+ text += `<${x}`;
27
+ accum.pop();
28
+ continue;
29
+ }
30
+ text += `\0${accum.length}x\x7F${rest}`;
31
+ new html_1.HtmlToken(t, attr, slash === '/', brace === '/>', config, accum);
32
+ }
33
+ return text;
34
+ };
35
+ exports.parseHtml = parseHtml;
36
+ constants_1.parsers['parseHtml'] = __filename;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseLinks = void 0;
4
+ const constants_1 = require("../util/constants");
5
+ const Parser = require("../index");
6
+ const index_1 = require("../src/link/index");
7
+ const file_1 = require("../src/link/file");
8
+ const category_1 = require("../src/link/category");
9
+ /**
10
+ * 解析内部链接
11
+ * @param wikitext
12
+ * @param config
13
+ * @param accum
14
+ */
15
+ const parseLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
16
+ const { parseQuotes } = require('./quotes');
17
+ const regex = /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(?:(\||\0\d+!\x7F)(.*?[^\]]))?\]\](.*)$/su, regexImg = /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(\||\0\d+!\x7F)(.*)$/su, regexExt = new RegExp(`^\\s*(?:${config.protocol})`, 'iu'), bits = wikitext.split('[[');
18
+ let s = bits.shift();
19
+ for (let i = 0; i < bits.length; i++) {
20
+ let mightBeImg = false, link, delimiter, text, after;
21
+ const x = bits[i], m = regex.exec(x);
22
+ if (m) {
23
+ [, link, delimiter, text, after] = m;
24
+ if (after.startsWith(']') && text?.includes('[')) {
25
+ text += ']';
26
+ after = after.slice(1);
27
+ }
28
+ }
29
+ else {
30
+ const m2 = regexImg.exec(x);
31
+ if (m2) {
32
+ mightBeImg = true;
33
+ [, link, delimiter, text] = m2;
34
+ }
35
+ }
36
+ if (link === undefined || regexExt.test(link) || /\0\d+[exhbru]\x7F/u.test(link)) {
37
+ s += `[[${x}`;
38
+ continue;
39
+ }
40
+ const force = link.trim().startsWith(':');
41
+ if (force && mightBeImg) {
42
+ s += `[[${x}`;
43
+ continue;
44
+ }
45
+ const title = Parser.normalizeTitle(link, 0, false, config, true, true, true), { ns, interwiki, valid, } = title;
46
+ if (!valid) {
47
+ s += `[[${x}`;
48
+ continue;
49
+ }
50
+ else if (mightBeImg) {
51
+ if (interwiki || ns !== 6) {
52
+ s += `[[${x}`;
53
+ continue;
54
+ }
55
+ let found = false;
56
+ for (i++; i < bits.length; i++) {
57
+ const next = bits[i], p = next.split(']]');
58
+ if (p.length > 2) {
59
+ found = true;
60
+ text += `[[${p[0]}]]${p[1]}`;
61
+ after = p.slice(2).join(']]');
62
+ break;
63
+ }
64
+ else if (p.length === 2) {
65
+ text += `[[${p[0]}]]${p[1]}`;
66
+ }
67
+ else {
68
+ text += `[[${next}`;
69
+ break;
70
+ }
71
+ }
72
+ text = (0, exports.parseLinks)(text, config, accum);
73
+ if (!found) {
74
+ s += `[[${link}${delimiter}${text}`;
75
+ continue;
76
+ }
77
+ }
78
+ text &&= parseQuotes(text, config, accum);
79
+ s += `\0${accum.length}l\x7F${after}`;
80
+ let SomeLinkToken = index_1.LinkToken;
81
+ if (!force) {
82
+ if (!interwiki && ns === 6) {
83
+ SomeLinkToken = file_1.FileToken;
84
+ }
85
+ else if (!interwiki && ns === 14) {
86
+ SomeLinkToken = category_1.CategoryToken;
87
+ }
88
+ }
89
+ new SomeLinkToken(link, text, config, accum, delimiter);
90
+ }
91
+ return s;
92
+ };
93
+ exports.parseLinks = parseLinks;
94
+ constants_1.parsers['parseLinks'] = __filename;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseList = void 0;
4
+ const constants_1 = require("../util/constants");
5
+ const Parser = require("../index");
6
+ const list_1 = require("../src/nowiki/list");
7
+ const dd_1 = require("../src/nowiki/dd");
8
+ /**
9
+ * 解析列表
10
+ * @param wikitext
11
+ * @param config
12
+ * @param accum
13
+ */
14
+ const parseList = (wikitext, config = Parser.getConfig(), accum = []) => {
15
+ const mt = /^((?:\0\d+c\x7F)*)([;:*#]+)/u.exec(wikitext);
16
+ if (!mt) {
17
+ return wikitext;
18
+ }
19
+ const [total, comment, prefix] = mt;
20
+ let text = `${comment}\0${accum.length}d\x7F${wikitext.slice(total.length)}`, dt = prefix.split(';').length - 1;
21
+ new list_1.ListToken(prefix, config, accum);
22
+ if (!dt) {
23
+ return text;
24
+ }
25
+ let regex = /:+|-\{/gu, ex = regex.exec(text), lc = 0;
26
+ while (ex && dt) {
27
+ const { 0: syntax, index } = ex;
28
+ if (syntax.startsWith(':')) {
29
+ if (syntax.length >= dt) {
30
+ new dd_1.DdToken(':'.repeat(dt), config, accum);
31
+ return `${text.slice(0, index)}\0${accum.length - 1}d\x7F${text.slice(index + dt)}`;
32
+ }
33
+ text = `${text.slice(0, index)}\0${accum.length}d\x7F${text.slice(regex.lastIndex)}`;
34
+ dt -= syntax.length;
35
+ regex.lastIndex = index + 4 + String(accum.length).length;
36
+ new dd_1.DdToken(syntax, config, accum);
37
+ }
38
+ else if (syntax === '-{') {
39
+ if (!lc) {
40
+ const { lastIndex } = regex;
41
+ regex = /-\{|\}-/gu;
42
+ regex.lastIndex = lastIndex;
43
+ }
44
+ lc++;
45
+ }
46
+ else {
47
+ lc--;
48
+ if (!lc) {
49
+ const { lastIndex } = regex;
50
+ regex = /:+|-\{/gu;
51
+ regex.lastIndex = lastIndex;
52
+ }
53
+ }
54
+ ex = regex.exec(text);
55
+ }
56
+ return text;
57
+ };
58
+ exports.parseList = parseList;
59
+ constants_1.parsers['parseList'] = __filename;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseMagicLinks = void 0;
4
+ const string_1 = require("../util/string");
5
+ const constants_1 = require("../util/constants");
6
+ const Parser = require("../index");
7
+ const magicLink_1 = require("../src/magicLink");
8
+ /**
9
+ * 解析自由外链
10
+ * @param wikitext
11
+ * @param config
12
+ * @param accum
13
+ */
14
+ const parseMagicLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
15
+ const regex = new RegExp(`(?<![\\p{L}\\d_])(?:${config.protocol})(${string_1.extUrlCharFirst}${string_1.extUrlChar})`, 'giu');
16
+ return wikitext.replace(regex, (m, p1) => {
17
+ let trail = '', url = m;
18
+ const m2 = /&(?:lt|gt|nbsp|#x0*(?:3[ce]|a0)|#0*(?:6[02]|160));/iu.exec(url);
19
+ if (m2) {
20
+ trail = url.slice(m2.index);
21
+ url = url.slice(0, m2.index);
22
+ }
23
+ const sep = new RegExp(`[,;.:!?${url.includes('(') ? '' : ')'}]+$`, 'u'), sepChars = sep.exec(url);
24
+ if (sepChars) {
25
+ let correction = 0;
26
+ if (sepChars[0].startsWith(';') && /&(?:[a-z]+|#x[\da-f]+|#\d+)$/iu.test(url.slice(0, sepChars.index))) {
27
+ correction = 1;
28
+ }
29
+ trail = `${url.slice(sepChars.index + correction)}${trail}`;
30
+ url = url.slice(0, sepChars.index + correction);
31
+ }
32
+ if (trail.length >= p1.length) {
33
+ return m;
34
+ }
35
+ new magicLink_1.MagicLinkToken(url, false, config, accum);
36
+ return `\0${accum.length - 1}w\x7F${trail}`;
37
+ });
38
+ };
39
+ exports.parseMagicLinks = parseMagicLinks;
40
+ constants_1.parsers['parseMagicLinks'] = __filename;