wikiparser-node 1.3.6 → 1.3.7-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 (154) hide show
  1. package/bundle/bundle.min.js +36 -0
  2. package/config/llwiki.json +1 -35
  3. package/config/moegirl.json +1 -44
  4. package/config/zhwiki.json +1 -466
  5. package/extensions/dist/base.js +68 -0
  6. package/extensions/dist/editor.js +159 -0
  7. package/extensions/dist/highlight.js +30 -0
  8. package/extensions/dist/lint.js +48 -0
  9. package/extensions/editor.css +63 -0
  10. package/extensions/ui.css +114 -0
  11. package/package.json +32 -12
  12. package/config/.schema.json +0 -172
  13. package/dist/addon/table.d.ts +0 -6
  14. package/dist/addon/table.js +0 -558
  15. package/dist/base.d.ts +0 -45
  16. package/dist/bin/toc.js +0 -18
  17. package/dist/index.d.ts +0 -32
  18. package/dist/index.js +0 -209
  19. package/dist/internal.d.ts +0 -44
  20. package/dist/lib/element.d.ts +0 -154
  21. package/dist/lib/element.js +0 -625
  22. package/dist/lib/node.d.ts +0 -146
  23. package/dist/lib/node.js +0 -423
  24. package/dist/lib/range.d.ts +0 -104
  25. package/dist/lib/range.js +0 -385
  26. package/dist/lib/ranges.d.ts +0 -26
  27. package/dist/lib/ranges.js +0 -118
  28. package/dist/lib/text.d.ts +0 -62
  29. package/dist/lib/text.js +0 -247
  30. package/dist/lib/title.d.ts +0 -38
  31. package/dist/lib/title.js +0 -162
  32. package/dist/mixin/attributesParent.js +0 -89
  33. package/dist/mixin/fixed.js +0 -25
  34. package/dist/mixin/flagsParent.js +0 -70
  35. package/dist/mixin/hidden.js +0 -26
  36. package/dist/mixin/magicLinkParent.js +0 -41
  37. package/dist/mixin/singleLine.js +0 -25
  38. package/dist/mixin/sol.js +0 -43
  39. package/dist/mixin/syntax.js +0 -54
  40. package/dist/parser/braces.js +0 -128
  41. package/dist/parser/commentAndExt.js +0 -77
  42. package/dist/parser/converter.js +0 -40
  43. package/dist/parser/externalLinks.js +0 -28
  44. package/dist/parser/hrAndDoubleUnderscore.js +0 -38
  45. package/dist/parser/html.js +0 -36
  46. package/dist/parser/links.js +0 -94
  47. package/dist/parser/list.js +0 -66
  48. package/dist/parser/magicLinks.js +0 -40
  49. package/dist/parser/quotes.js +0 -67
  50. package/dist/parser/selector.js +0 -161
  51. package/dist/parser/table.js +0 -120
  52. package/dist/src/arg.d.ts +0 -56
  53. package/dist/src/arg.js +0 -187
  54. package/dist/src/atom.d.ts +0 -12
  55. package/dist/src/atom.js +0 -27
  56. package/dist/src/attribute.d.ts +0 -88
  57. package/dist/src/attribute.js +0 -392
  58. package/dist/src/attributes.d.ts +0 -109
  59. package/dist/src/attributes.js +0 -344
  60. package/dist/src/converter.d.ts +0 -53
  61. package/dist/src/converter.js +0 -79
  62. package/dist/src/converterFlags.d.ts +0 -87
  63. package/dist/src/converterFlags.js +0 -224
  64. package/dist/src/converterRule.d.ts +0 -77
  65. package/dist/src/converterRule.js +0 -208
  66. package/dist/src/extLink.d.ts +0 -55
  67. package/dist/src/extLink.js +0 -122
  68. package/dist/src/gallery.d.ts +0 -54
  69. package/dist/src/gallery.js +0 -121
  70. package/dist/src/heading.d.ts +0 -76
  71. package/dist/src/heading.js +0 -127
  72. package/dist/src/hidden.d.ts +0 -23
  73. package/dist/src/hidden.js +0 -23
  74. package/dist/src/html.d.ts +0 -104
  75. package/dist/src/html.js +0 -226
  76. package/dist/src/imageParameter.d.ts +0 -65
  77. package/dist/src/imageParameter.js +0 -245
  78. package/dist/src/imagemap.d.ts +0 -56
  79. package/dist/src/imagemap.js +0 -147
  80. package/dist/src/imagemapLink.d.ts +0 -61
  81. package/dist/src/imagemapLink.js +0 -40
  82. package/dist/src/index.d.ts +0 -139
  83. package/dist/src/index.js +0 -777
  84. package/dist/src/link/base.d.ts +0 -52
  85. package/dist/src/link/base.js +0 -209
  86. package/dist/src/link/category.d.ts +0 -13
  87. package/dist/src/link/category.js +0 -29
  88. package/dist/src/link/file.d.ts +0 -96
  89. package/dist/src/link/file.js +0 -256
  90. package/dist/src/link/galleryImage.d.ts +0 -45
  91. package/dist/src/link/galleryImage.js +0 -106
  92. package/dist/src/link/index.d.ts +0 -53
  93. package/dist/src/link/index.js +0 -123
  94. package/dist/src/magicLink.d.ts +0 -69
  95. package/dist/src/magicLink.js +0 -146
  96. package/dist/src/nested.d.ts +0 -43
  97. package/dist/src/nested.js +0 -86
  98. package/dist/src/nowiki/base.d.ts +0 -48
  99. package/dist/src/nowiki/base.js +0 -42
  100. package/dist/src/nowiki/comment.d.ts +0 -41
  101. package/dist/src/nowiki/comment.js +0 -67
  102. package/dist/src/nowiki/dd.d.ts +0 -8
  103. package/dist/src/nowiki/dd.js +0 -25
  104. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -47
  105. package/dist/src/nowiki/doubleUnderscore.js +0 -50
  106. package/dist/src/nowiki/hr.d.ts +0 -33
  107. package/dist/src/nowiki/hr.js +0 -14
  108. package/dist/src/nowiki/index.d.ts +0 -16
  109. package/dist/src/nowiki/index.js +0 -21
  110. package/dist/src/nowiki/list.d.ts +0 -31
  111. package/dist/src/nowiki/list.js +0 -48
  112. package/dist/src/nowiki/listBase.d.ts +0 -20
  113. package/dist/src/nowiki/listBase.js +0 -12
  114. package/dist/src/nowiki/noinclude.d.ts +0 -26
  115. package/dist/src/nowiki/noinclude.js +0 -24
  116. package/dist/src/nowiki/quote.d.ts +0 -24
  117. package/dist/src/nowiki/quote.js +0 -45
  118. package/dist/src/onlyinclude.d.ts +0 -16
  119. package/dist/src/onlyinclude.js +0 -57
  120. package/dist/src/paramTag/index.d.ts +0 -37
  121. package/dist/src/paramTag/index.js +0 -68
  122. package/dist/src/paramTag/inputbox.d.ts +0 -8
  123. package/dist/src/paramTag/inputbox.js +0 -23
  124. package/dist/src/parameter.d.ts +0 -86
  125. package/dist/src/parameter.js +0 -205
  126. package/dist/src/pre.d.ts +0 -28
  127. package/dist/src/pre.js +0 -51
  128. package/dist/src/syntax.d.ts +0 -30
  129. package/dist/src/syntax.js +0 -34
  130. package/dist/src/table/base.d.ts +0 -55
  131. package/dist/src/table/base.js +0 -78
  132. package/dist/src/table/index.d.ts +0 -228
  133. package/dist/src/table/index.js +0 -378
  134. package/dist/src/table/td.d.ts +0 -107
  135. package/dist/src/table/td.js +0 -260
  136. package/dist/src/table/tr.d.ts +0 -32
  137. package/dist/src/table/tr.js +0 -56
  138. package/dist/src/table/trBase.d.ts +0 -53
  139. package/dist/src/table/trBase.js +0 -151
  140. package/dist/src/tagPair/ext.d.ts +0 -58
  141. package/dist/src/tagPair/ext.js +0 -142
  142. package/dist/src/tagPair/include.d.ts +0 -54
  143. package/dist/src/tagPair/include.js +0 -63
  144. package/dist/src/tagPair/index.d.ts +0 -49
  145. package/dist/src/tagPair/index.js +0 -93
  146. package/dist/src/transclude.d.ts +0 -167
  147. package/dist/src/transclude.js +0 -696
  148. package/dist/util/constants.js +0 -108
  149. package/dist/util/debug.js +0 -83
  150. package/dist/util/diff.js +0 -72
  151. package/dist/util/lint.js +0 -30
  152. package/dist/util/string.js +0 -51
  153. package/errors/README +0 -1
  154. package/printed/README +0 -1
@@ -1,25 +0,0 @@
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;
package/dist/mixin/sol.js DELETED
@@ -1,43 +0,0 @@
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;
@@ -1,54 +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 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;
@@ -1,128 +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 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.at(-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.at(-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.at(-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
- new heading_1.HeadingToken(rmt[1].length, rmt.slice(2), config, accum);
48
- }
49
- }
50
- }
51
- else if (syntax === '|' || innerEqual) { // 情形3:模板内部,含行首单个'='
52
- lastIndex = curIndex + 1;
53
- push(wikitext);
54
- if (syntax === '|') {
55
- parts.push([]);
56
- }
57
- top.pos = lastIndex;
58
- top.findEqual = syntax === '|';
59
- stack.push(top);
60
- }
61
- else if (syntax.startsWith('}}')) { // 情形4:闭合模板
62
- const close = syntax.slice(0, Math.min(open.length, 3)), rest = open.length - close.length, { length } = accum;
63
- lastIndex = curIndex + close.length; // 这不是最终的lastIndex
64
- push(wikitext);
65
- let skip = false, ch = 't';
66
- if (close.length === 3) {
67
- const argParts = parts.map(part => part.join('=')), str = argParts.length > 1 && (0, string_1.removeComment)(argParts[1]).trim();
68
- new arg_1.ArgToken(argParts, config, accum);
69
- if (str && str.endsWith(':') && subst.includes(str.slice(0, -1).toLowerCase())) {
70
- ch = 's';
71
- }
72
- }
73
- else {
74
- try {
75
- new transclude_1.TranscludeToken(parts[0][0], parts.slice(1), config, accum);
76
- const name = (0, string_1.removeComment)(parts[0][0]).trim();
77
- if (marks.has(name)) {
78
- ch = marks.get(name); // 标记{{!}}等
79
- }
80
- else if (/^(?:filepath|(?:full|canonical)urle?):.|^server$/iu.test(name)) {
81
- ch = 'm';
82
- }
83
- else if (/^#vardefine:./iu.test(name)) {
84
- ch = 'c';
85
- }
86
- }
87
- catch (e) {
88
- if (e instanceof SyntaxError && e.message.startsWith('非法的模板名称:')) {
89
- skip = true;
90
- }
91
- else {
92
- throw e;
93
- }
94
- }
95
- }
96
- if (!skip) {
97
- wikitext = `${wikitext.slice(0, index + rest)}\0${length}${ch}\x7F${wikitext.slice(lastIndex)}`;
98
- lastIndex = index + rest + 3 + String(length).length;
99
- if (rest > 1) {
100
- stack.push({ 0: open.slice(0, rest), index: index, pos: index + rest, parts: [[]] });
101
- }
102
- else if (rest === 1 && wikitext[index - 1] === '-') {
103
- stack.push({ 0: '-{', index: index - 1, pos: index + 1, parts: [[]] });
104
- }
105
- }
106
- }
107
- else { // 情形5:开启
108
- lastIndex = curIndex + syntax.length;
109
- if (syntax.startsWith('{')) {
110
- mt.pos = lastIndex;
111
- mt.parts = [[]];
112
- }
113
- stack.push(...'0' in top ? [top] : [], mt);
114
- }
115
- moreBraces &&= wikitext.slice(lastIndex).includes('}}');
116
- let curTop = stack.at(-1);
117
- if (!moreBraces && curTop?.[0]?.startsWith('{')) {
118
- stack.pop();
119
- curTop = stack.at(-1);
120
- }
121
- regex = new RegExp(source + (curTop ? `|${closes[curTop[0][0]]}${curTop.findEqual ? '|=' : ''}` : ''), 'gmu');
122
- regex.lastIndex = lastIndex;
123
- mt = regex.exec(wikitext);
124
- }
125
- return wikitext;
126
- };
127
- exports.parseBraces = parseBraces;
128
- constants_1.parsers['parseBraces'] = __filename;
@@ -1,77 +0,0 @@
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
- new noinclude_1.NoincludeToken(text, config, accum);
35
- str += `\0${accum.length - 1}c\x7F`;
36
- };
37
- while (i !== -1 && j !== -1) {
38
- const token = `\0${accum.length}e\x7F`;
39
- new onlyinclude_1.OnlyincludeToken(wikitext.slice(i + length, j), config, accum);
40
- if (i > 0) {
41
- noinclude(wikitext.slice(0, i));
42
- }
43
- str += token;
44
- wikitext = wikitext.slice(j + length + 1);
45
- ({ i, j } = update());
46
- }
47
- if (wikitext) {
48
- noinclude(wikitext);
49
- }
50
- return str;
51
- }
52
- }
53
- const ext = config.ext.join('|'), noincludeRegex = includeOnly ? 'includeonly' : '(?:no|only)include', includeRegex = includeOnly ? 'noinclude' : 'includeonly', regex = new RegExp('<!--.*?(?:-->|$)|' // comment
54
- + `<${noincludeRegex}(?:\\s[^>]*?)?>|</${noincludeRegex}\\s*>|` // <noinclude>
55
- + `<(${ext})(\\s[^>]*?)?(?:/>|>(.*?)</(\\1\\s*)>)|` // 扩展标签
56
- + `<(${includeRegex})(\\s[^>]*?)?(?:/>|>(.*?)(?:</(${includeRegex}\\s*)>|$))`, // <includeonly>
57
- 'gisu');
58
- return wikitext.replace(regex, (substr, name, attr, inner, closing, include, includeAttr, includeInner, includeClosing) => {
59
- const str = `\0${accum.length}${name ? 'e' : 'c'}\x7F`;
60
- if (name) {
61
- new ext_1.ExtToken(name, attr, inner, closing, config, accum);
62
- }
63
- else if (substr.startsWith('<!--')) {
64
- const closed = substr.endsWith('-->');
65
- new comment_1.CommentToken(substr.slice(4, closed ? -3 : undefined), closed, config, accum);
66
- }
67
- else if (include) {
68
- new include_1.IncludeToken(include, includeAttr, includeInner, includeClosing, config, accum);
69
- }
70
- else {
71
- new noinclude_1.NoincludeToken(substr, config, accum);
72
- }
73
- return str;
74
- });
75
- };
76
- exports.parseCommentAndExt = parseCommentAndExt;
77
- constants_1.parsers['parseCommentAndExt'] = __filename;
@@ -1,40 +0,0 @@
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;
@@ -1,28 +0,0 @@
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;
@@ -1,38 +0,0 @@
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;
@@ -1,36 +0,0 @@
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;
@@ -1,94 +0,0 @@
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;
@@ -1,66 +0,0 @@
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
- /**
27
- * 创建`DdToken`
28
- * @param syntax `:`
29
- * @param index 起点
30
- */
31
- const dd = (syntax, index) => {
32
- new dd_1.DdToken(syntax, config, accum);
33
- return `${text.slice(0, index)}\0${accum.length - 1}d\x7F${text.slice(index + syntax.length)}`;
34
- };
35
- while (ex && dt) {
36
- const { 0: syntax, index } = ex;
37
- if (syntax.startsWith(':')) {
38
- if (syntax.length >= dt) {
39
- return dd(syntax.slice(0, dt), index);
40
- }
41
- dt -= syntax.length;
42
- regex.lastIndex = index + 4 + String(accum.length).length;
43
- text = dd(syntax, index);
44
- }
45
- else if (syntax === '-{') {
46
- if (!lc) {
47
- const { lastIndex } = regex;
48
- regex = /-\{|\}-/gu;
49
- regex.lastIndex = lastIndex;
50
- }
51
- lc++;
52
- }
53
- else {
54
- lc--;
55
- if (!lc) {
56
- const { lastIndex } = regex;
57
- regex = /:+|-\{/gu;
58
- regex.lastIndex = lastIndex;
59
- }
60
- }
61
- ex = regex.exec(text);
62
- }
63
- return text;
64
- };
65
- exports.parseList = parseList;
66
- constants_1.parsers['parseList'] = __filename;