wikiparser-node 1.11.0 → 1.11.1-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 (172) 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/package.json +28 -35
  13. package/config/.schema.json +0 -186
  14. package/dist/addon/table.js +0 -486
  15. package/dist/addon/token.js +0 -304
  16. package/dist/addon/transclude.js +0 -184
  17. package/dist/base.d.ts +0 -81
  18. package/dist/base.js +0 -39
  19. package/dist/index.d.ts +0 -33
  20. package/dist/index.js +0 -235
  21. package/dist/internal.d.ts +0 -46
  22. package/dist/lib/element.d.ts +0 -125
  23. package/dist/lib/element.js +0 -375
  24. package/dist/lib/node.d.ts +0 -173
  25. package/dist/lib/node.js +0 -478
  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 -58
  33. package/dist/lib/text.js +0 -400
  34. package/dist/lib/title.d.ts +0 -42
  35. package/dist/lib/title.js +0 -208
  36. package/dist/mixin/attributesParent.d.ts +0 -49
  37. package/dist/mixin/attributesParent.js +0 -79
  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 -43
  41. package/dist/mixin/flagsParent.js +0 -64
  42. package/dist/mixin/hidden.d.ts +0 -7
  43. package/dist/mixin/hidden.js +0 -37
  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 -25
  48. package/dist/mixin/sol.d.ts +0 -6
  49. package/dist/mixin/sol.js +0 -45
  50. package/dist/mixin/syntax.d.ts +0 -8
  51. package/dist/mixin/syntax.js +0 -46
  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 -114
  60. package/dist/parser/magicLinks.js +0 -52
  61. package/dist/parser/quotes.js +0 -67
  62. package/dist/parser/redirect.js +0 -26
  63. package/dist/parser/selector.js +0 -394
  64. package/dist/parser/table.js +0 -123
  65. package/dist/src/arg.d.ts +0 -51
  66. package/dist/src/arg.js +0 -214
  67. package/dist/src/atom.d.ts +0 -14
  68. package/dist/src/atom.js +0 -52
  69. package/dist/src/attribute.d.ts +0 -64
  70. package/dist/src/attribute.js +0 -480
  71. package/dist/src/attributes.d.ts +0 -101
  72. package/dist/src/attributes.js +0 -381
  73. package/dist/src/converter.d.ts +0 -28
  74. package/dist/src/converter.js +0 -148
  75. package/dist/src/converterFlags.d.ts +0 -80
  76. package/dist/src/converterFlags.js +0 -239
  77. package/dist/src/converterRule.d.ts +0 -71
  78. package/dist/src/converterRule.js +0 -216
  79. package/dist/src/extLink.d.ts +0 -36
  80. package/dist/src/extLink.js +0 -218
  81. package/dist/src/gallery.d.ts +0 -47
  82. package/dist/src/gallery.js +0 -143
  83. package/dist/src/heading.d.ts +0 -40
  84. package/dist/src/heading.js +0 -192
  85. package/dist/src/hidden.d.ts +0 -9
  86. package/dist/src/hidden.js +0 -80
  87. package/dist/src/html.d.ts +0 -61
  88. package/dist/src/html.js +0 -343
  89. package/dist/src/imageParameter.d.ts +0 -60
  90. package/dist/src/imageParameter.js +0 -260
  91. package/dist/src/imagemap.d.ts +0 -47
  92. package/dist/src/imagemap.js +0 -146
  93. package/dist/src/imagemapLink.d.ts +0 -31
  94. package/dist/src/imagemapLink.js +0 -97
  95. package/dist/src/index.d.ts +0 -136
  96. package/dist/src/index.js +0 -834
  97. package/dist/src/link/base.d.ts +0 -52
  98. package/dist/src/link/base.js +0 -256
  99. package/dist/src/link/category.d.ts +0 -22
  100. package/dist/src/link/category.js +0 -34
  101. package/dist/src/link/file.d.ts +0 -102
  102. package/dist/src/link/file.js +0 -333
  103. package/dist/src/link/galleryImage.d.ts +0 -29
  104. package/dist/src/link/galleryImage.js +0 -132
  105. package/dist/src/link/index.d.ts +0 -39
  106. package/dist/src/link/index.js +0 -98
  107. package/dist/src/link/redirectTarget.d.ts +0 -27
  108. package/dist/src/link/redirectTarget.js +0 -69
  109. package/dist/src/magicLink.d.ts +0 -58
  110. package/dist/src/magicLink.js +0 -256
  111. package/dist/src/nested.d.ts +0 -40
  112. package/dist/src/nested.js +0 -106
  113. package/dist/src/nowiki/base.d.ts +0 -28
  114. package/dist/src/nowiki/base.js +0 -89
  115. package/dist/src/nowiki/comment.d.ts +0 -14
  116. package/dist/src/nowiki/comment.js +0 -121
  117. package/dist/src/nowiki/dd.d.ts +0 -8
  118. package/dist/src/nowiki/dd.js +0 -72
  119. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -15
  120. package/dist/src/nowiki/doubleUnderscore.js +0 -97
  121. package/dist/src/nowiki/hr.d.ts +0 -5
  122. package/dist/src/nowiki/hr.js +0 -70
  123. package/dist/src/nowiki/index.d.ts +0 -14
  124. package/dist/src/nowiki/index.js +0 -28
  125. package/dist/src/nowiki/list.d.ts +0 -5
  126. package/dist/src/nowiki/list.js +0 -65
  127. package/dist/src/nowiki/listBase.d.ts +0 -23
  128. package/dist/src/nowiki/listBase.js +0 -99
  129. package/dist/src/nowiki/noinclude.d.ts +0 -6
  130. package/dist/src/nowiki/noinclude.js +0 -75
  131. package/dist/src/nowiki/quote.d.ts +0 -14
  132. package/dist/src/nowiki/quote.js +0 -140
  133. package/dist/src/onlyinclude.d.ts +0 -13
  134. package/dist/src/onlyinclude.js +0 -58
  135. package/dist/src/paramTag/index.d.ts +0 -28
  136. package/dist/src/paramTag/index.js +0 -78
  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 -60
  140. package/dist/src/parameter.js +0 -264
  141. package/dist/src/pre.d.ts +0 -28
  142. package/dist/src/pre.js +0 -60
  143. package/dist/src/redirect.d.ts +0 -30
  144. package/dist/src/redirect.js +0 -126
  145. package/dist/src/syntax.d.ts +0 -17
  146. package/dist/src/syntax.js +0 -87
  147. package/dist/src/table/base.d.ts +0 -28
  148. package/dist/src/table/base.js +0 -81
  149. package/dist/src/table/index.d.ts +0 -230
  150. package/dist/src/table/index.js +0 -506
  151. package/dist/src/table/td.d.ts +0 -72
  152. package/dist/src/table/td.js +0 -370
  153. package/dist/src/table/tr.d.ts +0 -30
  154. package/dist/src/table/tr.js +0 -59
  155. package/dist/src/table/trBase.d.ts +0 -49
  156. package/dist/src/table/trBase.js +0 -164
  157. package/dist/src/tagPair/ext.d.ts +0 -29
  158. package/dist/src/tagPair/ext.js +0 -220
  159. package/dist/src/tagPair/include.d.ts +0 -33
  160. package/dist/src/tagPair/include.js +0 -130
  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 -159
  164. package/dist/src/transclude.js +0 -587
  165. package/dist/util/constants.js +0 -25
  166. package/dist/util/debug.js +0 -95
  167. package/dist/util/diff.js +0 -83
  168. package/dist/util/html.js +0 -143
  169. package/dist/util/lint.js +0 -32
  170. package/dist/util/string.js +0 -87
  171. package/errors/README +0 -3
  172. 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,114 +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 html_1 = require("../util/html");
6
- const list_1 = require("../src/nowiki/list");
7
- const dd_1 = require("../src/nowiki/dd");
8
- /**
9
- * 解析列表
10
- * @param wikitext
11
- * @param state
12
- * @param state.lastPrefix 上一个列表的前缀
13
- * @param config
14
- * @param accum
15
- */
16
- const parseList = (wikitext, state, config, accum) => {
17
- const mt = /^((?:\0\d+c\x7F)*)([;:*#]+\s*)/u.exec(wikitext);
18
- if (!mt) {
19
- state.lastPrefix = '';
20
- return wikitext;
21
- }
22
- const [total, comment, prefix] = mt, prefix2 = prefix.replace(/;/gu, ':'), commonPrefixLength = (0, html_1.getCommon)(prefix2, state.lastPrefix), parts = (commonPrefixLength > 1 ? prefix.slice(commonPrefixLength - 1) : prefix).split(/(?=;)/u), isDt = parts[0].startsWith(';');
23
- let dt = parts.length - (isDt ? 0 : 1);
24
- if (commonPrefixLength > 1) {
25
- const commonPrefix = prefix.slice(0, commonPrefixLength - 1);
26
- if (isDt) {
27
- parts.unshift(commonPrefix);
28
- }
29
- else {
30
- parts[0] = commonPrefix + parts[0];
31
- }
32
- }
33
- state.lastPrefix = prefix2;
34
- let text = comment + parts.map((_, i) => `\0${accum.length + i}d\x7F`).join('') + wikitext.slice(total.length);
35
- for (const part of parts) {
36
- // @ts-expect-error abstract class
37
- new list_1.ListToken(part, config, accum);
38
- }
39
- if (!dt) {
40
- return text;
41
- }
42
- const { html: [normalTags] } = config, fullRegex = /:+|-\{|\0\d+[xq]\x7F/gu;
43
- let regex = fullRegex, ex = regex.exec(text), lt = 0, lb = false, li = false, lc = 0;
44
- /**
45
- * 创建`DdToken`
46
- * @param syntax `:`
47
- * @param index 起点
48
- */
49
- const dd = (syntax, index) => {
50
- // @ts-expect-error abstract class
51
- new dd_1.DdToken(syntax, config, accum);
52
- return `${text.slice(0, index)}\0${accum.length - 1}d\x7F${text.slice(index + syntax.length)}`;
53
- };
54
- /**
55
- * 更新 `lt`
56
- * @param closing 是否是闭合标签
57
- */
58
- const update = (closing) => {
59
- if (!closing) {
60
- lt++;
61
- }
62
- else if (lt) {
63
- lt--;
64
- }
65
- };
66
- while (ex && dt) {
67
- const { 0: syntax, index } = ex;
68
- if (syntax === '-{') {
69
- if (!lc) {
70
- const { lastIndex } = regex;
71
- regex = /-\{|\}-/gu;
72
- regex.lastIndex = lastIndex;
73
- }
74
- lc++;
75
- }
76
- else if (syntax === '}-') {
77
- lc--;
78
- if (!lc) {
79
- const { lastIndex } = regex;
80
- regex = fullRegex;
81
- regex.lastIndex = lastIndex;
82
- }
83
- }
84
- else if (syntax.endsWith('x\x7F')) {
85
- const { name, closing, selfClosing } = accum[Number(syntax.slice(1, -2))];
86
- if (!selfClosing || normalTags.includes(name)) {
87
- update(closing);
88
- }
89
- }
90
- else if (syntax.endsWith('q\x7F')) {
91
- const { bold, italic } = accum[Number(syntax.slice(1, -2))];
92
- if (bold) {
93
- update(lb);
94
- lb = !lb;
95
- }
96
- if (italic) {
97
- update(li);
98
- li = !li;
99
- }
100
- }
101
- else if (lt === 0) { // syntax === ':'
102
- if (syntax.length >= dt) {
103
- return dd(syntax.slice(0, dt), index);
104
- }
105
- dt -= syntax.length;
106
- regex.lastIndex = index + 4 + String(accum.length).length;
107
- text = dd(syntax, index);
108
- }
109
- ex = regex.exec(text);
110
- }
111
- return text;
112
- };
113
- exports.parseList = parseList;
114
- constants_1.parsers['parseList'] = __filename;
@@ -1,52 +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
- /**
8
- * 解析自由外链
9
- * @param wikitext
10
- * @param config
11
- * @param accum
12
- */
13
- const parseMagicLinks = (wikitext, config, accum) => {
14
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
15
- /(^|[^\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;
16
- 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');
17
- return wikitext.replace(regex, (m, lead, p1) => {
18
- let url = lead ? m.slice(lead.length) : m;
19
- if (p1) {
20
- let trail = '';
21
- const m2 = /&(?:lt|gt|nbsp|#x0*(?:3[ce]|a0)|#0*(?:6[02]|160));/iu.exec(url);
22
- if (m2) {
23
- trail = url.slice(m2.index);
24
- url = url.slice(0, m2.index);
25
- }
26
- const sep = url.includes('(') ? /[^,;\\.:!?][,;\\.:!?]+$/u : /[^,;\\.:!?)][,;\\.:!?)]+$/u, sepChars = sep.exec(url);
27
- if (sepChars) {
28
- let correction = 1;
29
- if (sepChars[0][1] === ';'
30
- && /&(?:[a-z]+|#x[\da-f]+|#\d+)$/iu.test(url.slice(0, sepChars.index))) {
31
- correction = 2;
32
- }
33
- trail = url.slice(sepChars.index + correction) + trail;
34
- url = url.slice(0, sepChars.index + correction);
35
- }
36
- if (trail.length >= p1.length) {
37
- return m;
38
- }
39
- // @ts-expect-error abstract class
40
- new magicLink_1.MagicLinkToken(url, undefined, config, accum);
41
- return `${lead}\0${accum.length - 1}w\x7F${trail}`;
42
- }
43
- else if (!/^(?:RFC|PMID|ISBN)/u.test(url)) {
44
- return m;
45
- }
46
- // @ts-expect-error abstract class
47
- new magicLink_1.MagicLinkToken(url, 'magic-link', config, accum);
48
- return `${lead}\0${accum.length - 1}i\x7F`;
49
- });
50
- };
51
- exports.parseMagicLinks = parseMagicLinks;
52
- 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;