wikiparser-node 1.10.0 → 1.11.0-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 (173) hide show
  1. package/bundle/bundle.min.js +38 -0
  2. package/config/enwiki.json +1 -814
  3. package/config/llwiki.json +1 -35
  4. package/config/moegirl.json +1 -44
  5. package/config/zhwiki.json +1 -466
  6. package/extensions/dist/base.js +64 -0
  7. package/extensions/dist/editor.js +159 -0
  8. package/extensions/dist/highlight.js +56 -0
  9. package/extensions/dist/lint.js +72 -0
  10. package/extensions/editor.css +64 -0
  11. package/extensions/ui.css +144 -0
  12. package/i18n/zh-hans.json +1 -1
  13. package/i18n/zh-hant.json +1 -1
  14. package/package.json +43 -33
  15. package/config/.schema.json +0 -186
  16. package/dist/addon/table.js +0 -486
  17. package/dist/addon/token.js +0 -324
  18. package/dist/addon/transclude.js +0 -185
  19. package/dist/base.d.ts +0 -81
  20. package/dist/base.js +0 -39
  21. package/dist/index.d.ts +0 -33
  22. package/dist/index.js +0 -231
  23. package/dist/internal.d.ts +0 -46
  24. package/dist/lib/element.d.ts +0 -125
  25. package/dist/lib/element.js +0 -374
  26. package/dist/lib/node.d.ts +0 -173
  27. package/dist/lib/node.js +0 -478
  28. package/dist/lib/range.d.ts +0 -105
  29. package/dist/lib/range.js +0 -406
  30. package/dist/lib/ranges.d.ts +0 -28
  31. package/dist/lib/ranges.js +0 -126
  32. package/dist/lib/rect.d.ts +0 -18
  33. package/dist/lib/rect.js +0 -34
  34. package/dist/lib/text.d.ts +0 -58
  35. package/dist/lib/text.js +0 -361
  36. package/dist/lib/title.d.ts +0 -42
  37. package/dist/lib/title.js +0 -205
  38. package/dist/mixin/attributesParent.d.ts +0 -49
  39. package/dist/mixin/attributesParent.js +0 -79
  40. package/dist/mixin/fixed.d.ts +0 -5
  41. package/dist/mixin/fixed.js +0 -32
  42. package/dist/mixin/flagsParent.d.ts +0 -41
  43. package/dist/mixin/flagsParent.js +0 -60
  44. package/dist/mixin/hidden.d.ts +0 -7
  45. package/dist/mixin/hidden.js +0 -37
  46. package/dist/mixin/magicLinkParent.d.ts +0 -19
  47. package/dist/mixin/magicLinkParent.js +0 -43
  48. package/dist/mixin/singleLine.d.ts +0 -5
  49. package/dist/mixin/singleLine.js +0 -25
  50. package/dist/mixin/sol.d.ts +0 -6
  51. package/dist/mixin/sol.js +0 -44
  52. package/dist/mixin/syntax.d.ts +0 -8
  53. package/dist/mixin/syntax.js +0 -46
  54. package/dist/parser/braces.js +0 -150
  55. package/dist/parser/commentAndExt.js +0 -79
  56. package/dist/parser/converter.js +0 -39
  57. package/dist/parser/externalLinks.js +0 -37
  58. package/dist/parser/hrAndDoubleUnderscore.js +0 -42
  59. package/dist/parser/html.js +0 -38
  60. package/dist/parser/links.js +0 -101
  61. package/dist/parser/list.js +0 -99
  62. package/dist/parser/magicLinks.js +0 -53
  63. package/dist/parser/quotes.js +0 -67
  64. package/dist/parser/redirect.js +0 -26
  65. package/dist/parser/selector.js +0 -394
  66. package/dist/parser/table.js +0 -123
  67. package/dist/src/arg.d.ts +0 -51
  68. package/dist/src/arg.js +0 -214
  69. package/dist/src/atom.d.ts +0 -14
  70. package/dist/src/atom.js +0 -52
  71. package/dist/src/attribute.d.ts +0 -64
  72. package/dist/src/attribute.js +0 -483
  73. package/dist/src/attributes.d.ts +0 -101
  74. package/dist/src/attributes.js +0 -382
  75. package/dist/src/converter.d.ts +0 -28
  76. package/dist/src/converter.js +0 -147
  77. package/dist/src/converterFlags.d.ts +0 -80
  78. package/dist/src/converterFlags.js +0 -242
  79. package/dist/src/converterRule.d.ts +0 -71
  80. package/dist/src/converterRule.js +0 -216
  81. package/dist/src/extLink.d.ts +0 -36
  82. package/dist/src/extLink.js +0 -198
  83. package/dist/src/gallery.d.ts +0 -47
  84. package/dist/src/gallery.js +0 -142
  85. package/dist/src/heading.d.ts +0 -40
  86. package/dist/src/heading.js +0 -191
  87. package/dist/src/hidden.d.ts +0 -9
  88. package/dist/src/hidden.js +0 -80
  89. package/dist/src/html.d.ts +0 -57
  90. package/dist/src/html.js +0 -343
  91. package/dist/src/imageParameter.d.ts +0 -58
  92. package/dist/src/imageParameter.js +0 -247
  93. package/dist/src/imagemap.d.ts +0 -47
  94. package/dist/src/imagemap.js +0 -146
  95. package/dist/src/imagemapLink.d.ts +0 -31
  96. package/dist/src/imagemapLink.js +0 -97
  97. package/dist/src/index.d.ts +0 -141
  98. package/dist/src/index.js +0 -795
  99. package/dist/src/link/base.d.ts +0 -54
  100. package/dist/src/link/base.js +0 -263
  101. package/dist/src/link/category.d.ts +0 -22
  102. package/dist/src/link/category.js +0 -34
  103. package/dist/src/link/file.d.ts +0 -96
  104. package/dist/src/link/file.js +0 -276
  105. package/dist/src/link/galleryImage.d.ts +0 -29
  106. package/dist/src/link/galleryImage.js +0 -132
  107. package/dist/src/link/index.d.ts +0 -39
  108. package/dist/src/link/index.js +0 -99
  109. package/dist/src/link/redirectTarget.d.ts +0 -27
  110. package/dist/src/link/redirectTarget.js +0 -72
  111. package/dist/src/magicLink.d.ts +0 -61
  112. package/dist/src/magicLink.js +0 -261
  113. package/dist/src/nested.d.ts +0 -40
  114. package/dist/src/nested.js +0 -106
  115. package/dist/src/nowiki/base.d.ts +0 -30
  116. package/dist/src/nowiki/base.js +0 -89
  117. package/dist/src/nowiki/comment.d.ts +0 -14
  118. package/dist/src/nowiki/comment.js +0 -124
  119. package/dist/src/nowiki/dd.d.ts +0 -8
  120. package/dist/src/nowiki/dd.js +0 -72
  121. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -15
  122. package/dist/src/nowiki/doubleUnderscore.js +0 -97
  123. package/dist/src/nowiki/hr.d.ts +0 -5
  124. package/dist/src/nowiki/hr.js +0 -70
  125. package/dist/src/nowiki/index.d.ts +0 -14
  126. package/dist/src/nowiki/index.js +0 -31
  127. package/dist/src/nowiki/list.d.ts +0 -5
  128. package/dist/src/nowiki/list.js +0 -65
  129. package/dist/src/nowiki/listBase.d.ts +0 -17
  130. package/dist/src/nowiki/listBase.js +0 -75
  131. package/dist/src/nowiki/noinclude.d.ts +0 -6
  132. package/dist/src/nowiki/noinclude.js +0 -75
  133. package/dist/src/nowiki/quote.d.ts +0 -14
  134. package/dist/src/nowiki/quote.js +0 -135
  135. package/dist/src/onlyinclude.d.ts +0 -13
  136. package/dist/src/onlyinclude.js +0 -58
  137. package/dist/src/paramTag/index.d.ts +0 -30
  138. package/dist/src/paramTag/index.js +0 -78
  139. package/dist/src/paramTag/inputbox.d.ts +0 -8
  140. package/dist/src/paramTag/inputbox.js +0 -22
  141. package/dist/src/parameter.d.ts +0 -60
  142. package/dist/src/parameter.js +0 -268
  143. package/dist/src/pre.d.ts +0 -28
  144. package/dist/src/pre.js +0 -60
  145. package/dist/src/redirect.d.ts +0 -30
  146. package/dist/src/redirect.js +0 -126
  147. package/dist/src/syntax.d.ts +0 -17
  148. package/dist/src/syntax.js +0 -87
  149. package/dist/src/table/base.d.ts +0 -28
  150. package/dist/src/table/base.js +0 -81
  151. package/dist/src/table/index.d.ts +0 -230
  152. package/dist/src/table/index.js +0 -505
  153. package/dist/src/table/td.d.ts +0 -72
  154. package/dist/src/table/td.js +0 -370
  155. package/dist/src/table/tr.d.ts +0 -30
  156. package/dist/src/table/tr.js +0 -59
  157. package/dist/src/table/trBase.d.ts +0 -49
  158. package/dist/src/table/trBase.js +0 -164
  159. package/dist/src/tagPair/ext.d.ts +0 -29
  160. package/dist/src/tagPair/ext.js +0 -220
  161. package/dist/src/tagPair/include.d.ts +0 -33
  162. package/dist/src/tagPair/include.js +0 -130
  163. package/dist/src/tagPair/index.d.ts +0 -23
  164. package/dist/src/tagPair/index.js +0 -128
  165. package/dist/src/transclude.d.ts +0 -159
  166. package/dist/src/transclude.js +0 -587
  167. package/dist/util/constants.js +0 -25
  168. package/dist/util/debug.js +0 -95
  169. package/dist/util/diff.js +0 -83
  170. package/dist/util/lint.js +0 -32
  171. package/dist/util/string.js +0 -84
  172. package/errors/README +0 -3
  173. package/printed/README +0 -3
@@ -1,79 +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 onlyinclude_1 = require("../src/onlyinclude");
6
- const noinclude_1 = require("../src/nowiki/noinclude");
7
- const include_1 = require("../src/tagPair/include");
8
- const ext_1 = require("../src/tagPair/ext");
9
- const comment_1 = require("../src/nowiki/comment");
10
- /**
11
- * 解析HTML注释和扩展标签
12
- * @param wikitext
13
- * @param config
14
- * @param accum
15
- * @param includeOnly 是否嵌入
16
- */
17
- const parseCommentAndExt = (wikitext, config, accum, includeOnly) => {
18
- const onlyincludeLeft = '<onlyinclude>', onlyincludeRight = '</onlyinclude>', { length } = onlyincludeLeft;
19
- /** 更新`<onlyinclude>`和`</onlyinclude>`的位置 */
20
- const update = () => {
21
- const i = wikitext.indexOf(onlyincludeLeft);
22
- return { i, j: wikitext.indexOf(onlyincludeRight, i + length) };
23
- };
24
- if (includeOnly) {
25
- let { i, j } = update();
26
- if (i !== -1 && j !== -1) { // `<onlyinclude>`拥有最高优先级
27
- let str = '';
28
- /**
29
- * 忽略未被`<onlyinclude>`和`</onlyinclude>`包裹的内容
30
- * @param text 未被包裹的内容
31
- */
32
- const noinclude = (text) => {
33
- // @ts-expect-error abstract class
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
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
54
- /<!--.*?(?:-->|$)|<foo(?:\s[^>]*)?\/?>|<\/foo\s*>|<(bar)(\s[^>]*?)?(?:\/>|>(.*?)<\/(\1\s*)>)|<(baz)(\s[^>]*?)?(?:\/>|>(.*?)(?:<\/(baz\s*)>|$))/gisu;
55
- const ext = config.ext.join('|'), noincludeRegex = includeOnly ? 'includeonly' : '(?:no|only)include', includeRegex = includeOnly ? 'noinclude' : 'includeonly', regex = new RegExp(String.raw `<!--.*?(?:-->|$)|<${noincludeRegex}(?:\s[^>]*)?/?>|</${noincludeRegex}\s*>|<(${ext})(\s[^>]*?)?(?:/>|>(.*?)</(\1\s*)>)|<(${includeRegex})(\s[^>]*?)?(?:/>|>(.*?)(?:</(${includeRegex}\s*)>|$))`, 'gisu');
56
- return wikitext.replace(regex, (substr, name, attr, inner, closing, include, includeAttr, includeInner, includeClosing) => {
57
- const str = `\0${accum.length}${name ? 'e' : 'c'}\x7F`;
58
- if (name) {
59
- // @ts-expect-error abstract class
60
- new ext_1.ExtToken(name, attr, inner, closing, config, accum);
61
- }
62
- else if (substr.startsWith('<!--')) {
63
- const closed = substr.endsWith('-->');
64
- // @ts-expect-error abstract class
65
- new comment_1.CommentToken(substr.slice(4, closed ? -3 : undefined), closed, config, accum);
66
- }
67
- else if (include) {
68
- // @ts-expect-error abstract class
69
- new include_1.IncludeToken(include, includeAttr, includeInner, includeClosing, config, accum);
70
- }
71
- else {
72
- // @ts-expect-error abstract class
73
- new noinclude_1.NoincludeToken(substr, config, accum);
74
- }
75
- return str;
76
- });
77
- };
78
- exports.parseCommentAndExt = parseCommentAndExt;
79
- constants_1.parsers['parseCommentAndExt'] = __filename;
@@ -1,39 +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 converter_1 = require("../src/converter");
6
- /**
7
- * 解析语言变体转换
8
- * @param text
9
- * @param config
10
- * @param accum
11
- */
12
- const parseConverter = (text, config, accum) => {
13
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
14
- /;(?=(?:[^;]*?=>)?\s*zh\s*:|(?:\s|\0\d+c\x7F)*$)/u;
15
- const variants = `(?:${config.variants.join('|')})`, regex1 = /-\{/gu, regex2 = /-\{|\}-/gu, regex3 = new RegExp(String.raw `;(?=(?:[^;]*?=>)?\s*${variants}\s*:|(?:\s|\0\d+c\x7F)*$)`, 'u'), stack = [];
16
- let regex = regex1, mt = regex.exec(text);
17
- while (mt) {
18
- const { 0: syntax, index } = mt;
19
- if (syntax === '}-') {
20
- 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'), rules = temp.split(regex3).map(rule => rule.replace(/\x01/gu, ';'));
21
- // @ts-expect-error abstract class
22
- new converter_1.ConverterToken(flags, rules, config, accum);
23
- text = `${text.slice(0, top.index)}\0${length}v\x7F${text.slice(index + 2)}`;
24
- if (stack.length === 0) {
25
- regex = regex1;
26
- }
27
- regex.lastIndex = top.index + 3 + String(length).length;
28
- }
29
- else {
30
- stack.push(mt);
31
- regex = regex2;
32
- regex.lastIndex = index + 2;
33
- }
34
- mt = regex.exec(text);
35
- }
36
- return text;
37
- };
38
- exports.parseConverter = parseConverter;
39
- constants_1.parsers['parseConverter'] = __filename;
@@ -1,37 +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 extLink_1 = require("../src/extLink");
7
- const magicLink_1 = require("../src/magicLink");
8
- /**
9
- * 解析外部链接
10
- * @param wikitext
11
- * @param config
12
- * @param accum
13
- * @param inFile 是否在图链中
14
- */
15
- const parseExternalLinks = (wikitext, config, accum, inFile) => {
16
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
17
- /\[((?:ftp:\/\/|\/\/)(?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])[^[\]<>"\t\n\p{Zs}]*(?=[[\]<>"\t\p{Zs}]|\0\d))(\p{Zs}*(?!\p{Zs}))([^\]\n]*)\]/giu;
18
- const regex = new RegExp(String.raw `\[(\0\d+f\x7F|(?:(?:${config.protocol}|//)${string_1.extUrlCharFirst}|\0\d+m\x7F)${string_1.extUrlChar}(?=[[\]<>"\t\p{Zs}]|\0\d))(\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
- if (inFile) {
27
- // @ts-expect-error abstract class
28
- new magicLink_1.MagicLinkToken(url, 'ext-link-url', config, accum);
29
- return `[\0${length}f\x7F${space}${text}]`;
30
- }
31
- // @ts-expect-error abstract class
32
- new extLink_1.ExtLinkToken(url, space, text, config, accum);
33
- return `\0${length}w\x7F`;
34
- });
35
- };
36
- exports.parseExternalLinks = parseExternalLinks;
37
- constants_1.parsers['parseExternalLinks'] = __filename;
@@ -1,42 +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 hr_1 = require("../src/nowiki/hr");
6
- const doubleUnderscore_1 = require("../src/nowiki/doubleUnderscore");
7
- const heading_1 = require("../src/heading");
8
- /**
9
- * 解析`<hr>`和状态开关
10
- * @param {Token} root 根节点
11
- * @param config
12
- * @param accum
13
- */
14
- const parseHrAndDoubleUnderscore = ({ firstChild: { data }, type, name }, config, accum) => {
15
- const { doubleUnderscore } = config, insensitive = new Set(doubleUnderscore[0]), sensitive = new Set(doubleUnderscore[1]);
16
- if (type !== 'root' && (type !== 'ext-inner' || name !== 'poem')) {
17
- data = `\0${data}`;
18
- }
19
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
20
- /__(toc|notoc)__/giu;
21
- data = data.replace(/^((?:\0\d+c\x7F)*)(-{4,})/gmu, (_, lead, m) => {
22
- // @ts-expect-error abstract class
23
- new hr_1.HrToken(m, config, accum);
24
- return `${lead}\0${accum.length - 1}r\x7F`;
25
- }).replace(new RegExp(`__(${[...doubleUnderscore[0], ...doubleUnderscore[1]].join('|')})__`, 'giu'), (m, p1) => {
26
- const caseSensitive = sensitive.has(p1);
27
- if (caseSensitive || insensitive.has(p1.toLowerCase())) {
28
- // @ts-expect-error abstract class
29
- new doubleUnderscore_1.DoubleUnderscoreToken(p1, caseSensitive, config, accum);
30
- return `\0${accum.length - 1}u\x7F`;
31
- }
32
- return m;
33
- }).replace(/^((?:\0\d+c\x7F)*)(={1,6})(.+)\2((?:[^\S\n]|\0\d+c\x7F)*)$/gmu, (_, lead, equals, heading, trail) => {
34
- const text = `${lead}\0${accum.length}h\x7F`;
35
- // @ts-expect-error abstract class
36
- new heading_1.HeadingToken(equals.length, [heading, trail], config, accum);
37
- return text;
38
- });
39
- return type === 'root' || type === 'ext-inner' && name === 'poem' ? data : data.slice(1);
40
- };
41
- exports.parseHrAndDoubleUnderscore = parseHrAndDoubleUnderscore;
42
- constants_1.parsers['parseHrAndDoubleUnderscore'] = __filename;
@@ -1,38 +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 attributes_1 = require("../src/attributes");
6
- const html_1 = require("../src/html");
7
- /**
8
- * 解析HTML标签
9
- * @param wikitext
10
- * @param config
11
- * @param accum
12
- */
13
- const parseHtml = (wikitext, config, accum) => {
14
- const regex = /^(\/?)([a-z][^\s/>]*)((?:\s|\/(?!>))[^>]*?)?(\/?>)([^<]*)$/iu, { html } = config, elements = new Set([...html[0], ...html[1], ...html[2]]), bits = wikitext.split('<');
15
- let text = bits.shift();
16
- for (const x of bits) {
17
- const mt = regex.exec(x), t = mt?.[2], name = t?.toLowerCase();
18
- if (!mt || !elements.has(name)) {
19
- text += `<${x}`;
20
- continue;
21
- }
22
- const [, slash, , params = '', brace, rest] = mt, { length } = accum,
23
- // @ts-expect-error abstract class
24
- attrs = new attributes_1.AttributesToken(params, 'html-attrs', name, config, accum), itemprop = attrs.getAttr('itemprop');
25
- if (name === 'meta' && (itemprop === undefined || attrs.getAttr('content') === undefined)
26
- || name === 'link' && (itemprop === undefined || attrs.getAttr('href') === undefined)) {
27
- text += `<${x}`;
28
- accum.length = length;
29
- continue;
30
- }
31
- text += `\0${accum.length}x\x7F${rest}`;
32
- // @ts-expect-error abstract class
33
- new html_1.HtmlToken(t, attrs, slash === '/', brace === '/>', config, accum);
34
- }
35
- return text;
36
- };
37
- exports.parseHtml = parseHtml;
38
- constants_1.parsers['parseHtml'] = __filename;
@@ -1,101 +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 index_1 = require("../index");
6
- const quotes_1 = require("./quotes");
7
- const externalLinks_1 = require("./externalLinks");
8
- const index_2 = require("../src/link/index");
9
- const file_1 = require("../src/link/file");
10
- const category_1 = require("../src/link/category");
11
- /**
12
- * 解析内部链接
13
- * @param wikitext
14
- * @param config
15
- * @param accum
16
- */
17
- const parseLinks = (wikitext, config, accum) => {
18
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
19
- /^\s*(?:ftp:\/\/|\/\/)/iu;
20
- const regex = true // eslint-disable-line no-constant-condition, @typescript-eslint/no-unnecessary-condition
21
- ? /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(?:(\||\0\d+!\x7F)(.*?[^\]]))?\]\](.*)$/su
22
- : /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(?:(\||\0\d+!\x7F)(.*?[^\]])?)?\]\](.*)$/su, regexImg = /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(\||\0\d+!\x7F)(.*)$/su, regexExt = new RegExp(String.raw `^\s*(?:${config.protocol}|//)`, 'iu'), bits = wikitext.split('[[');
23
- let s = bits.shift();
24
- for (let i = 0; i < bits.length; i++) {
25
- let mightBeImg = false, link, delimiter, text, after;
26
- const x = bits[i], m = regex.exec(x);
27
- if (m) {
28
- [, link, delimiter, text, after] = m;
29
- if (after.startsWith(']') && text?.includes('[')) {
30
- text += ']';
31
- after = after.slice(1);
32
- }
33
- }
34
- else {
35
- const m2 = regexImg.exec(x);
36
- if (m2) {
37
- mightBeImg = true;
38
- [, link, delimiter, text] = m2;
39
- }
40
- }
41
- if (link === undefined || regexExt.test(link) || /\0\d+[exhbru]\x7F/u.test(link)) {
42
- s += `[[${x}`;
43
- continue;
44
- }
45
- const force = link.trim().startsWith(':');
46
- if (force && mightBeImg) {
47
- s += `[[${x}`;
48
- continue;
49
- }
50
- const title = index_1.default.normalizeTitle(link, 0, false, config, true, true, true), { ns, valid, interwiki } = title;
51
- if (!valid) {
52
- s += `[[${x}`;
53
- continue;
54
- }
55
- else if (mightBeImg) {
56
- if (interwiki || ns !== 6) {
57
- s += `[[${x}`;
58
- continue;
59
- }
60
- let found = false;
61
- for (i++; i < bits.length; i++) {
62
- const next = bits[i], p = next.split(']]');
63
- if (p.length > 2) {
64
- found = true;
65
- text += `[[${p[0]}]]${p[1]}`;
66
- after = p.slice(2).join(']]');
67
- break;
68
- }
69
- else if (p.length === 2) {
70
- text += `[[${p[0]}]]${p[1]}`;
71
- }
72
- else {
73
- text += `[[${next}`;
74
- break;
75
- }
76
- }
77
- text = (0, exports.parseLinks)(text, config, accum);
78
- if (!found) {
79
- s += `[[${link}${delimiter}${text}`;
80
- continue;
81
- }
82
- }
83
- text &&= (0, quotes_1.parseQuotes)(text, config, accum);
84
- let SomeLinkToken = index_2.LinkToken;
85
- if (!force) {
86
- if (!interwiki && ns === 6) {
87
- text &&= (0, externalLinks_1.parseExternalLinks)(text, config, accum, true);
88
- SomeLinkToken = file_1.FileToken;
89
- }
90
- else if (!interwiki && ns === 14) {
91
- SomeLinkToken = category_1.CategoryToken;
92
- }
93
- }
94
- s += `\0${accum.length}l\x7F${after}`;
95
- // @ts-expect-error abstract class
96
- new SomeLinkToken(link, text, config, accum, delimiter);
97
- }
98
- return s;
99
- };
100
- exports.parseLinks = parseLinks;
101
- constants_1.parsers['parseLinks'] = __filename;
@@ -1,99 +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 list_1 = require("../src/nowiki/list");
6
- const dd_1 = require("../src/nowiki/dd");
7
- /**
8
- * 解析列表
9
- * @param wikitext
10
- * @param config
11
- * @param accum
12
- */
13
- const parseList = (wikitext, config, accum) => {
14
- const mt = /^((?:\0\d+c\x7F)*)([;:*#]+\s*)/u.exec(wikitext);
15
- if (!mt) {
16
- return wikitext;
17
- }
18
- const [total, comment, prefix] = mt, parts = prefix.split(/(?=;)/u);
19
- let text = comment + parts.map((_, i) => `\0${accum.length + i}d\x7F`).join('') + wikitext.slice(total.length), dt = parts.length - (parts[0].startsWith(';') ? 0 : 1);
20
- for (const part of parts) {
21
- // @ts-expect-error abstract class
22
- new list_1.ListToken(part, config, accum);
23
- }
24
- if (!dt) {
25
- return text;
26
- }
27
- const { html: [normalTags] } = config, fullRegex = /:+\s*|-\{|\0\d+[xq]\x7F/gu;
28
- let regex = fullRegex, ex = regex.exec(text), lt = 0, lb = false, li = false, lc = 0;
29
- /**
30
- * 创建`DdToken`
31
- * @param syntax `:`
32
- * @param index 起点
33
- */
34
- const dd = (syntax, index) => {
35
- // @ts-expect-error abstract class
36
- new dd_1.DdToken(syntax, config, accum);
37
- return `${text.slice(0, index)}\0${accum.length - 1}d\x7F${text.slice(index + syntax.length)}`;
38
- };
39
- /**
40
- * 更新 `lt`
41
- * @param closing 是否是闭合标签
42
- */
43
- const update = (closing) => {
44
- if (!closing) {
45
- lt++;
46
- }
47
- else if (lt) {
48
- lt--;
49
- }
50
- };
51
- while (ex && dt) {
52
- const { 0: syntax, index } = ex;
53
- if (syntax === '-{') {
54
- if (!lc) {
55
- const { lastIndex } = regex;
56
- regex = /-\{|\}-/gu;
57
- regex.lastIndex = lastIndex;
58
- }
59
- lc++;
60
- }
61
- else if (syntax === '}-') {
62
- lc--;
63
- if (!lc) {
64
- const { lastIndex } = regex;
65
- regex = fullRegex;
66
- regex.lastIndex = lastIndex;
67
- }
68
- }
69
- else if (syntax.endsWith('x\x7F')) {
70
- const { name, closing, selfClosing } = accum[Number(syntax.slice(1, -2))];
71
- if (!selfClosing || normalTags.includes(name)) {
72
- update(closing);
73
- }
74
- }
75
- else if (syntax.endsWith('q\x7F')) {
76
- const { bold, italic } = accum[Number(syntax.slice(1, -2))];
77
- if (bold) {
78
- update(lb);
79
- lb = !lb;
80
- }
81
- if (italic) {
82
- update(li);
83
- li = !li;
84
- }
85
- }
86
- else if (lt === 0) { // syntax === ':'
87
- if (syntax.length >= dt) {
88
- return dd(syntax.slice(0, dt), index);
89
- }
90
- dt -= syntax.length;
91
- regex.lastIndex = index + 4 + String(accum.length).length;
92
- text = dd(syntax, index);
93
- }
94
- ex = regex.exec(text);
95
- }
96
- return text;
97
- };
98
- exports.parseList = parseList;
99
- constants_1.parsers['parseList'] = __filename;
@@ -1,53 +0,0 @@
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 magicLink_1 = require("../src/magicLink");
7
- const sepRegex = /[^,;\\.:!?)][,;\\.:!?)]+$/u, sepLparRegex = /[^,;\\.:!?][,;\\.:!?]+$/u;
8
- /**
9
- * 解析自由外链
10
- * @param wikitext
11
- * @param config
12
- * @param accum
13
- */
14
- const parseMagicLinks = (wikitext, config, accum) => {
15
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
16
- /(^|[^\p{L}\d_])(?:(?:ftp:\/\/|http:\/\/)((?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])[^[\]<>"\0\t\n\p{Zs}]*)|(?:rfc|pmid)[\p{Zs}\t]+\d+\b|isbn[\p{Zs}\t]+(?:97[89][\p{Zs}\t-]?)?(?:\d[\p{Zs}\t-]?){9}[\dx]\b)/giu;
17
- const space = String.raw `[\p{Zs}\t]|&nbsp;|&#0*160;|&#x0*a0;`, spdash = `(?:${space}|-)`, regex = new RegExp(String.raw `(^|[^\p{L}\d_])(?:(?:${config.protocol})(${string_1.extUrlCharFirst}${string_1.extUrlChar})|(?:RFC|PMID)(?:${space})+\d+\b|ISBN(?:${space})+(?:97[89]${spdash}?)?(?:\d${spdash}?){9}[\dx]\b)`, 'giu');
18
- return wikitext.replace(regex, (m, lead, p1) => {
19
- let url = lead ? m.slice(lead.length) : m;
20
- if (p1) {
21
- let trail = '';
22
- const m2 = /&(?:lt|gt|nbsp|#x0*(?:3[ce]|a0)|#0*(?:6[02]|160));/iu.exec(url);
23
- if (m2) {
24
- trail = url.slice(m2.index);
25
- url = url.slice(0, m2.index);
26
- }
27
- const sep = url.includes('(') ? sepLparRegex : sepRegex, sepChars = sep.exec(url);
28
- if (sepChars) {
29
- let correction = 1;
30
- if (sepChars[0][1] === ';'
31
- && /&(?:[a-z]+|#x[\da-f]+|#\d+)$/iu.test(url.slice(0, sepChars.index))) {
32
- correction = 2;
33
- }
34
- trail = url.slice(sepChars.index + correction) + trail;
35
- url = url.slice(0, sepChars.index + correction);
36
- }
37
- if (trail.length >= p1.length) {
38
- return m;
39
- }
40
- // @ts-expect-error abstract class
41
- new magicLink_1.MagicLinkToken(url, undefined, config, accum);
42
- return `${lead}\0${accum.length - 1}w\x7F${trail}`;
43
- }
44
- else if (!/^(?:RFC|PMID|ISBN)/u.test(url)) {
45
- return m;
46
- }
47
- // @ts-expect-error abstract class
48
- new magicLink_1.MagicLinkToken(url, 'magic-link', config, accum);
49
- return `${lead}\0${accum.length - 1}i\x7F`;
50
- });
51
- };
52
- exports.parseMagicLinks = parseMagicLinks;
53
- constants_1.parsers['parseMagicLinks'] = __filename;
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseQuotes = void 0;
4
- const constants_1 = require("../util/constants");
5
- const quote_1 = require("../src/nowiki/quote");
6
- /**
7
- * 解析单引号
8
- * @param wikitext
9
- * @param config
10
- * @param accum
11
- */
12
- const parseQuotes = (wikitext, config, accum) => {
13
- const arr = wikitext.split(/('{2,})/u), { length } = arr;
14
- if (length === 1) {
15
- return wikitext;
16
- }
17
- let nBold = 0, nItalic = 0, firstSingle, firstMulti, firstSpace;
18
- for (let i = 1; i < length; i += 2) {
19
- const len = arr[i].length;
20
- switch (len) {
21
- case 2:
22
- nItalic++;
23
- break;
24
- case 4:
25
- arr[i - 1] += `'`;
26
- arr[i] = `'''`;
27
- // fall through
28
- case 3:
29
- nBold++;
30
- if (firstSingle !== undefined) {
31
- break;
32
- }
33
- else if (arr[i - 1].endsWith(' ')) {
34
- if (firstMulti === undefined && firstSpace === undefined) {
35
- firstSpace = i;
36
- }
37
- }
38
- else if (arr[i - 1].slice(-2, -1) === ' ') {
39
- firstSingle = i;
40
- }
41
- else {
42
- firstMulti ??= i;
43
- }
44
- break;
45
- default:
46
- arr[i - 1] += `'`.repeat(len - 5);
47
- arr[i] = `'''''`;
48
- nItalic++;
49
- nBold++;
50
- }
51
- }
52
- if (nItalic % 2 === 1 && nBold % 2 === 1) {
53
- const i = firstSingle ?? firstMulti ?? firstSpace;
54
- if (i !== undefined) {
55
- arr[i] = `''`;
56
- arr[i - 1] += `'`;
57
- }
58
- }
59
- for (let i = 1; i < length; i += 2) {
60
- // @ts-expect-error abstract class
61
- new quote_1.QuoteToken(arr[i], config, accum);
62
- arr[i] = `\0${accum.length - 1}q\x7F`;
63
- }
64
- return arr.join('');
65
- };
66
- exports.parseQuotes = parseQuotes;
67
- constants_1.parsers['parseQuotes'] = __filename;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseRedirect = void 0;
4
- const constants_1 = require("../util/constants");
5
- const index_1 = require("../index");
6
- const redirect_1 = require("../src/redirect");
7
- /**
8
- * 解析重定向
9
- * @param text
10
- * @param config
11
- * @param accum
12
- */
13
- const parseRedirect = (text, config, accum) => {
14
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
15
- /^(\s*)((?:#redirect|#重定向)\s*(?::\s*)?)\[\[([^\n|\]]+)(\|.*?)?\]\](\s*)/iu;
16
- const re = new RegExp(String.raw `^(\s*)((?:${config.redirection.join('|')})\s*(?::\s*)?)\[\[([^\n|\]]+)(\|.*?)?\]\](\s*)`, 'iu'), mt = re.exec(text);
17
- if (mt && index_1.default.normalizeTitle(mt[3], 0, false, config, true, true).valid) {
18
- text = `\0${accum.length}c\x7F${text.slice(mt[0].length)}`;
19
- // @ts-expect-error abstract class
20
- new redirect_1.RedirectToken(...mt.slice(1), config, accum);
21
- return text;
22
- }
23
- return false;
24
- };
25
- exports.parseRedirect = parseRedirect;
26
- constants_1.parsers['parseRedirect'] = __filename;