wikiparser-node 1.8.0 → 1.9.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 (171) 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 +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/i18n/zh-hans.json +1 -0
  13. package/i18n/zh-hant.json +1 -0
  14. package/package.json +29 -19
  15. package/config/.schema.json +0 -181
  16. package/dist/addon/table.js +0 -485
  17. package/dist/addon/token.js +0 -237
  18. package/dist/addon/transclude.js +0 -183
  19. package/dist/base.d.ts +0 -71
  20. package/dist/base.js +0 -38
  21. package/dist/index.d.ts +0 -35
  22. package/dist/index.js +0 -211
  23. package/dist/internal.d.ts +0 -46
  24. package/dist/lib/element.d.ts +0 -140
  25. package/dist/lib/element.js +0 -597
  26. package/dist/lib/node.d.ts +0 -166
  27. package/dist/lib/node.js +0 -480
  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/text.d.ts +0 -63
  33. package/dist/lib/text.js +0 -355
  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 -81
  38. package/dist/mixin/fixed.d.ts +0 -5
  39. package/dist/mixin/fixed.js +0 -30
  40. package/dist/mixin/flagsParent.d.ts +0 -41
  41. package/dist/mixin/flagsParent.js +0 -59
  42. package/dist/mixin/hidden.d.ts +0 -4
  43. package/dist/mixin/hidden.js +0 -24
  44. package/dist/mixin/magicLinkParent.d.ts +0 -19
  45. package/dist/mixin/magicLinkParent.js +0 -42
  46. package/dist/mixin/singleLine.d.ts +0 -5
  47. package/dist/mixin/singleLine.js +0 -26
  48. package/dist/mixin/sol.d.ts +0 -5
  49. package/dist/mixin/sol.js +0 -43
  50. package/dist/mixin/syntax.d.ts +0 -8
  51. package/dist/mixin/syntax.js +0 -50
  52. package/dist/parser/braces.js +0 -130
  53. package/dist/parser/commentAndExt.js +0 -89
  54. package/dist/parser/converter.js +0 -40
  55. package/dist/parser/externalLinks.js +0 -44
  56. package/dist/parser/hrAndDoubleUnderscore.js +0 -40
  57. package/dist/parser/html.js +0 -38
  58. package/dist/parser/links.js +0 -99
  59. package/dist/parser/list.js +0 -97
  60. package/dist/parser/magicLinks.js +0 -42
  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 -58
  66. package/dist/src/arg.js +0 -214
  67. package/dist/src/atom.d.ts +0 -12
  68. package/dist/src/atom.js +0 -27
  69. package/dist/src/attribute.d.ts +0 -71
  70. package/dist/src/attribute.js +0 -502
  71. package/dist/src/attributes.d.ts +0 -109
  72. package/dist/src/attributes.js +0 -356
  73. package/dist/src/converter.d.ts +0 -33
  74. package/dist/src/converter.js +0 -134
  75. package/dist/src/converterFlags.d.ts +0 -87
  76. package/dist/src/converterFlags.js +0 -242
  77. package/dist/src/converterRule.d.ts +0 -77
  78. package/dist/src/converterRule.js +0 -209
  79. package/dist/src/extLink.d.ts +0 -43
  80. package/dist/src/extLink.js +0 -191
  81. package/dist/src/gallery.d.ts +0 -54
  82. package/dist/src/gallery.js +0 -139
  83. package/dist/src/heading.d.ts +0 -47
  84. package/dist/src/heading.js +0 -190
  85. package/dist/src/hidden.d.ts +0 -7
  86. package/dist/src/hidden.js +0 -23
  87. package/dist/src/html.d.ts +0 -65
  88. package/dist/src/html.js +0 -358
  89. package/dist/src/imageParameter.d.ts +0 -65
  90. package/dist/src/imageParameter.js +0 -257
  91. package/dist/src/imagemap.d.ts +0 -54
  92. package/dist/src/imagemap.js +0 -144
  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 -142
  96. package/dist/src/index.js +0 -701
  97. package/dist/src/link/base.d.ts +0 -52
  98. package/dist/src/link/base.js +0 -228
  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 -98
  102. package/dist/src/link/file.js +0 -272
  103. package/dist/src/link/galleryImage.d.ts +0 -32
  104. package/dist/src/link/galleryImage.js +0 -158
  105. package/dist/src/link/index.d.ts +0 -56
  106. package/dist/src/link/index.js +0 -133
  107. package/dist/src/link/redirectTarget.d.ts +0 -51
  108. package/dist/src/link/redirectTarget.js +0 -101
  109. package/dist/src/magicLink.d.ts +0 -59
  110. package/dist/src/magicLink.js +0 -220
  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 -19
  132. package/dist/src/nowiki/quote.js +0 -137
  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/redirect.d.ts +0 -34
  144. package/dist/src/redirect.js +0 -119
  145. package/dist/src/syntax.d.ts +0 -19
  146. package/dist/src/syntax.js +0 -86
  147. package/dist/src/table/base.d.ts +0 -27
  148. package/dist/src/table/base.js +0 -81
  149. package/dist/src/table/index.d.ts +0 -242
  150. package/dist/src/table/index.js +0 -498
  151. package/dist/src/table/td.d.ts +0 -86
  152. package/dist/src/table/td.js +0 -355
  153. package/dist/src/table/tr.d.ts +0 -32
  154. package/dist/src/table/tr.js +0 -58
  155. package/dist/src/table/trBase.d.ts +0 -53
  156. package/dist/src/table/trBase.js +0 -156
  157. package/dist/src/tagPair/ext.d.ts +0 -32
  158. package/dist/src/tagPair/ext.js +0 -203
  159. package/dist/src/tagPair/include.d.ts +0 -35
  160. package/dist/src/tagPair/include.js +0 -74
  161. package/dist/src/tagPair/index.d.ts +0 -27
  162. package/dist/src/tagPair/index.js +0 -128
  163. package/dist/src/transclude.d.ts +0 -166
  164. package/dist/src/transclude.js +0 -584
  165. package/dist/util/constants.js +0 -27
  166. package/dist/util/debug.js +0 -81
  167. package/dist/util/diff.js +0 -83
  168. package/dist/util/lint.js +0 -31
  169. package/dist/util/string.js +0 -60
  170. package/errors/README +0 -1
  171. 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,44 +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, mt = /&[lg]t;/u.exec(url);
28
- if (mt) {
29
- url = url.slice(0, mt.index);
30
- space = '';
31
- text = url.slice(mt.index) + space + text;
32
- }
33
- if (inFile) {
34
- // @ts-expect-error abstract class
35
- new magicLink_1.MagicLinkToken(url, true, config, accum);
36
- return `[\0${length}f\x7F${space}${text}]`;
37
- }
38
- // @ts-expect-error abstract class
39
- new extLink_1.ExtLinkToken(url, space, text, config, accum);
40
- return `\0${length}w\x7F`;
41
- });
42
- };
43
- exports.parseExternalLinks = parseExternalLinks;
44
- 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,99 +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 = true // eslint-disable-line no-constant-condition, @typescript-eslint/no-unnecessary-condition
19
- ? /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(?:(\||\0\d+!\x7F)(.*?[^\]]))?\]\](.*)$/su
20
- : /^((?:(?!\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('[[');
21
- let s = bits.shift();
22
- for (let i = 0; i < bits.length; i++) {
23
- let mightBeImg = false, link, delimiter, text, after;
24
- const x = bits[i], m = regex.exec(x);
25
- if (m) {
26
- [, link, delimiter, text, after] = m;
27
- if (after.startsWith(']') && text?.includes('[')) {
28
- text += ']';
29
- after = after.slice(1);
30
- }
31
- }
32
- else {
33
- const m2 = regexImg.exec(x);
34
- if (m2) {
35
- mightBeImg = true;
36
- [, link, delimiter, text] = m2;
37
- }
38
- }
39
- if (link === undefined || regexExt.test(link) || /\0\d+[exhbru]\x7F/u.test(link)) {
40
- s += `[[${x}`;
41
- continue;
42
- }
43
- const force = link.trim().startsWith(':');
44
- if (force && mightBeImg) {
45
- s += `[[${x}`;
46
- continue;
47
- }
48
- const title = index_1.default.normalizeTitle(link, 0, false, config, true, true, true), { ns, valid, interwiki } = title;
49
- if (!valid) {
50
- s += `[[${x}`;
51
- continue;
52
- }
53
- else if (mightBeImg) {
54
- if (interwiki || ns !== 6) {
55
- s += `[[${x}`;
56
- continue;
57
- }
58
- let found = false;
59
- for (i++; i < bits.length; i++) {
60
- const next = bits[i], p = next.split(']]');
61
- if (p.length > 2) {
62
- found = true;
63
- text += `[[${p[0]}]]${p[1]}`;
64
- after = p.slice(2).join(']]');
65
- break;
66
- }
67
- else if (p.length === 2) {
68
- text += `[[${p[0]}]]${p[1]}`;
69
- }
70
- else {
71
- text += `[[${next}`;
72
- break;
73
- }
74
- }
75
- text = (0, exports.parseLinks)(text, config, accum);
76
- if (!found) {
77
- s += `[[${link}${delimiter}${text}`;
78
- continue;
79
- }
80
- }
81
- text &&= (0, quotes_1.parseQuotes)(text, config, accum);
82
- let SomeLinkToken = index_2.LinkToken;
83
- if (!force) {
84
- if (!interwiki && ns === 6) {
85
- text &&= (0, externalLinks_1.parseExternalLinks)(text, config, accum, true);
86
- SomeLinkToken = file_1.FileToken;
87
- }
88
- else if (!interwiki && ns === 14) {
89
- SomeLinkToken = category_1.CategoryToken;
90
- }
91
- }
92
- s += `\0${accum.length}l\x7F${after}`;
93
- // @ts-expect-error abstract class
94
- new SomeLinkToken(link, text, config, accum, delimiter);
95
- }
96
- return s;
97
- };
98
- exports.parseLinks = parseLinks;
99
- 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;
@@ -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(`^(\\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;