wikiparser-node 1.6.2 → 1.7.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 (169) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/bundle/bundle.min.js +38 -0
  4. package/config/default.json +5 -0
  5. package/config/enwiki.json +4 -814
  6. package/config/llwiki.json +5 -35
  7. package/config/minimum.json +3 -0
  8. package/config/moegirl.json +5 -44
  9. package/config/zhwiki.json +6 -466
  10. package/extensions/dist/base.js +64 -0
  11. package/extensions/dist/editor.js +159 -0
  12. package/extensions/dist/highlight.js +58 -0
  13. package/extensions/dist/lint.js +72 -0
  14. package/extensions/editor.css +64 -0
  15. package/extensions/ui.css +144 -0
  16. package/i18n/zh-hans.json +2 -1
  17. package/i18n/zh-hant.json +2 -1
  18. package/package.json +37 -21
  19. package/config/.schema.json +0 -172
  20. package/dist/addon/table.d.ts +0 -1
  21. package/dist/addon/table.js +0 -485
  22. package/dist/base.d.ts +0 -69
  23. package/dist/base.js +0 -38
  24. package/dist/index.d.ts +0 -31
  25. package/dist/index.js +0 -212
  26. package/dist/internal.d.ts +0 -44
  27. package/dist/lib/element.d.ts +0 -151
  28. package/dist/lib/element.js +0 -618
  29. package/dist/lib/node.d.ts +0 -146
  30. package/dist/lib/node.js +0 -426
  31. package/dist/lib/range.d.ts +0 -104
  32. package/dist/lib/range.js +0 -385
  33. package/dist/lib/ranges.d.ts +0 -28
  34. package/dist/lib/ranges.js +0 -126
  35. package/dist/lib/text.d.ts +0 -63
  36. package/dist/lib/text.js +0 -354
  37. package/dist/lib/title.d.ts +0 -40
  38. package/dist/lib/title.js +0 -179
  39. package/dist/mixin/attributesParent.d.ts +0 -50
  40. package/dist/mixin/attributesParent.js +0 -81
  41. package/dist/mixin/fixed.d.ts +0 -6
  42. package/dist/mixin/fixed.js +0 -30
  43. package/dist/mixin/flagsParent.d.ts +0 -72
  44. package/dist/mixin/flagsParent.js +0 -59
  45. package/dist/mixin/hidden.d.ts +0 -5
  46. package/dist/mixin/hidden.js +0 -24
  47. package/dist/mixin/magicLinkParent.d.ts +0 -40
  48. package/dist/mixin/magicLinkParent.js +0 -42
  49. package/dist/mixin/singleLine.d.ts +0 -6
  50. package/dist/mixin/singleLine.js +0 -26
  51. package/dist/mixin/sol.d.ts +0 -6
  52. package/dist/mixin/sol.js +0 -43
  53. package/dist/mixin/syntax.d.ts +0 -9
  54. package/dist/mixin/syntax.js +0 -50
  55. package/dist/parser/braces.js +0 -130
  56. package/dist/parser/commentAndExt.js +0 -89
  57. package/dist/parser/converter.js +0 -40
  58. package/dist/parser/externalLinks.js +0 -45
  59. package/dist/parser/hrAndDoubleUnderscore.js +0 -40
  60. package/dist/parser/html.js +0 -38
  61. package/dist/parser/links.js +0 -97
  62. package/dist/parser/list.js +0 -97
  63. package/dist/parser/magicLinks.js +0 -42
  64. package/dist/parser/quotes.js +0 -67
  65. package/dist/parser/selector.js +0 -190
  66. package/dist/parser/table.js +0 -123
  67. package/dist/src/arg.d.ts +0 -58
  68. package/dist/src/arg.js +0 -214
  69. package/dist/src/atom.d.ts +0 -12
  70. package/dist/src/atom.js +0 -27
  71. package/dist/src/attribute.d.ts +0 -71
  72. package/dist/src/attribute.js +0 -502
  73. package/dist/src/attributes.d.ts +0 -109
  74. package/dist/src/attributes.js +0 -356
  75. package/dist/src/converter.d.ts +0 -33
  76. package/dist/src/converter.js +0 -134
  77. package/dist/src/converterFlags.d.ts +0 -87
  78. package/dist/src/converterFlags.js +0 -242
  79. package/dist/src/converterRule.d.ts +0 -77
  80. package/dist/src/converterRule.js +0 -209
  81. package/dist/src/extLink.d.ts +0 -43
  82. package/dist/src/extLink.js +0 -191
  83. package/dist/src/gallery.d.ts +0 -54
  84. package/dist/src/gallery.js +0 -139
  85. package/dist/src/heading.d.ts +0 -47
  86. package/dist/src/heading.js +0 -190
  87. package/dist/src/hidden.d.ts +0 -7
  88. package/dist/src/hidden.js +0 -23
  89. package/dist/src/html.d.ts +0 -65
  90. package/dist/src/html.js +0 -358
  91. package/dist/src/imageParameter.d.ts +0 -65
  92. package/dist/src/imageParameter.js +0 -257
  93. package/dist/src/imagemap.d.ts +0 -54
  94. package/dist/src/imagemap.js +0 -144
  95. package/dist/src/imagemapLink.d.ts +0 -31
  96. package/dist/src/imagemapLink.js +0 -93
  97. package/dist/src/index.d.ts +0 -143
  98. package/dist/src/index.js +0 -851
  99. package/dist/src/link/base.d.ts +0 -52
  100. package/dist/src/link/base.js +0 -228
  101. package/dist/src/link/category.d.ts +0 -13
  102. package/dist/src/link/category.js +0 -28
  103. package/dist/src/link/file.d.ts +0 -98
  104. package/dist/src/link/file.js +0 -272
  105. package/dist/src/link/galleryImage.d.ts +0 -32
  106. package/dist/src/link/galleryImage.js +0 -158
  107. package/dist/src/link/index.d.ts +0 -56
  108. package/dist/src/link/index.js +0 -133
  109. package/dist/src/magicLink.d.ts +0 -59
  110. package/dist/src/magicLink.js +0 -223
  111. package/dist/src/nested.d.ts +0 -43
  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 -93
  115. package/dist/src/nowiki/comment.d.ts +0 -25
  116. package/dist/src/nowiki/comment.js +0 -76
  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 -18
  120. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  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 -16
  124. package/dist/src/nowiki/index.js +0 -27
  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 -23
  131. package/dist/src/nowiki/quote.d.ts +0 -14
  132. package/dist/src/nowiki/quote.js +0 -131
  133. package/dist/src/onlyinclude.d.ts +0 -16
  134. package/dist/src/onlyinclude.js +0 -57
  135. package/dist/src/paramTag/index.d.ts +0 -37
  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 -70
  140. package/dist/src/parameter.js +0 -264
  141. package/dist/src/pre.d.ts +0 -31
  142. package/dist/src/pre.js +0 -59
  143. package/dist/src/syntax.d.ts +0 -20
  144. package/dist/src/syntax.js +0 -86
  145. package/dist/src/table/base.d.ts +0 -27
  146. package/dist/src/table/base.js +0 -81
  147. package/dist/src/table/index.d.ts +0 -242
  148. package/dist/src/table/index.js +0 -497
  149. package/dist/src/table/td.d.ts +0 -86
  150. package/dist/src/table/td.js +0 -355
  151. package/dist/src/table/tr.d.ts +0 -32
  152. package/dist/src/table/tr.js +0 -58
  153. package/dist/src/table/trBase.d.ts +0 -53
  154. package/dist/src/table/trBase.js +0 -156
  155. package/dist/src/tagPair/ext.d.ts +0 -32
  156. package/dist/src/tagPair/ext.js +0 -203
  157. package/dist/src/tagPair/include.d.ts +0 -35
  158. package/dist/src/tagPair/include.js +0 -74
  159. package/dist/src/tagPair/index.d.ts +0 -27
  160. package/dist/src/tagPair/index.js +0 -128
  161. package/dist/src/transclude.d.ts +0 -167
  162. package/dist/src/transclude.js +0 -717
  163. package/dist/util/constants.js +0 -27
  164. package/dist/util/debug.js +0 -81
  165. package/dist/util/diff.js +0 -83
  166. package/dist/util/lint.js +0 -31
  167. package/dist/util/string.js +0 -60
  168. package/errors/README +0 -1
  169. package/printed/README +0 -1
@@ -1,89 +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 @typescript-eslint/no-unused-expressions */
54
- /<foo(?:\s[^>]*)?>|<\/foo\s*>/giu;
55
- /<(bar)(\s[^>]*?)?(?:\/>|>(.*?)<\/(\1\s*)>)/gisu;
56
- /<(baz)(\s[^>]*?)?(?:\/>|>(.*?)(?:<\/(baz\s*)>|$))/gisu;
57
- /* eslint-enable @typescript-eslint/no-unused-expressions */
58
- const ext = config.ext.join('|'), noincludeRegex = includeOnly ? 'includeonly' : '(?:no|only)include', includeRegex = includeOnly ? 'noinclude' : 'includeonly', regex = new RegExp('<!--.*?(?:-->|$)' // comment
59
- + '|'
60
- + `<${noincludeRegex}(?:\\s[^>]*)?>|</${noincludeRegex}\\s*>` // <noinclude>
61
- + '|'
62
- + `<(${ext})(\\s[^>]*?)?(?:/>|>(.*?)</(\\1\\s*)>)` // 扩展标签
63
- + '|'
64
- + `<(${includeRegex})(\\s[^>]*?)?(?:/>|>(.*?)(?:</(${includeRegex}\\s*)>|$))`, // <includeonly>
65
- 'gisu');
66
- return wikitext.replace(regex, (substr, name, attr, inner, closing, include, includeAttr, includeInner, includeClosing) => {
67
- const str = `\0${accum.length}${name ? 'e' : 'c'}\x7F`;
68
- if (name) {
69
- // @ts-expect-error abstract class
70
- new ext_1.ExtToken(name, attr, inner, closing, config, accum);
71
- }
72
- else if (substr.startsWith('<!--')) {
73
- const closed = substr.endsWith('-->');
74
- // @ts-expect-error abstract class
75
- new comment_1.CommentToken(substr.slice(4, closed ? -3 : undefined), closed, config, accum);
76
- }
77
- else if (include) {
78
- // @ts-expect-error abstract class
79
- new include_1.IncludeToken(include, includeAttr, includeInner, includeClosing, config, accum);
80
- }
81
- else {
82
- // @ts-expect-error abstract class
83
- new noinclude_1.NoincludeToken(substr, config, accum);
84
- }
85
- return str;
86
- });
87
- };
88
- exports.parseCommentAndExt = parseCommentAndExt;
89
- 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 converter_1 = require("../src/converter");
6
- /**
7
- * 解析语言变体转换
8
- * @param text
9
- * @param config
10
- * @param accum
11
- */
12
- const parseConverter = (text, config, accum) => {
13
- const regex1 = /-\{/gu, regex2 = /-\{|\}-/gu, stack = [];
14
- let regex = regex1, mt = regex.exec(text);
15
- while (mt) {
16
- const { 0: syntax, index } = mt;
17
- if (syntax === '}-') {
18
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
19
- /;(?=(?:[^;]*?=>)?\s*foo\s*:|(?:\s|\0\d+c\x7F)*$)/u;
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'), variants = `(?:${config.variants.join('|')})`, rules = temp.split(new RegExp(`;(?=(?:[^;]*?=>)?\\s*${variants}\\s*:|(?:\\s|\0\\d+c\x7F)*$)`, 'u'))
21
- .map(rule => rule.replace(/\x01/gu, ';'));
22
- // @ts-expect-error abstract class
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,45 +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
- /\[((?:\[[\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('\\[' // 左括号
19
- + `(${'\0\\d+f\x7F' // 预先解析的MagicLinkToken
20
- + '|'
21
- + `(?:(?:${config.protocol}|//)${string_1.extUrlCharFirst}|\0\\d+m\x7F)${string_1.extUrlChar}(?=[[\\]<>"\\t\\p{Zs}]|\0\\d)`})` // 链接网址
22
- + '(\\p{Zs}*(?=\\P{Zs}))' // 空格
23
- + '([^\\]\x01-\x08\x0A-\x1F\uFFFD]*)' // 链接文字
24
- + '\\]', // 右括号
25
- 'giu');
26
- return wikitext.replace(regex, (_, url, space, text) => {
27
- const { length } = accum;
28
- const mt = /&[lg]t;/u.exec(url);
29
- if (mt) {
30
- url = url.slice(0, mt.index);
31
- space = '';
32
- text = `${url.slice(mt.index)}${space}${text}`;
33
- }
34
- if (inFile) {
35
- // @ts-expect-error abstract class
36
- new magicLink_1.MagicLinkToken(url, true, config, accum);
37
- return `[\0${length}f\x7F${space}${text}]`;
38
- }
39
- // @ts-expect-error abstract class
40
- new extLink_1.ExtLinkToken(url, space, text, config, accum);
41
- return `\0${length}w\x7F`;
42
- });
43
- };
44
- exports.parseExternalLinks = parseExternalLinks;
45
- constants_1.parsers['parseExternalLinks'] = __filename;
@@ -1,40 +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
- data = data.replace(/^((?:\0\d+c\x7F)*)(-{4,})/gmu, (_, lead, m) => {
20
- // @ts-expect-error abstract class
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 caseSensitive = sensitive.has(p1);
25
- if (caseSensitive || insensitive.has(p1.toLowerCase())) {
26
- // @ts-expect-error abstract class
27
- new doubleUnderscore_1.DoubleUnderscoreToken(p1, caseSensitive, config, accum);
28
- return `\0${accum.length - 1}u\x7F`;
29
- }
30
- return m;
31
- }).replace(/^((?:\0\d+c\x7F)*)(={1,6})(.+)\2((?:[^\S\n]|\0\d+c\x7F)*)$/gmu, (_, lead, equals, heading, trail) => {
32
- const text = `${lead}\0${accum.length}h\x7F`;
33
- // @ts-expect-error abstract class
34
- new heading_1.HeadingToken(equals.length, [heading, trail], config, accum);
35
- return text;
36
- });
37
- return type === 'root' || type === 'ext-inner' && name === 'poem' ? data : data.slice(1);
38
- };
39
- exports.parseHrAndDoubleUnderscore = parseHrAndDoubleUnderscore;
40
- 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, elements = new Set(config.html.flat()), 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,97 +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
- 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('[[');
19
- let s = bits.shift();
20
- for (let i = 0; i < bits.length; i++) {
21
- let mightBeImg = false, link, delimiter, text, after;
22
- const x = bits[i], m = regex.exec(x);
23
- if (m) {
24
- [, link, delimiter, text, after] = m;
25
- if (after.startsWith(']') && text?.includes('[')) {
26
- text += ']';
27
- after = after.slice(1);
28
- }
29
- }
30
- else {
31
- const m2 = regexImg.exec(x);
32
- if (m2) {
33
- mightBeImg = true;
34
- [, link, delimiter, text] = m2;
35
- }
36
- }
37
- if (link === undefined || regexExt.test(link) || /\0\d+[exhbru]\x7F/u.test(link)) {
38
- s += `[[${x}`;
39
- continue;
40
- }
41
- const force = link.trim().startsWith(':');
42
- if (force && mightBeImg) {
43
- s += `[[${x}`;
44
- continue;
45
- }
46
- const title = index_1.default.normalizeTitle(link, 0, false, config, true, true, true), { ns, valid, interwiki } = title;
47
- if (!valid) {
48
- s += `[[${x}`;
49
- continue;
50
- }
51
- else if (mightBeImg) {
52
- if (interwiki || ns !== 6) {
53
- s += `[[${x}`;
54
- continue;
55
- }
56
- let found = false;
57
- for (i++; i < bits.length; i++) {
58
- const next = bits[i], p = next.split(']]');
59
- if (p.length > 2) {
60
- found = true;
61
- text += `[[${p[0]}]]${p[1]}`;
62
- after = p.slice(2).join(']]');
63
- break;
64
- }
65
- else if (p.length === 2) {
66
- text += `[[${p[0]}]]${p[1]}`;
67
- }
68
- else {
69
- text += `[[${next}`;
70
- break;
71
- }
72
- }
73
- text = (0, exports.parseLinks)(text, config, accum);
74
- if (!found) {
75
- s += `[[${link}${delimiter}${text}`;
76
- continue;
77
- }
78
- }
79
- text &&= (0, quotes_1.parseQuotes)(text, config, accum);
80
- let SomeLinkToken = index_2.LinkToken;
81
- if (!force) {
82
- if (!interwiki && ns === 6) {
83
- text &&= (0, externalLinks_1.parseExternalLinks)(text, config, accum, true);
84
- SomeLinkToken = file_1.FileToken;
85
- }
86
- else if (!interwiki && ns === 14) {
87
- SomeLinkToken = category_1.CategoryToken;
88
- }
89
- }
90
- s += `\0${accum.length}l\x7F${after}`;
91
- // @ts-expect-error abstract class
92
- new SomeLinkToken(link, text, config, accum, delimiter);
93
- }
94
- return s;
95
- };
96
- exports.parseLinks = parseLinks;
97
- 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,42 +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_])((?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])(?:[^[\]<>"\0\t\n\p{Zs}]|\0\d+c\x7F)*)/giu;
16
- const regex = new RegExp(`(^|[^\\p{L}\\d_])(?:${config.protocol})(${string_1.extUrlCharFirst}${string_1.extUrlChar})`, 'giu');
17
- return wikitext.replace(regex, (m, lead, p1) => {
18
- let trail = '', url = lead ? m.slice(lead.length) : m;
19
- const m2 = /&(?:lt|gt|nbsp|#x0*(?:3[ce]|a0)|#0*(?:6[02]|160));/iu.exec(url);
20
- if (m2) {
21
- trail = url.slice(m2.index);
22
- url = url.slice(0, m2.index);
23
- }
24
- const sep = new RegExp(`[,;\\\\.:!?${url.includes('(') ? '' : ')'}]+$`, 'u'), sepChars = sep.exec(url);
25
- if (sepChars) {
26
- let correction = 0;
27
- if (sepChars[0].startsWith(';') && /&(?:[a-z]+|#x[\da-f]+|#\d+)$/iu.test(url.slice(0, sepChars.index))) {
28
- correction = 1;
29
- }
30
- trail = `${url.slice(sepChars.index + correction)}${trail}`;
31
- url = url.slice(0, sepChars.index + correction);
32
- }
33
- if (trail.length >= p1.length) {
34
- return m;
35
- }
36
- // @ts-expect-error abstract class
37
- new magicLink_1.MagicLinkToken(url, false, config, accum);
38
- return `${lead}\0${accum.length - 1}w\x7F${trail}`;
39
- });
40
- };
41
- exports.parseMagicLinks = parseMagicLinks;
42
- 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;