wikiparser-node 1.4.3 → 1.4.4-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 (166) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/bundle/bundle.min.js +36 -0
  4. package/config/enwiki.json +1 -814
  5. package/config/llwiki.json +1 -35
  6. package/config/moegirl.json +1 -44
  7. package/config/zhwiki.json +1 -466
  8. package/extensions/dist/base.js +64 -0
  9. package/extensions/dist/editor.js +159 -0
  10. package/extensions/dist/highlight.js +59 -0
  11. package/extensions/dist/lint.js +48 -0
  12. package/extensions/editor.css +63 -0
  13. package/extensions/ui.css +141 -0
  14. package/i18n/zh-hans.json +1 -0
  15. package/i18n/zh-hant.json +1 -0
  16. package/package.json +28 -15
  17. package/config/.schema.json +0 -172
  18. package/dist/addon/table.d.ts +0 -6
  19. package/dist/addon/table.js +0 -564
  20. package/dist/base.d.ts +0 -58
  21. package/dist/index.d.ts +0 -30
  22. package/dist/index.js +0 -211
  23. package/dist/internal.d.ts +0 -44
  24. package/dist/lib/element.d.ts +0 -155
  25. package/dist/lib/element.js +0 -650
  26. package/dist/lib/node.d.ts +0 -146
  27. package/dist/lib/node.js +0 -428
  28. package/dist/lib/range.d.ts +0 -104
  29. package/dist/lib/range.js +0 -385
  30. package/dist/lib/ranges.d.ts +0 -26
  31. package/dist/lib/ranges.js +0 -118
  32. package/dist/lib/text.d.ts +0 -62
  33. package/dist/lib/text.js +0 -306
  34. package/dist/lib/title.d.ts +0 -38
  35. package/dist/lib/title.js +0 -164
  36. package/dist/mixin/attributesParent.d.ts +0 -50
  37. package/dist/mixin/attributesParent.js +0 -78
  38. package/dist/mixin/fixed.d.ts +0 -6
  39. package/dist/mixin/fixed.js +0 -30
  40. package/dist/mixin/flagsParent.d.ts +0 -72
  41. package/dist/mixin/flagsParent.js +0 -59
  42. package/dist/mixin/hidden.d.ts +0 -5
  43. package/dist/mixin/hidden.js +0 -24
  44. package/dist/mixin/magicLinkParent.d.ts +0 -40
  45. package/dist/mixin/magicLinkParent.js +0 -42
  46. package/dist/mixin/singleLine.d.ts +0 -6
  47. package/dist/mixin/singleLine.js +0 -26
  48. package/dist/mixin/sol.d.ts +0 -6
  49. package/dist/mixin/sol.js +0 -43
  50. package/dist/mixin/syntax.d.ts +0 -9
  51. package/dist/mixin/syntax.js +0 -50
  52. package/dist/parser/braces.js +0 -131
  53. package/dist/parser/commentAndExt.js +0 -90
  54. package/dist/parser/converter.js +0 -41
  55. package/dist/parser/externalLinks.js +0 -32
  56. package/dist/parser/hrAndDoubleUnderscore.js +0 -41
  57. package/dist/parser/html.js +0 -39
  58. package/dist/parser/links.js +0 -95
  59. package/dist/parser/list.js +0 -68
  60. package/dist/parser/magicLinks.js +0 -43
  61. package/dist/parser/quotes.js +0 -68
  62. package/dist/parser/selector.js +0 -162
  63. package/dist/parser/table.js +0 -124
  64. package/dist/src/arg.d.ts +0 -58
  65. package/dist/src/arg.js +0 -196
  66. package/dist/src/atom.d.ts +0 -12
  67. package/dist/src/atom.js +0 -27
  68. package/dist/src/attribute.d.ts +0 -69
  69. package/dist/src/attribute.js +0 -475
  70. package/dist/src/attributes.d.ts +0 -109
  71. package/dist/src/attributes.js +0 -346
  72. package/dist/src/converter.d.ts +0 -33
  73. package/dist/src/converter.js +0 -134
  74. package/dist/src/converterFlags.d.ts +0 -87
  75. package/dist/src/converterFlags.js +0 -226
  76. package/dist/src/converterRule.d.ts +0 -77
  77. package/dist/src/converterRule.js +0 -209
  78. package/dist/src/extLink.d.ts +0 -43
  79. package/dist/src/extLink.js +0 -186
  80. package/dist/src/gallery.d.ts +0 -54
  81. package/dist/src/gallery.js +0 -126
  82. package/dist/src/heading.d.ts +0 -47
  83. package/dist/src/heading.js +0 -190
  84. package/dist/src/hidden.d.ts +0 -7
  85. package/dist/src/hidden.js +0 -23
  86. package/dist/src/html.d.ts +0 -65
  87. package/dist/src/html.js +0 -335
  88. package/dist/src/imageParameter.d.ts +0 -65
  89. package/dist/src/imageParameter.js +0 -248
  90. package/dist/src/imagemap.d.ts +0 -56
  91. package/dist/src/imagemap.js +0 -150
  92. package/dist/src/imagemapLink.d.ts +0 -31
  93. package/dist/src/imagemapLink.js +0 -93
  94. package/dist/src/index.d.ts +0 -143
  95. package/dist/src/index.js +0 -803
  96. package/dist/src/link/base.d.ts +0 -52
  97. package/dist/src/link/base.js +0 -209
  98. package/dist/src/link/category.d.ts +0 -13
  99. package/dist/src/link/category.js +0 -28
  100. package/dist/src/link/file.d.ts +0 -96
  101. package/dist/src/link/file.js +0 -265
  102. package/dist/src/link/galleryImage.d.ts +0 -32
  103. package/dist/src/link/galleryImage.js +0 -157
  104. package/dist/src/link/index.d.ts +0 -56
  105. package/dist/src/link/index.js +0 -133
  106. package/dist/src/magicLink.d.ts +0 -59
  107. package/dist/src/magicLink.js +0 -199
  108. package/dist/src/nested.d.ts +0 -43
  109. package/dist/src/nested.js +0 -92
  110. package/dist/src/nowiki/base.d.ts +0 -31
  111. package/dist/src/nowiki/base.js +0 -93
  112. package/dist/src/nowiki/comment.d.ts +0 -25
  113. package/dist/src/nowiki/comment.js +0 -68
  114. package/dist/src/nowiki/dd.d.ts +0 -8
  115. package/dist/src/nowiki/dd.js +0 -24
  116. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -18
  117. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  118. package/dist/src/nowiki/hr.d.ts +0 -5
  119. package/dist/src/nowiki/hr.js +0 -63
  120. package/dist/src/nowiki/index.d.ts +0 -16
  121. package/dist/src/nowiki/index.js +0 -21
  122. package/dist/src/nowiki/list.d.ts +0 -16
  123. package/dist/src/nowiki/list.js +0 -97
  124. package/dist/src/nowiki/listBase.d.ts +0 -5
  125. package/dist/src/nowiki/listBase.js +0 -61
  126. package/dist/src/nowiki/noinclude.d.ts +0 -10
  127. package/dist/src/nowiki/noinclude.js +0 -23
  128. package/dist/src/nowiki/quote.d.ts +0 -14
  129. package/dist/src/nowiki/quote.js +0 -116
  130. package/dist/src/onlyinclude.d.ts +0 -16
  131. package/dist/src/onlyinclude.js +0 -57
  132. package/dist/src/paramTag/index.d.ts +0 -37
  133. package/dist/src/paramTag/index.js +0 -69
  134. package/dist/src/paramTag/inputbox.d.ts +0 -8
  135. package/dist/src/paramTag/inputbox.js +0 -22
  136. package/dist/src/parameter.d.ts +0 -70
  137. package/dist/src/parameter.js +0 -262
  138. package/dist/src/pre.d.ts +0 -28
  139. package/dist/src/pre.js +0 -55
  140. package/dist/src/syntax.d.ts +0 -20
  141. package/dist/src/syntax.js +0 -86
  142. package/dist/src/table/base.d.ts +0 -30
  143. package/dist/src/table/base.js +0 -132
  144. package/dist/src/table/index.d.ts +0 -233
  145. package/dist/src/table/index.js +0 -386
  146. package/dist/src/table/td.d.ts +0 -92
  147. package/dist/src/table/td.js +0 -337
  148. package/dist/src/table/tr.d.ts +0 -32
  149. package/dist/src/table/tr.js +0 -58
  150. package/dist/src/table/trBase.d.ts +0 -53
  151. package/dist/src/table/trBase.js +0 -154
  152. package/dist/src/tagPair/ext.d.ts +0 -32
  153. package/dist/src/tagPair/ext.js +0 -203
  154. package/dist/src/tagPair/include.d.ts +0 -35
  155. package/dist/src/tagPair/include.js +0 -63
  156. package/dist/src/tagPair/index.d.ts +0 -27
  157. package/dist/src/tagPair/index.js +0 -128
  158. package/dist/src/transclude.d.ts +0 -167
  159. package/dist/src/transclude.js +0 -710
  160. package/dist/util/constants.js +0 -113
  161. package/dist/util/debug.js +0 -88
  162. package/dist/util/diff.js +0 -82
  163. package/dist/util/lint.js +0 -30
  164. package/dist/util/string.js +0 -53
  165. package/errors/README +0 -1
  166. package/printed/README +0 -1
@@ -1,32 +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 index_1 = require("../index");
7
- const extLink_1 = require("../src/extLink");
8
- /**
9
- * 解析外部链接
10
- * @param wikitext
11
- * @param config
12
- * @param accum
13
- */
14
- const parseExternalLinks = (wikitext, config = index_1.default.getConfig(), accum = []) => {
15
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
16
- /\[((?:\[[\da-f:.]+\]|[^[\]\t\n\p{Zs}])[^[\]\t\n\p{Zs}]*(?=[[\]\t\p{Zs}]|\0\d))(\p{Zs}*(?=\P{Zs}))([^\]\n]*)\]/giu;
17
- const regex = new RegExp(`\\[((?:(?:${config.protocol}|//)${string_1.extUrlCharFirst}|\0\\d+m\x7F)${string_1.extUrlChar}(?=[[\\]<>"\\t\\p{Zs}]|\0\\d))`
18
- + '(\\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
- // @ts-expect-error abstract class
27
- new extLink_1.ExtLinkToken(url, space, text, config, accum);
28
- return `\0${length}w\x7F`;
29
- });
30
- };
31
- exports.parseExternalLinks = parseExternalLinks;
32
- constants_1.parsers['parseExternalLinks'] = __filename;
@@ -1,41 +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 index_1 = require("../index");
6
- const hr_1 = require("../src/nowiki/hr");
7
- const doubleUnderscore_1 = require("../src/nowiki/doubleUnderscore");
8
- const heading_1 = require("../src/heading");
9
- /**
10
- * 解析`<hr>`和状态开关
11
- * @param {Token} root 根节点
12
- * @param config
13
- * @param accum
14
- */
15
- const parseHrAndDoubleUnderscore = ({ firstChild: { data }, type, name }, config = index_1.default.getConfig(), accum = []) => {
16
- const { doubleUnderscore } = config, insensitive = new Set(doubleUnderscore[0]), sensitive = new Set(doubleUnderscore[1]);
17
- if (type !== 'root' && (type !== 'ext-inner' || name !== 'poem')) {
18
- data = `\0${data}`;
19
- }
20
- data = data.replace(/^((?:\0\d+c\x7F)*)(-{4,})/gmu, (_, lead, m) => {
21
- // @ts-expect-error abstract class
22
- new hr_1.HrToken(m, config, accum);
23
- return `${lead}\0${accum.length - 1}r\x7F`;
24
- }).replace(new RegExp(`__(${doubleUnderscore.flat().join('|')})__`, 'giu'), (m, p1) => {
25
- const caseSensitive = sensitive.has(p1);
26
- if (caseSensitive || insensitive.has(p1.toLowerCase())) {
27
- // @ts-expect-error abstract class
28
- new doubleUnderscore_1.DoubleUnderscoreToken(p1, caseSensitive, config, accum);
29
- return `\0${accum.length - 1}u\x7F`;
30
- }
31
- return m;
32
- }).replace(/^((?:\0\d+c\x7F)*)(={1,6})(.+)\2((?:[^\S\n]|\0\d+c\x7F)*)$/gmu, (_, lead, equals, heading, trail) => {
33
- const text = `${lead}\0${accum.length}h\x7F`;
34
- // @ts-expect-error abstract class
35
- new heading_1.HeadingToken(equals.length, [heading, trail], config, accum);
36
- return text;
37
- });
38
- return type === 'root' || type === 'ext-inner' && name === 'poem' ? data : data.slice(1);
39
- };
40
- exports.parseHrAndDoubleUnderscore = parseHrAndDoubleUnderscore;
41
- constants_1.parsers['parseHrAndDoubleUnderscore'] = __filename;
@@ -1,39 +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 index_1 = require("../index");
6
- const attributes_1 = require("../src/attributes");
7
- const html_1 = require("../src/html");
8
- /**
9
- * 解析HTML标签
10
- * @param wikitext
11
- * @param config
12
- * @param accum
13
- */
14
- const parseHtml = (wikitext, config = index_1.default.getConfig(), accum = []) => {
15
- const regex = /^(\/?)([a-z][^\s/>]*)((?:\s|\/(?!>))[^>]*?)?(\/?>)([^<]*)$/iu, elements = new Set(config.html.flat()), bits = wikitext.split('<');
16
- let text = bits.shift();
17
- for (const x of bits) {
18
- const mt = regex.exec(x), t = mt?.[2], name = t?.toLowerCase();
19
- if (!mt || !elements.has(name)) {
20
- text += `<${x}`;
21
- continue;
22
- }
23
- const [, slash, , params = '', brace, rest] = mt,
24
- // @ts-expect-error abstract class
25
- attr = new attributes_1.AttributesToken(params, 'html-attrs', name, config, accum), itemprop = attr.getAttr('itemprop');
26
- if (name === 'meta' && (itemprop === undefined || attr.getAttr('content') === undefined)
27
- || name === 'link' && (itemprop === undefined || attr.getAttr('href') === undefined)) {
28
- text += `<${x}`;
29
- accum.pop();
30
- continue;
31
- }
32
- text += `\0${accum.length}x\x7F${rest}`;
33
- // @ts-expect-error abstract class
34
- new html_1.HtmlToken(t, attr, slash === '/', brace === '/>', config, accum);
35
- }
36
- return text;
37
- };
38
- exports.parseHtml = parseHtml;
39
- constants_1.parsers['parseHtml'] = __filename;
@@ -1,95 +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 index_2 = require("../src/link/index");
7
- const file_1 = require("../src/link/file");
8
- const category_1 = require("../src/link/category");
9
- /**
10
- * 解析内部链接
11
- * @param wikitext
12
- * @param config
13
- * @param accum
14
- */
15
- const parseLinks = (wikitext, config = index_1.default.getConfig(), accum = []) => {
16
- const { parseQuotes } = require('./quotes');
17
- 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('[[');
18
- let s = bits.shift();
19
- for (let i = 0; i < bits.length; i++) {
20
- let mightBeImg = false, link, delimiter, text, after;
21
- const x = bits[i], m = regex.exec(x);
22
- if (m) {
23
- [, link, delimiter, text, after] = m;
24
- if (after.startsWith(']') && text?.includes('[')) {
25
- text += ']';
26
- after = after.slice(1);
27
- }
28
- }
29
- else {
30
- const m2 = regexImg.exec(x);
31
- if (m2) {
32
- mightBeImg = true;
33
- [, link, delimiter, text] = m2;
34
- }
35
- }
36
- if (link === undefined || regexExt.test(link) || /\0\d+[exhbru]\x7F/u.test(link)) {
37
- s += `[[${x}`;
38
- continue;
39
- }
40
- const force = link.trim().startsWith(':');
41
- if (force && mightBeImg) {
42
- s += `[[${x}`;
43
- continue;
44
- }
45
- const title = index_1.default.normalizeTitle(link, 0, false, config, true, true, true), { ns, valid, interwiki } = title;
46
- if (!valid) {
47
- s += `[[${x}`;
48
- continue;
49
- }
50
- else if (mightBeImg) {
51
- if (interwiki || ns !== 6) {
52
- s += `[[${x}`;
53
- continue;
54
- }
55
- let found = false;
56
- for (i++; i < bits.length; i++) {
57
- const next = bits[i], p = next.split(']]');
58
- if (p.length > 2) {
59
- found = true;
60
- text += `[[${p[0]}]]${p[1]}`;
61
- after = p.slice(2).join(']]');
62
- break;
63
- }
64
- else if (p.length === 2) {
65
- text += `[[${p[0]}]]${p[1]}`;
66
- }
67
- else {
68
- text += `[[${next}`;
69
- break;
70
- }
71
- }
72
- text = (0, exports.parseLinks)(text, config, accum);
73
- if (!found) {
74
- s += `[[${link}${delimiter}${text}`;
75
- continue;
76
- }
77
- }
78
- text &&= parseQuotes(text, config, accum);
79
- s += `\0${accum.length}l\x7F${after}`;
80
- let SomeLinkToken = index_2.LinkToken;
81
- if (!force) {
82
- if (!interwiki && ns === 6) {
83
- SomeLinkToken = file_1.FileToken;
84
- }
85
- else if (!interwiki && ns === 14) {
86
- SomeLinkToken = category_1.CategoryToken;
87
- }
88
- }
89
- // @ts-expect-error abstract class
90
- new SomeLinkToken(link, text, config, accum, delimiter);
91
- }
92
- return s;
93
- };
94
- exports.parseLinks = parseLinks;
95
- constants_1.parsers['parseLinks'] = __filename;
@@ -1,68 +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 index_1 = require("../index");
6
- const list_1 = require("../src/nowiki/list");
7
- const dd_1 = require("../src/nowiki/dd");
8
- /**
9
- * 解析列表
10
- * @param wikitext
11
- * @param config
12
- * @param accum
13
- */
14
- const parseList = (wikitext, config = index_1.default.getConfig(), accum = []) => {
15
- const mt = /^((?:\0\d+c\x7F)*)([;:*#]+)/u.exec(wikitext);
16
- if (!mt) {
17
- return wikitext;
18
- }
19
- const [total, comment, prefix] = mt;
20
- let text = `${comment}\0${accum.length}d\x7F${wikitext.slice(total.length)}`, dt = prefix.split(';').length - 1;
21
- // @ts-expect-error abstract class
22
- new list_1.ListToken(prefix, config, accum);
23
- if (!dt) {
24
- return text;
25
- }
26
- let regex = /:+|-\{/gu, ex = regex.exec(text), 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
- while (ex && dt) {
38
- const { 0: syntax, index } = ex;
39
- if (syntax.startsWith(':')) {
40
- if (syntax.length >= dt) {
41
- return dd(syntax.slice(0, dt), index);
42
- }
43
- dt -= syntax.length;
44
- regex.lastIndex = index + 4 + String(accum.length).length;
45
- text = dd(syntax, index);
46
- }
47
- else if (syntax === '-{') {
48
- if (!lc) {
49
- const { lastIndex } = regex;
50
- regex = /-\{|\}-/gu;
51
- regex.lastIndex = lastIndex;
52
- }
53
- lc++;
54
- }
55
- else {
56
- lc--;
57
- if (!lc) {
58
- const { lastIndex } = regex;
59
- regex = /:+|-\{/gu;
60
- regex.lastIndex = lastIndex;
61
- }
62
- }
63
- ex = regex.exec(text);
64
- }
65
- return text;
66
- };
67
- exports.parseList = parseList;
68
- constants_1.parsers['parseList'] = __filename;
@@ -1,43 +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 index_1 = require("../index");
7
- const magicLink_1 = require("../src/magicLink");
8
- /**
9
- * 解析自由外链
10
- * @param wikitext
11
- * @param config
12
- * @param accum
13
- */
14
- const parseMagicLinks = (wikitext, config = index_1.default.getConfig(), accum = []) => {
15
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
16
- /(^|[^\p{L}\d_])((?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])(?:[^[\]<>"\0\t\n\p{Zs}]|\0\d+c\x7F)*)/giu;
17
- const regex = new RegExp(`(^|[^\\p{L}\\d_])(?:${config.protocol})(${string_1.extUrlCharFirst}${string_1.extUrlChar})`, 'giu');
18
- return wikitext.replace(regex, (m, lead, p1) => {
19
- let trail = '', url = lead ? m.slice(1) : m;
20
- const m2 = /&(?:lt|gt|nbsp|#x0*(?:3[ce]|a0)|#0*(?:6[02]|160));/iu.exec(url);
21
- if (m2) {
22
- trail = url.slice(m2.index);
23
- url = url.slice(0, m2.index);
24
- }
25
- const sep = new RegExp(`[,;.:!?${url.includes('(') ? '' : ')'}]+$`, 'u'), sepChars = sep.exec(url);
26
- if (sepChars) {
27
- let correction = 0;
28
- if (sepChars[0].startsWith(';') && /&(?:[a-z]+|#x[\da-f]+|#\d+)$/iu.test(url.slice(0, sepChars.index))) {
29
- correction = 1;
30
- }
31
- trail = `${url.slice(sepChars.index + correction)}${trail}`;
32
- url = url.slice(0, sepChars.index + correction);
33
- }
34
- if (trail.length >= p1.length) {
35
- return m;
36
- }
37
- // @ts-expect-error abstract class
38
- new magicLink_1.MagicLinkToken(url, false, config, accum);
39
- return `${lead}\0${accum.length - 1}w\x7F${trail}`;
40
- });
41
- };
42
- exports.parseMagicLinks = parseMagicLinks;
43
- constants_1.parsers['parseMagicLinks'] = __filename;
@@ -1,68 +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 index_1 = require("../index");
6
- const quote_1 = require("../src/nowiki/quote");
7
- /**
8
- * 解析单引号
9
- * @param wikitext
10
- * @param config
11
- * @param accum
12
- */
13
- const parseQuotes = (wikitext, config = index_1.default.getConfig(), accum = []) => {
14
- const arr = wikitext.split(/('{2,})/u), { length } = arr;
15
- if (length === 1) {
16
- return wikitext;
17
- }
18
- let nBold = 0, nItalic = 0, firstSingle, firstMulti, firstSpace;
19
- for (let i = 1; i < length; i += 2) {
20
- const len = arr[i].length;
21
- switch (len) {
22
- case 2:
23
- nItalic++;
24
- break;
25
- case 4:
26
- arr[i - 1] += `'`;
27
- arr[i] = `'''`;
28
- // fall through
29
- case 3:
30
- nBold++;
31
- if (firstSingle !== undefined) {
32
- break;
33
- }
34
- else if (arr[i - 1].endsWith(' ')) {
35
- if (firstMulti === undefined && firstSpace === undefined) {
36
- firstSpace = i;
37
- }
38
- }
39
- else if (arr[i - 1].slice(-2, -1) === ' ') {
40
- firstSingle = i;
41
- }
42
- else {
43
- firstMulti ??= i;
44
- }
45
- break;
46
- default:
47
- arr[i - 1] += `'`.repeat(len - 5);
48
- arr[i] = `'''''`;
49
- nItalic++;
50
- nBold++;
51
- }
52
- }
53
- if (nItalic % 2 === 1 && nBold % 2 === 1) {
54
- const i = firstSingle ?? firstMulti ?? firstSpace;
55
- if (i !== undefined) {
56
- arr[i] = `''`;
57
- arr[i - 1] += `'`;
58
- }
59
- }
60
- for (let i = 1; i < length; i += 2) {
61
- // @ts-expect-error abstract class
62
- new quote_1.QuoteToken(arr[i], config, accum);
63
- arr[i] = `\0${accum.length - 1}q\x7F`;
64
- }
65
- return arr.join('');
66
- };
67
- exports.parseQuotes = parseQuotes;
68
- constants_1.parsers['parseQuotes'] = __filename;
@@ -1,162 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseSelector = void 0;
4
- const constants_1 = require("../util/constants");
5
- const string_1 = require("../util/string");
6
- const index_1 = require("../index");
7
- const simplePseudos = new Set([
8
- 'root',
9
- 'first-child',
10
- 'first-of-type',
11
- 'last-child',
12
- 'last-of-type',
13
- 'only-child',
14
- 'only-of-type',
15
- 'empty',
16
- 'parent',
17
- 'header',
18
- 'hidden',
19
- 'visible',
20
- 'only-whitespace',
21
- 'any-link',
22
- 'local-link',
23
- 'invalid',
24
- 'required',
25
- 'optional',
26
- ]);
27
- const complexPseudos = [
28
- 'is',
29
- 'not',
30
- 'nth-child',
31
- 'nth-of-type',
32
- 'nth-last-child',
33
- 'nth-last-of-type',
34
- 'contains',
35
- 'has',
36
- 'lang',
37
- 'regex',
38
- ];
39
- const specialChars = [
40
- ['[', '&lbrack;'],
41
- [']', '&rbrack;'],
42
- ['(', '&lpar;'],
43
- [')', '&rpar;'],
44
- ['"', '&quot;'],
45
- [`'`, '&apos;'],
46
- [':', '&colon;'],
47
- ['\\', '&bsol;'],
48
- ['&', '&amp;'],
49
- ];
50
- const pseudoRegex = new RegExp(`:(${complexPseudos.join('|')})$`, 'u'), regularRegex = /[[(,>+~]|\s+/u, attributeRegex = /^\s*(\w+)\s*(?:([~|^$*!]?=)\s*("[^"]*"|'[^']*'|[^\s[\]]+)(?:\s+(i))?\s*)?\]/u, functionRegex = /^(\s*"[^"]*"\s*|\s*'[^']*'\s*|[^()]*)\)/u, grouping = new Set([',', '>', '+', '~']), combinator = new Set(['>', '+', '~', '']);
51
- /**
52
- * 清理转义符号
53
- * @param selector
54
- */
55
- const sanitize = (selector) => {
56
- for (const [c, escaped] of specialChars) {
57
- selector = selector.replace(new RegExp((0, string_1.escapeRegExp)(`\\${c}`), 'gu'), escaped);
58
- }
59
- return selector;
60
- };
61
- /**
62
- * 还原转义符号
63
- * @param selector
64
- */
65
- const desanitize = (selector) => {
66
- for (const [c, escaped] of specialChars) {
67
- selector = selector.replace(new RegExp(escaped, 'gu'), c);
68
- }
69
- return selector.trim();
70
- };
71
- /**
72
- * 去除首尾的引号
73
- * @param val 属性值或伪选择器函数的参数
74
- */
75
- const deQuote = (val) => /^(["']).*\1$/u.test(val) ? val.slice(1, -1) : val.trim();
76
- /**
77
- * 解析选择器
78
- * @param selector
79
- * @throws `SyntaxError` 非法的选择器
80
- */
81
- const parseSelector = (selector) => {
82
- selector = selector.trim();
83
- const stack = [[[]]];
84
- let sanitized = sanitize(selector), regex = regularRegex, mt = regex.exec(sanitized), [condition] = stack, [step] = condition;
85
- /**
86
- * 解析简单伪选择器
87
- * @param index 伪选择器的终点位置
88
- * @throws `SyntaxError` 非法的选择器
89
- */
90
- const pushSimple = (index) => {
91
- const str = sanitized.slice(0, index), pieces = str.trim().split(':'),
92
- // eslint-disable-next-line unicorn/explicit-length-check
93
- i = pieces.slice(1).findIndex(pseudo => simplePseudos.has(pseudo)) + 1 || pieces.length;
94
- if (pieces.slice(i).some(pseudo => !simplePseudos.has(pseudo))) {
95
- throw new SyntaxError(`非法的选择器!\n${str}\n可能需要将':'转义为'\\:'。`);
96
- }
97
- step.push(desanitize(pieces.slice(0, i).join(':')), ...pieces.slice(i).map(piece => `:${piece}`));
98
- };
99
- while (mt) {
100
- let { 0: syntax, index } = mt;
101
- if (syntax.trim() === '') {
102
- index += syntax.length;
103
- const char = sanitized[index];
104
- syntax = grouping.has(char) ? char : '';
105
- }
106
- if (syntax === ',') { // 情形1:并列
107
- pushSimple(index);
108
- condition = [[]];
109
- [step] = condition;
110
- stack.push(condition);
111
- }
112
- else if (combinator.has(syntax)) { // 情形2:关系
113
- pushSimple(index);
114
- if (!step.some(Boolean)) {
115
- throw new SyntaxError(`非法的选择器!\n${selector}\n可能需要通用选择器'*'。`);
116
- }
117
- step.relation = syntax;
118
- step = [];
119
- condition.push(step);
120
- }
121
- else if (syntax === '[') { // 情形3:属性开启
122
- pushSimple(index);
123
- regex = attributeRegex;
124
- }
125
- else if (syntax.endsWith(']')) { // 情形4:属性闭合
126
- mt[3] &&= desanitize(deQuote(mt[3]));
127
- step.push(mt.slice(1));
128
- regex = regularRegex;
129
- }
130
- else if (syntax === '(') { // 情形5:伪选择器开启
131
- const pseudoExec = pseudoRegex.exec(sanitized.slice(0, index));
132
- if (!pseudoExec) {
133
- throw new SyntaxError(`非法的选择器!\n${desanitize(sanitized)}\n请检查伪选择器是否存在。`);
134
- }
135
- pushSimple(pseudoExec.index);
136
- step.push(pseudoExec[1]); // 临时存放复杂伪选择器
137
- regex = functionRegex;
138
- }
139
- else { // 情形6:伪选择器闭合
140
- mt.push(step.pop());
141
- mt[1] &&= deQuote(mt[1]);
142
- step.push(mt.slice(1));
143
- regex = regularRegex;
144
- }
145
- sanitized = sanitized.slice(index + syntax.length);
146
- if (grouping.has(syntax)) {
147
- sanitized = sanitized.trim();
148
- }
149
- mt = regex.exec(sanitized);
150
- }
151
- if (regex === regularRegex) {
152
- pushSimple(Infinity);
153
- const pseudos = new Set(stack.flat(2).filter((e) => typeof e === 'string' && e.startsWith(':')));
154
- if (pseudos.size > 0) {
155
- index_1.default.warn('检测到伪选择器,请确认是否需要将":"转义成"\\:"。', pseudos);
156
- }
157
- return stack;
158
- }
159
- throw new SyntaxError(`非法的选择器!\n${selector}\n检测到未闭合的'${regex === attributeRegex ? '[' : '('}'`);
160
- };
161
- exports.parseSelector = parseSelector;
162
- constants_1.parsers['parseSelector'] = __filename;
@@ -1,124 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseTable = void 0;
4
- const constants_1 = require("../util/constants");
5
- const index_1 = require("../index");
6
- const index_2 = require("../src/index");
7
- const index_3 = require("../src/table/index");
8
- const tr_1 = require("../src/table/tr");
9
- const td_1 = require("../src/table/td");
10
- const dd_1 = require("../src/nowiki/dd");
11
- /**
12
- * 判断是否为表格行或表格
13
- * @param token 表格节点
14
- */
15
- const isTr = (token) => token.lastChild.constructor !== index_2.Token;
16
- /**
17
- * 解析表格,注意`tr`和`td`包含开头的换行
18
- * @param {Token & {firstChild: AstText}} root 根节点
19
- * @param config
20
- * @param accum
21
- */
22
- const parseTable = ({ firstChild: { data }, type, name }, config = index_1.default.getConfig(), accum = []) => {
23
- const stack = [], lines = data.split('\n');
24
- let out = type === 'root' || type === 'parameter-value' || type === 'ext-inner' && name === 'poem'
25
- ? ''
26
- : `\n${lines.shift()}`, top;
27
- /**
28
- * 向表格中插入纯文本
29
- * @param str 待插入的文本
30
- * @param topToken 当前解析的表格或表格行
31
- */
32
- const push = (str, topToken) => {
33
- if (!topToken) {
34
- out += str;
35
- return;
36
- }
37
- const { lastChild } = topToken;
38
- if (isTr(topToken)) {
39
- const token = new index_2.Token(str, config, accum);
40
- token.type = 'table-inter';
41
- token.setAttribute('stage', 3);
42
- topToken.insertAt(token);
43
- }
44
- else {
45
- lastChild.setText(String(lastChild) + str);
46
- }
47
- },
48
- /** 取出最近的表格行 */
49
- pop = () => top.type === 'td' ? stack.pop() : top;
50
- for (const outLine of lines) {
51
- top = stack.pop();
52
- const [spaces] = /^(?:\s|\0\d+c\x7F)*/u.exec(outLine), line = outLine.slice(spaces.length), matchesStart = /^(:*)((?:\s|\0\d+c\x7F)*)(\{\||\{(?:\0\d+c\x7F)*\0\d+!\x7F|\0\d+\{\x7F)(.*)$/u
53
- .exec(line);
54
- if (matchesStart) {
55
- while (top && top.type !== 'td') {
56
- top = stack.pop();
57
- }
58
- const [, indent, moreSpaces, tableSyntax, attr] = matchesStart;
59
- if (indent) {
60
- // @ts-expect-error abstract class
61
- new dd_1.DdToken(indent, config, accum);
62
- }
63
- push(`\n${spaces}${indent && `\0${accum.length - 1}d\x7F`}${moreSpaces}\0${accum.length}b\x7F`, top);
64
- // @ts-expect-error abstract class
65
- stack.push(...top ? [top] : [], new index_3.TableToken(tableSyntax, attr, config, accum));
66
- continue;
67
- }
68
- else if (!top) {
69
- out += `\n${outLine}`;
70
- continue;
71
- }
72
- // eslint-disable-next-line @stylistic/operator-linebreak
73
- const matches = /^(?:(\|\}|\0\d+!\x7F\}|\0\d+\}\x7F)|(\|-+|\0\d+!\x7F-+|\0\d+-\x7F-*)(?!-)|(!|(?:\||\0\d+!\x7F)\+?))(.*)$/u
74
- .exec(line);
75
- if (!matches) {
76
- push(`\n${outLine}`, top);
77
- stack.push(top);
78
- continue;
79
- }
80
- const [, closing, row, cell, attr] = matches;
81
- if (closing) {
82
- while (top.type !== 'table') {
83
- top = stack.pop();
84
- }
85
- top.close(`\n${spaces}${closing}`, true);
86
- push(attr, stack[stack.length - 1]);
87
- }
88
- else if (row) {
89
- top = pop();
90
- if (top.type === 'tr') {
91
- top = stack.pop();
92
- }
93
- // @ts-expect-error abstract class
94
- const tr = new tr_1.TrToken(`\n${spaces}${row}`, attr, config, accum);
95
- stack.push(top, tr);
96
- top.insertAt(tr);
97
- }
98
- else {
99
- top = pop();
100
- const regex = cell === '!' ? /!!|(?:\||\0\d+!\x7F){2}|\0\d+\+\x7F/gu : /(?:\||\0\d+!\x7F){2}|\0\d+\+\x7F/gu;
101
- let mt = regex.exec(attr), lastIndex = 0, lastSyntax = `\n${spaces}${cell}`;
102
- /**
103
- * 创建表格单元格
104
- * @param tr 当前表格行
105
- */
106
- const createTd = (tr) => {
107
- // @ts-expect-error abstract class
108
- const td = new td_1.TdToken(lastSyntax, attr.slice(lastIndex, mt?.index), config, accum);
109
- tr.insertAt(td);
110
- return td;
111
- };
112
- while (mt) {
113
- createTd(top);
114
- ({ lastIndex } = regex);
115
- [lastSyntax] = mt;
116
- mt = regex.exec(attr);
117
- }
118
- stack.push(top, createTd(top));
119
- }
120
- }
121
- return out.slice(1);
122
- };
123
- exports.parseTable = parseTable;
124
- constants_1.parsers['parseTable'] = __filename;