wikiparser-node 1.9.2 → 1.9.3-b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/bundle/bundle.min.js +39 -0
  2. package/config/enwiki.json +1 -814
  3. package/config/llwiki.json +1 -35
  4. package/config/moegirl.json +1 -44
  5. package/config/zhwiki.json +1 -466
  6. package/extensions/dist/base.js +64 -0
  7. package/extensions/dist/editor.js +159 -0
  8. package/extensions/dist/highlight.js +58 -0
  9. package/extensions/dist/lint.js +72 -0
  10. package/extensions/editor.css +64 -0
  11. package/extensions/ui.css +144 -0
  12. package/package.json +32 -22
  13. package/config/.schema.json +0 -181
  14. package/dist/addon/table.js +0 -486
  15. package/dist/addon/token.js +0 -240
  16. package/dist/addon/transclude.js +0 -185
  17. package/dist/base.d.ts +0 -73
  18. package/dist/base.js +0 -39
  19. package/dist/index.d.ts +0 -31
  20. package/dist/index.js +0 -232
  21. package/dist/internal.d.ts +0 -46
  22. package/dist/lib/element.d.ts +0 -124
  23. package/dist/lib/element.js +0 -600
  24. package/dist/lib/node.d.ts +0 -166
  25. package/dist/lib/node.js +0 -472
  26. package/dist/lib/range.d.ts +0 -105
  27. package/dist/lib/range.js +0 -406
  28. package/dist/lib/ranges.d.ts +0 -28
  29. package/dist/lib/ranges.js +0 -126
  30. package/dist/lib/rect.d.ts +0 -18
  31. package/dist/lib/rect.js +0 -34
  32. package/dist/lib/text.d.ts +0 -54
  33. package/dist/lib/text.js +0 -345
  34. package/dist/lib/title.d.ts +0 -40
  35. package/dist/lib/title.js +0 -197
  36. package/dist/mixin/attributesParent.d.ts +0 -49
  37. package/dist/mixin/attributesParent.js +0 -82
  38. package/dist/mixin/fixed.d.ts +0 -5
  39. package/dist/mixin/fixed.js +0 -32
  40. package/dist/mixin/flagsParent.d.ts +0 -41
  41. package/dist/mixin/flagsParent.js +0 -60
  42. package/dist/mixin/hidden.d.ts +0 -6
  43. package/dist/mixin/hidden.js +0 -29
  44. package/dist/mixin/magicLinkParent.d.ts +0 -19
  45. package/dist/mixin/magicLinkParent.js +0 -43
  46. package/dist/mixin/singleLine.d.ts +0 -5
  47. package/dist/mixin/singleLine.js +0 -27
  48. package/dist/mixin/sol.d.ts +0 -5
  49. package/dist/mixin/sol.js +0 -44
  50. package/dist/mixin/syntax.d.ts +0 -8
  51. package/dist/mixin/syntax.js +0 -47
  52. package/dist/parser/braces.js +0 -150
  53. package/dist/parser/commentAndExt.js +0 -79
  54. package/dist/parser/converter.js +0 -39
  55. package/dist/parser/externalLinks.js +0 -37
  56. package/dist/parser/hrAndDoubleUnderscore.js +0 -42
  57. package/dist/parser/html.js +0 -38
  58. package/dist/parser/links.js +0 -101
  59. package/dist/parser/list.js +0 -97
  60. package/dist/parser/magicLinks.js +0 -53
  61. package/dist/parser/quotes.js +0 -67
  62. package/dist/parser/redirect.js +0 -26
  63. package/dist/parser/selector.js +0 -190
  64. package/dist/parser/table.js +0 -123
  65. package/dist/src/arg.d.ts +0 -52
  66. package/dist/src/arg.js +0 -213
  67. package/dist/src/atom.d.ts +0 -12
  68. package/dist/src/atom.js +0 -26
  69. package/dist/src/attribute.d.ts +0 -65
  70. package/dist/src/attribute.js +0 -483
  71. package/dist/src/attributes.d.ts +0 -103
  72. package/dist/src/attributes.js +0 -350
  73. package/dist/src/converter.d.ts +0 -29
  74. package/dist/src/converter.js +0 -134
  75. package/dist/src/converterFlags.d.ts +0 -81
  76. package/dist/src/converterFlags.js +0 -239
  77. package/dist/src/converterRule.d.ts +0 -73
  78. package/dist/src/converterRule.js +0 -210
  79. package/dist/src/extLink.d.ts +0 -37
  80. package/dist/src/extLink.js +0 -191
  81. package/dist/src/gallery.d.ts +0 -48
  82. package/dist/src/gallery.js +0 -139
  83. package/dist/src/heading.d.ts +0 -41
  84. package/dist/src/heading.js +0 -185
  85. package/dist/src/hidden.d.ts +0 -10
  86. package/dist/src/hidden.js +0 -79
  87. package/dist/src/html.d.ts +0 -58
  88. package/dist/src/html.js +0 -334
  89. package/dist/src/imageParameter.d.ts +0 -59
  90. package/dist/src/imageParameter.js +0 -246
  91. package/dist/src/imagemap.d.ts +0 -48
  92. package/dist/src/imagemap.js +0 -145
  93. package/dist/src/imagemapLink.d.ts +0 -31
  94. package/dist/src/imagemapLink.js +0 -93
  95. package/dist/src/index.d.ts +0 -130
  96. package/dist/src/index.js +0 -721
  97. package/dist/src/link/base.d.ts +0 -46
  98. package/dist/src/link/base.js +0 -224
  99. package/dist/src/link/category.d.ts +0 -22
  100. package/dist/src/link/category.js +0 -30
  101. package/dist/src/link/file.d.ts +0 -96
  102. package/dist/src/link/file.js +0 -274
  103. package/dist/src/link/galleryImage.d.ts +0 -30
  104. package/dist/src/link/galleryImage.js +0 -158
  105. package/dist/src/link/index.d.ts +0 -52
  106. package/dist/src/link/index.js +0 -133
  107. package/dist/src/link/redirectTarget.d.ts +0 -37
  108. package/dist/src/link/redirectTarget.js +0 -95
  109. package/dist/src/magicLink.d.ts +0 -60
  110. package/dist/src/magicLink.js +0 -270
  111. package/dist/src/nested.d.ts +0 -41
  112. package/dist/src/nested.js +0 -105
  113. package/dist/src/nowiki/base.d.ts +0 -31
  114. package/dist/src/nowiki/base.js +0 -91
  115. package/dist/src/nowiki/comment.d.ts +0 -15
  116. package/dist/src/nowiki/comment.js +0 -123
  117. package/dist/src/nowiki/dd.d.ts +0 -8
  118. package/dist/src/nowiki/dd.js +0 -24
  119. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -16
  120. package/dist/src/nowiki/doubleUnderscore.js +0 -96
  121. package/dist/src/nowiki/hr.d.ts +0 -5
  122. package/dist/src/nowiki/hr.js +0 -63
  123. package/dist/src/nowiki/index.d.ts +0 -14
  124. package/dist/src/nowiki/index.js +0 -29
  125. package/dist/src/nowiki/list.d.ts +0 -16
  126. package/dist/src/nowiki/list.js +0 -109
  127. package/dist/src/nowiki/listBase.d.ts +0 -5
  128. package/dist/src/nowiki/listBase.js +0 -61
  129. package/dist/src/nowiki/noinclude.d.ts +0 -10
  130. package/dist/src/nowiki/noinclude.js +0 -73
  131. package/dist/src/nowiki/quote.d.ts +0 -17
  132. package/dist/src/nowiki/quote.js +0 -131
  133. package/dist/src/onlyinclude.d.ts +0 -14
  134. package/dist/src/onlyinclude.js +0 -57
  135. package/dist/src/paramTag/index.d.ts +0 -31
  136. package/dist/src/paramTag/index.js +0 -77
  137. package/dist/src/paramTag/inputbox.d.ts +0 -8
  138. package/dist/src/paramTag/inputbox.js +0 -22
  139. package/dist/src/parameter.d.ts +0 -66
  140. package/dist/src/parameter.js +0 -265
  141. package/dist/src/pre.d.ts +0 -29
  142. package/dist/src/pre.js +0 -59
  143. package/dist/src/redirect.d.ts +0 -31
  144. package/dist/src/redirect.js +0 -121
  145. package/dist/src/syntax.d.ts +0 -17
  146. package/dist/src/syntax.js +0 -84
  147. package/dist/src/table/base.d.ts +0 -29
  148. package/dist/src/table/base.js +0 -82
  149. package/dist/src/table/index.d.ts +0 -239
  150. package/dist/src/table/index.js +0 -502
  151. package/dist/src/table/td.d.ts +0 -78
  152. package/dist/src/table/td.js +0 -368
  153. package/dist/src/table/tr.d.ts +0 -30
  154. package/dist/src/table/tr.js +0 -57
  155. package/dist/src/table/trBase.d.ts +0 -49
  156. package/dist/src/table/trBase.js +0 -156
  157. package/dist/src/tagPair/ext.d.ts +0 -30
  158. package/dist/src/tagPair/ext.js +0 -201
  159. package/dist/src/tagPair/include.d.ts +0 -35
  160. package/dist/src/tagPair/include.js +0 -124
  161. package/dist/src/tagPair/index.d.ts +0 -23
  162. package/dist/src/tagPair/index.js +0 -128
  163. package/dist/src/transclude.d.ts +0 -160
  164. package/dist/src/transclude.js +0 -579
  165. package/dist/util/constants.js +0 -25
  166. package/dist/util/debug.js +0 -97
  167. package/dist/util/diff.js +0 -83
  168. package/dist/util/lint.js +0 -32
  169. package/dist/util/string.js +0 -60
  170. package/errors/README +0 -1
  171. package/printed/README +0 -1
@@ -1,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,97 +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)*)([;:*#]+)/u.exec(wikitext);
15
- if (!mt) {
16
- return wikitext;
17
- }
18
- const [total, comment, prefix] = mt;
19
- let text = `${comment}\0${accum.length}d\x7F${wikitext.slice(total.length)}`, dt = prefix.split(';').length - 1;
20
- // @ts-expect-error abstract class
21
- new list_1.ListToken(prefix, config, accum);
22
- if (!dt) {
23
- return text;
24
- }
25
- const { html: [normalTags] } = config, fullRegex = /:+|-\{|\0\d+[xq]\x7F/gu;
26
- let regex = fullRegex, ex = regex.exec(text), lt = 0, lb = false, li = false, lc = 0;
27
- /**
28
- * 创建`DdToken`
29
- * @param syntax `:`
30
- * @param index 起点
31
- */
32
- const dd = (syntax, index) => {
33
- // @ts-expect-error abstract class
34
- new dd_1.DdToken(syntax, config, accum);
35
- return `${text.slice(0, index)}\0${accum.length - 1}d\x7F${text.slice(index + syntax.length)}`;
36
- };
37
- /**
38
- * 更新 `lt`
39
- * @param closing 是否是闭合标签
40
- */
41
- const update = (closing) => {
42
- if (!closing) {
43
- lt++;
44
- }
45
- else if (lt) {
46
- lt--;
47
- }
48
- };
49
- while (ex && dt) {
50
- const { 0: syntax, index } = ex;
51
- if (syntax === '-{') {
52
- if (!lc) {
53
- const { lastIndex } = regex;
54
- regex = /-\{|\}-/gu;
55
- regex.lastIndex = lastIndex;
56
- }
57
- lc++;
58
- }
59
- else if (syntax === '}-') {
60
- lc--;
61
- if (!lc) {
62
- const { lastIndex } = regex;
63
- regex = fullRegex;
64
- regex.lastIndex = lastIndex;
65
- }
66
- }
67
- else if (syntax.endsWith('x\x7F')) {
68
- const { name, closing, selfClosing } = accum[Number(syntax.slice(1, -2))];
69
- if (!selfClosing || normalTags.includes(name)) {
70
- update(closing);
71
- }
72
- }
73
- else if (syntax.endsWith('q\x7F')) {
74
- const { bold, italic } = accum[Number(syntax.slice(1, -2))];
75
- if (bold) {
76
- update(lb);
77
- lb = !lb;
78
- }
79
- if (italic) {
80
- update(li);
81
- li = !li;
82
- }
83
- }
84
- else if (lt === 0) { // syntax === ':'
85
- if (syntax.length >= dt) {
86
- return dd(syntax.slice(0, dt), index);
87
- }
88
- dt -= syntax.length;
89
- regex.lastIndex = index + 4 + String(accum.length).length;
90
- text = dd(syntax, index);
91
- }
92
- ex = regex.exec(text);
93
- }
94
- return text;
95
- };
96
- exports.parseList = parseList;
97
- 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;