wikiparser-node 1.3.2 → 1.3.3-b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/bundle/bundle.min.js +36 -0
  2. package/config/llwiki.json +1 -35
  3. package/config/moegirl.json +1 -44
  4. package/config/zhwiki.json +1 -466
  5. package/extensions/dist/base.js +68 -0
  6. package/extensions/dist/editor.js +159 -0
  7. package/extensions/dist/highlight.js +30 -0
  8. package/extensions/dist/lint.js +48 -0
  9. package/extensions/editor.css +63 -0
  10. package/extensions/ui.css +114 -0
  11. package/package.json +32 -12
  12. package/config/.schema.json +0 -172
  13. package/dist/addon/table.d.ts +0 -6
  14. package/dist/addon/table.js +0 -564
  15. package/dist/base.d.ts +0 -45
  16. package/dist/bin/toc.js +0 -18
  17. package/dist/index.d.ts +0 -31
  18. package/dist/index.js +0 -209
  19. package/dist/internal.d.ts +0 -44
  20. package/dist/lib/element.d.ts +0 -155
  21. package/dist/lib/element.js +0 -634
  22. package/dist/lib/node.d.ts +0 -146
  23. package/dist/lib/node.js +0 -419
  24. package/dist/lib/range.d.ts +0 -104
  25. package/dist/lib/range.js +0 -385
  26. package/dist/lib/ranges.d.ts +0 -26
  27. package/dist/lib/ranges.js +0 -117
  28. package/dist/lib/text.d.ts +0 -62
  29. package/dist/lib/text.js +0 -248
  30. package/dist/lib/title.d.ts +0 -38
  31. package/dist/lib/title.js +0 -162
  32. package/dist/mixin/attributesParent.js +0 -94
  33. package/dist/mixin/fixed.js +0 -32
  34. package/dist/mixin/flagsParent.js +0 -70
  35. package/dist/mixin/hidden.js +0 -26
  36. package/dist/mixin/magicLinkParent.js +0 -41
  37. package/dist/mixin/singleLine.js +0 -25
  38. package/dist/mixin/sol.js +0 -43
  39. package/dist/mixin/syntax.js +0 -56
  40. package/dist/parser/braces.js +0 -121
  41. package/dist/parser/commentAndExt.js +0 -69
  42. package/dist/parser/converter.js +0 -40
  43. package/dist/parser/externalLinks.js +0 -28
  44. package/dist/parser/hrAndDoubleUnderscore.js +0 -38
  45. package/dist/parser/html.js +0 -36
  46. package/dist/parser/links.js +0 -94
  47. package/dist/parser/list.js +0 -59
  48. package/dist/parser/magicLinks.js +0 -40
  49. package/dist/parser/quotes.js +0 -67
  50. package/dist/parser/selector.js +0 -162
  51. package/dist/parser/table.js +0 -112
  52. package/dist/src/arg.d.ts +0 -58
  53. package/dist/src/arg.js +0 -189
  54. package/dist/src/atom.d.ts +0 -12
  55. package/dist/src/atom.js +0 -27
  56. package/dist/src/attribute.d.ts +0 -87
  57. package/dist/src/attribute.js +0 -392
  58. package/dist/src/attributes.d.ts +0 -107
  59. package/dist/src/attributes.js +0 -341
  60. package/dist/src/converter.d.ts +0 -52
  61. package/dist/src/converter.js +0 -79
  62. package/dist/src/converterFlags.d.ts +0 -87
  63. package/dist/src/converterFlags.js +0 -224
  64. package/dist/src/converterRule.d.ts +0 -81
  65. package/dist/src/converterRule.js +0 -212
  66. package/dist/src/extLink.d.ts +0 -54
  67. package/dist/src/extLink.js +0 -122
  68. package/dist/src/gallery.d.ts +0 -55
  69. package/dist/src/gallery.js +0 -122
  70. package/dist/src/heading.d.ts +0 -74
  71. package/dist/src/heading.js +0 -127
  72. package/dist/src/hidden.d.ts +0 -22
  73. package/dist/src/hidden.js +0 -23
  74. package/dist/src/html.d.ts +0 -101
  75. package/dist/src/html.js +0 -222
  76. package/dist/src/imageParameter.d.ts +0 -66
  77. package/dist/src/imageParameter.js +0 -247
  78. package/dist/src/imagemap.d.ts +0 -57
  79. package/dist/src/imagemap.js +0 -148
  80. package/dist/src/imagemapLink.d.ts +0 -59
  81. package/dist/src/imagemapLink.js +0 -40
  82. package/dist/src/index.d.ts +0 -146
  83. package/dist/src/index.js +0 -777
  84. package/dist/src/link/base.d.ts +0 -52
  85. package/dist/src/link/base.js +0 -209
  86. package/dist/src/link/category.d.ts +0 -13
  87. package/dist/src/link/category.js +0 -29
  88. package/dist/src/link/file.d.ts +0 -96
  89. package/dist/src/link/file.js +0 -255
  90. package/dist/src/link/galleryImage.d.ts +0 -44
  91. package/dist/src/link/galleryImage.js +0 -106
  92. package/dist/src/link/index.d.ts +0 -53
  93. package/dist/src/link/index.js +0 -123
  94. package/dist/src/magicLink.d.ts +0 -70
  95. package/dist/src/magicLink.js +0 -147
  96. package/dist/src/nested.d.ts +0 -44
  97. package/dist/src/nested.js +0 -87
  98. package/dist/src/nowiki/base.d.ts +0 -47
  99. package/dist/src/nowiki/base.js +0 -42
  100. package/dist/src/nowiki/comment.d.ts +0 -40
  101. package/dist/src/nowiki/comment.js +0 -67
  102. package/dist/src/nowiki/dd.d.ts +0 -8
  103. package/dist/src/nowiki/dd.js +0 -25
  104. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -45
  105. package/dist/src/nowiki/doubleUnderscore.js +0 -50
  106. package/dist/src/nowiki/hr.d.ts +0 -31
  107. package/dist/src/nowiki/hr.js +0 -14
  108. package/dist/src/nowiki/index.d.ts +0 -16
  109. package/dist/src/nowiki/index.js +0 -21
  110. package/dist/src/nowiki/list.d.ts +0 -30
  111. package/dist/src/nowiki/list.js +0 -48
  112. package/dist/src/nowiki/listBase.d.ts +0 -19
  113. package/dist/src/nowiki/listBase.js +0 -12
  114. package/dist/src/nowiki/noinclude.d.ts +0 -26
  115. package/dist/src/nowiki/noinclude.js +0 -25
  116. package/dist/src/nowiki/quote.d.ts +0 -23
  117. package/dist/src/nowiki/quote.js +0 -45
  118. package/dist/src/onlyinclude.d.ts +0 -16
  119. package/dist/src/onlyinclude.js +0 -57
  120. package/dist/src/paramTag/index.d.ts +0 -37
  121. package/dist/src/paramTag/index.js +0 -68
  122. package/dist/src/paramTag/inputbox.d.ts +0 -8
  123. package/dist/src/paramTag/inputbox.js +0 -23
  124. package/dist/src/parameter.d.ts +0 -85
  125. package/dist/src/parameter.js +0 -205
  126. package/dist/src/pre.d.ts +0 -28
  127. package/dist/src/pre.js +0 -51
  128. package/dist/src/syntax.d.ts +0 -28
  129. package/dist/src/syntax.js +0 -34
  130. package/dist/src/table/base.d.ts +0 -53
  131. package/dist/src/table/base.js +0 -78
  132. package/dist/src/table/index.d.ts +0 -229
  133. package/dist/src/table/index.js +0 -379
  134. package/dist/src/table/td.d.ts +0 -104
  135. package/dist/src/table/td.js +0 -261
  136. package/dist/src/table/tr.d.ts +0 -32
  137. package/dist/src/table/tr.js +0 -56
  138. package/dist/src/table/trBase.d.ts +0 -54
  139. package/dist/src/table/trBase.js +0 -159
  140. package/dist/src/tagPair/ext.d.ts +0 -56
  141. package/dist/src/tagPair/ext.js +0 -142
  142. package/dist/src/tagPair/include.d.ts +0 -53
  143. package/dist/src/tagPair/include.js +0 -63
  144. package/dist/src/tagPair/index.d.ts +0 -48
  145. package/dist/src/tagPair/index.js +0 -93
  146. package/dist/src/transclude.d.ts +0 -167
  147. package/dist/src/transclude.js +0 -689
  148. package/dist/util/constants.js +0 -108
  149. package/dist/util/debug.js +0 -64
  150. package/dist/util/diff.js +0 -72
  151. package/dist/util/lint.js +0 -46
  152. package/dist/util/string.js +0 -61
  153. package/errors/README +0 -1
  154. package/printed/README +0 -1
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.magicLinkParent = void 0;
4
- const constants_1 = require("../util/constants");
5
- /**
6
- * ExtLinkToken
7
- * @param constructor 基类
8
- */
9
- const magicLinkParent = (constructor) => {
10
- /** 子节点含有MagicLinkParent的类 */
11
- class MagicLinkParent extends constructor {
12
- /** 协议 */
13
- get protocol() {
14
- return this.firstChild.protocol;
15
- }
16
- set protocol(value) {
17
- this.firstChild.protocol = value;
18
- }
19
- /** 和内链保持一致 */
20
- get link() {
21
- return this.firstChild.link;
22
- }
23
- set link(url) {
24
- this.firstChild.link = url;
25
- }
26
- /** 获取网址 */
27
- getUrl() {
28
- return this.firstChild.getUrl();
29
- }
30
- /**
31
- * 设置链接目标
32
- * @param url 网址
33
- */
34
- setTarget(url) {
35
- this.firstChild.setTarget(url);
36
- }
37
- }
38
- return MagicLinkParent;
39
- };
40
- exports.magicLinkParent = magicLinkParent;
41
- constants_1.mixins['magicLinkParent'] = __filename;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.singleLine = void 0;
4
- const constants_1 = require("../util/constants");
5
- /**
6
- * 不可包含换行符的类
7
- * @param constructor 基类
8
- */
9
- const singleLine = (constructor) => {
10
- /** 不可包含换行符的类 */
11
- class SingleLineToken extends constructor {
12
- /** @private */
13
- toString(omit) {
14
- return super.toString(omit).replaceAll('\n', ' ');
15
- }
16
- /** @override */
17
- text() {
18
- return super.text().replaceAll('\n', ' ');
19
- }
20
- }
21
- Object.defineProperty(SingleLineToken, 'name', { value: `SingleLine${constructor.name}` });
22
- return SingleLineToken;
23
- };
24
- exports.singleLine = singleLine;
25
- constants_1.mixins['singleLine'] = __filename;
package/dist/mixin/sol.js DELETED
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sol = void 0;
4
- const constants_1 = require("../util/constants");
5
- /**
6
- * 只能位于行首的类
7
- * @param constructor 基类
8
- */
9
- const sol = (constructor) => {
10
- /** 只能位于行首的类 */
11
- class SolToken extends constructor {
12
- /** 在前方插入newline */
13
- prependNewLine() {
14
- const { previousVisibleSibling, parentNode, type } = this;
15
- if (previousVisibleSibling) {
16
- return String(previousVisibleSibling).endsWith('\n') ? '' : '\n';
17
- }
18
- return parentNode?.type === 'root'
19
- || type !== 'heading' && parentNode?.type === 'ext-inner' && parentNode.name === 'poem'
20
- ? ''
21
- : '\n';
22
- }
23
- /** @private */
24
- toString(omit) {
25
- return omit && this.matchesTypes(omit)
26
- ? ''
27
- : `${this.prependNewLine()}${super.toString(omit)}`;
28
- }
29
- /** @private */
30
- getAttribute(key) {
31
- return key === 'padding'
32
- ? this.prependNewLine().length
33
- : super.getAttribute(key);
34
- }
35
- /** @override */
36
- text() {
37
- return `${this.prependNewLine()}${super.text()}`;
38
- }
39
- }
40
- return SolToken;
41
- };
42
- exports.sol = sol;
43
- constants_1.mixins['sol'] = __filename;
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.syntax = void 0;
4
- const debug_1 = require("../util/debug");
5
- const constants_1 = require("../util/constants");
6
- const string_1 = require("../util/string");
7
- const Parser = require("../index");
8
- /**
9
- * 满足特定语法格式的Token
10
- * @param constructor 基类
11
- * @param pattern 语法正则
12
- */
13
- const syntax = (constructor, pattern) => {
14
- /** 满足特定语法格式的Token */
15
- class SyntaxToken extends constructor {
16
- #pattern = pattern;
17
- /** @private */
18
- afterBuild() {
19
- const /** @implements */ syntaxListener = (e, data) => {
20
- if (!debug_1.Shadow.running && !this.#pattern.test(this.text())) {
21
- (0, debug_1.undo)(e, data);
22
- Parser.error(`不可修改 ${this.constructor.name} 的语法!`, this.#pattern);
23
- throw new Error(`不可修改 ${this.constructor.name} 的语法!`);
24
- }
25
- };
26
- this.addEventListener(['remove', 'insert', 'replace', 'text'], syntaxListener);
27
- }
28
- /** @private */
29
- getAttribute(key) {
30
- return key === 'pattern' ? this.#pattern : super.getAttribute(key);
31
- }
32
- /** @private */
33
- setAttribute(key, value) {
34
- if (key === 'pattern') {
35
- this.#pattern = value;
36
- }
37
- else {
38
- super.setAttribute(key, value);
39
- }
40
- }
41
- /**
42
- * @override
43
- * @param elements 待替换的子节点
44
- */
45
- replaceChildren(...elements) {
46
- if (debug_1.Shadow.running || this.#pattern.test((0, string_1.text)(elements))) {
47
- debug_1.Shadow.run(() => {
48
- super.replaceChildren(...elements);
49
- });
50
- }
51
- }
52
- }
53
- return SyntaxToken;
54
- };
55
- exports.syntax = syntax;
56
- constants_1.mixins['syntax'] = __filename;
@@ -1,121 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseBraces = void 0;
4
- const string_1 = require("../util/string");
5
- const constants_1 = require("../util/constants");
6
- const Parser = require("../index");
7
- const heading_1 = require("../src/heading");
8
- const transclude_1 = require("../src/transclude");
9
- const arg_1 = require("../src/arg");
10
- /**
11
- * 解析花括号
12
- * @param wikitext
13
- * @param config
14
- * @param accum
15
- * @throws TranscludeToken.constructor()
16
- */
17
- const parseBraces = (wikitext, config = Parser.getConfig(), accum = []) => {
18
- const source = `${config.excludes?.includes('heading') ? '' : '^(\0\\d+c\x7F)*={1,6}|'}\\[\\[|\\{{2,}|-\\{(?!\\{)`, { parserFunction: [, , , subst] } = config, stack = [], closes = { '=': '\n', '{': '\\}{2,}|\\|', '-': '\\}-', '[': '\\]\\]' }, marks = new Map([['!', '!'], ['!!', '+'], ['(!', '{'], ['!)', '}'], ['!-', '-'], ['=', '~']]);
19
- let regex = new RegExp(source, 'gmu'), mt = regex.exec(wikitext), moreBraces = wikitext.includes('}}'), lastIndex;
20
- while (mt
21
- || lastIndex !== undefined && lastIndex <= wikitext.length && stack.at(-1)?.[0]?.startsWith('=')) {
22
- if (mt?.[1]) {
23
- const [, { length }] = mt;
24
- mt[0] = mt[0].slice(length);
25
- mt.index += length;
26
- }
27
- const { 0: syntax, index: curIndex } = mt ?? { 0: '\n', index: wikitext.length }, top = stack.pop() ?? {}, { 0: open, index, parts, findEqual: topFindEqual, pos: topPos } = top, innerEqual = syntax === '=' && topFindEqual;
28
- if (syntax === ']]' || syntax === '}-') { // 情形1:闭合内链或转换
29
- lastIndex = curIndex + 2;
30
- }
31
- else if (syntax === '\n') { // 情形2:闭合标题或文末
32
- lastIndex = curIndex + 1;
33
- const { pos, findEqual } = stack.at(-1) ?? {};
34
- if (pos === undefined || findEqual || (0, string_1.removeComment)(wikitext.slice(pos, index)) !== '') {
35
- const rmt = /^(={1,6})(.+)\1((?:\s|\0\d+c\x7F)*)$/u
36
- .exec(wikitext.slice(index, curIndex));
37
- if (rmt) {
38
- wikitext = `${wikitext.slice(0, index)}\0${accum.length}h\x7F${wikitext.slice(curIndex)}`;
39
- lastIndex = index + 4 + String(accum.length).length;
40
- new heading_1.HeadingToken(rmt[1].length, rmt.slice(2), config, accum);
41
- }
42
- }
43
- }
44
- else if (syntax === '|' || innerEqual) { // 情形3:模板内部,含行首单个'='
45
- lastIndex = curIndex + 1;
46
- parts.at(-1).push(wikitext.slice(topPos, curIndex));
47
- if (syntax === '|') {
48
- parts.push([]);
49
- }
50
- top.pos = lastIndex;
51
- top.findEqual = syntax === '|';
52
- stack.push(top);
53
- }
54
- else if (syntax.startsWith('}}')) { // 情形4:闭合模板
55
- const close = syntax.slice(0, Math.min(open.length, 3)), rest = open.length - close.length, { length } = accum;
56
- lastIndex = curIndex + close.length; // 这不是最终的lastIndex
57
- parts.at(-1).push(wikitext.slice(topPos, curIndex));
58
- let skip = false, ch = 't';
59
- if (close.length === 3) {
60
- const argParts = parts.map(part => part.join('=')), str = argParts.length > 1 && (0, string_1.removeComment)(argParts[1]).trim();
61
- new arg_1.ArgToken(argParts, config, accum);
62
- if (str && str.endsWith(':') && subst.includes(str.slice(0, -1).toLowerCase())) {
63
- ch = 's';
64
- }
65
- }
66
- else {
67
- try {
68
- new transclude_1.TranscludeToken(parts[0][0], parts.slice(1), config, accum);
69
- const name = (0, string_1.removeComment)(parts[0][0]).trim();
70
- if (marks.has(name)) {
71
- ch = marks.get(name); // 标记{{!}}等
72
- }
73
- else if (/^(?:filepath|(?:full|canonical)urle?):.|^server$/iu.test(name)) {
74
- ch = 'm';
75
- }
76
- else if (/^#vardefine:./iu.test(name)) {
77
- ch = 'c';
78
- }
79
- }
80
- catch (e) {
81
- if (e instanceof SyntaxError && e.message.startsWith('非法的模板名称:')) {
82
- skip = true;
83
- }
84
- else {
85
- throw e;
86
- }
87
- }
88
- }
89
- if (!skip) {
90
- wikitext = `${wikitext.slice(0, index + rest)}\0${length}${ch}\x7F${wikitext.slice(lastIndex)}`;
91
- lastIndex = index + rest + 3 + String(length).length;
92
- if (rest > 1) {
93
- stack.push({ 0: open.slice(0, rest), index: index, pos: index + rest, parts: [[]] });
94
- }
95
- else if (rest === 1 && wikitext[index - 1] === '-') {
96
- stack.push({ 0: '-{', index: index - 1, pos: index + 1, parts: [[]] });
97
- }
98
- }
99
- }
100
- else { // 情形5:开启
101
- lastIndex = curIndex + syntax.length;
102
- if (syntax.startsWith('{')) {
103
- mt.pos = lastIndex;
104
- mt.parts = [[]];
105
- }
106
- stack.push(...'0' in top ? [top] : [], mt);
107
- }
108
- moreBraces &&= wikitext.slice(lastIndex).includes('}}');
109
- let curTop = stack.at(-1);
110
- if (!moreBraces && curTop?.[0]?.startsWith('{')) {
111
- stack.pop();
112
- curTop = stack.at(-1);
113
- }
114
- regex = new RegExp(source + (curTop ? `|${closes[curTop[0][0]]}${curTop.findEqual ? '|=' : ''}` : ''), 'gmu');
115
- regex.lastIndex = lastIndex;
116
- mt = regex.exec(wikitext);
117
- }
118
- return wikitext;
119
- };
120
- exports.parseBraces = parseBraces;
121
- constants_1.parsers['parseBraces'] = __filename;
@@ -1,69 +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 Parser = require("../index");
6
- const onlyinclude_1 = require("../src/onlyinclude");
7
- const noinclude_1 = require("../src/nowiki/noinclude");
8
- const include_1 = require("../src/tagPair/include");
9
- const ext_1 = require("../src/tagPair/ext");
10
- const comment_1 = require("../src/nowiki/comment");
11
- /**
12
- * 解析HTML注释和扩展标签
13
- * @param wikitext
14
- * @param config
15
- * @param accum
16
- * @param includeOnly 是否嵌入
17
- */
18
- const parseCommentAndExt = (wikitext, config = Parser.getConfig(), accum = [], includeOnly = false) => {
19
- const onlyincludeLeft = '<onlyinclude>', onlyincludeRight = '</onlyinclude>', { length } = onlyincludeLeft;
20
- if (includeOnly) {
21
- let i = wikitext.indexOf(onlyincludeLeft), j = wikitext.indexOf(onlyincludeRight, i + length);
22
- if (i !== -1 && j !== -1) { // `<onlyinclude>`拥有最高优先级
23
- let str = '';
24
- while (i !== -1 && j !== -1) {
25
- const token = `\0${accum.length}e\x7F`;
26
- new onlyinclude_1.OnlyincludeToken(wikitext.slice(i + length, j), config, accum);
27
- if (i > 0) {
28
- new noinclude_1.NoincludeToken(wikitext.slice(0, i), config, accum);
29
- str += `\0${accum.length - 1}c\x7F${token}`;
30
- }
31
- else {
32
- str += token;
33
- }
34
- wikitext = wikitext.slice(j + length + 1);
35
- i = wikitext.indexOf(onlyincludeLeft);
36
- j = wikitext.indexOf(onlyincludeRight, i + length);
37
- }
38
- if (wikitext) {
39
- new noinclude_1.NoincludeToken(wikitext, config, accum);
40
- str += `\0${accum.length - 1}c\x7F`;
41
- }
42
- return str;
43
- }
44
- }
45
- const ext = config.ext.join('|'), noincludeRegex = includeOnly ? 'includeonly' : '(?:no|only)include', includeRegex = includeOnly ? 'noinclude' : 'includeonly', regex = new RegExp('<!--.*?(?:-->|$)|' // comment
46
- + `<${noincludeRegex}(?:\\s[^>]*?)?>|</${noincludeRegex}\\s*>|` // <noinclude>
47
- + `<(${ext})(\\s[^>]*?)?(?:/>|>(.*?)</(\\1\\s*)>)|` // 扩展标签
48
- + `<(${includeRegex})(\\s[^>]*?)?(?:/>|>(.*?)(?:</(${includeRegex}\\s*)>|$))`, // <includeonly>
49
- 'gisu');
50
- return wikitext.replace(regex, (substr, name, attr, inner, closing, include, includeAttr, includeInner, includeClosing) => {
51
- const str = `\0${accum.length}${name ? 'e' : 'c'}\x7F`;
52
- if (name) {
53
- new ext_1.ExtToken(name, attr, inner, closing, config, accum);
54
- }
55
- else if (substr.startsWith('<!--')) {
56
- const closed = substr.endsWith('-->');
57
- new comment_1.CommentToken(substr.slice(4, closed ? -3 : undefined), closed, config, accum);
58
- }
59
- else if (include) {
60
- new include_1.IncludeToken(include, includeAttr, includeInner, includeClosing, config, accum);
61
- }
62
- else {
63
- new noinclude_1.NoincludeToken(substr, config, accum);
64
- }
65
- return str;
66
- });
67
- };
68
- exports.parseCommentAndExt = parseCommentAndExt;
69
- 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 Parser = require("../index");
6
- const converter_1 = require("../src/converter");
7
- /**
8
- * 解析语言变体转换
9
- * @param text
10
- * @param config
11
- * @param accum
12
- */
13
- const parseConverter = (text, config = Parser.getConfig(), accum = []) => {
14
- const regex1 = /-\{/gu, regex2 = /-\{|\}-/gu, stack = [];
15
- let regex = regex1, mt = regex.exec(text);
16
- while (mt) {
17
- const { 0: syntax, index } = mt;
18
- if (syntax === '}-') {
19
- 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)],
20
- // eslint-disable-next-line regexp/prefer-lookaround
21
- temp = raw.replace(/(&[#a-z\d]+);/giu, '$1\x01'), variants = `(?:${config.variants.join('|')})`, rules = temp.split(new RegExp(`;(?=\\s*(?:${variants}|[^;]*?=>\\s*${variants})\\s*:)`, 'u'))
22
- .map(rule => rule.replaceAll('\x01', ';'));
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,28 +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 Parser = 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 = Parser.getConfig(), accum = []) => {
15
- const regex = new RegExp(`\\[((?:(?:${config.protocol}|//)${string_1.extUrlCharFirst}|\0\\d+m\x7F)${string_1.extUrlChar})(\\p{Zs}*)([^\\]\x01-\x08\x0A-\x1F\uFFFD]*)\\]`, 'giu');
16
- return wikitext.replace(regex, (_, url, space, text) => {
17
- const { length } = accum, mt = /&[lg]t;/u.exec(url);
18
- if (mt) {
19
- url = url.slice(0, mt.index);
20
- space = '';
21
- text = `${url.slice(mt.index)}${space}${text}`;
22
- }
23
- new extLink_1.ExtLinkToken(url, space, text, config, accum);
24
- return `\0${length}w\x7F`;
25
- });
26
- };
27
- exports.parseExternalLinks = parseExternalLinks;
28
- constants_1.parsers['parseExternalLinks'] = __filename;
@@ -1,38 +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 Parser = 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 = Parser.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
- 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 fixed = sensitive.has(p1);
25
- if (fixed || insensitive.has(p1.toLowerCase())) {
26
- new doubleUnderscore_1.DoubleUnderscoreToken(p1, fixed, config, accum);
27
- return `\0${accum.length - 1}u\x7F`;
28
- }
29
- return m;
30
- }).replace(/^((?:\0\d+c\x7F)*)(={1,6})(.+)\2((?:[^\S\n]|\0\d+c\x7F)*)$/gmu, (_, lead, equals, heading, trail) => {
31
- const text = `${lead}\0${accum.length}h\x7F`;
32
- new heading_1.HeadingToken(equals.length, [heading, trail], config, accum);
33
- return text;
34
- });
35
- return type === 'root' || type === 'ext-inner' && name === 'poem' ? data : data.slice(1);
36
- };
37
- exports.parseHrAndDoubleUnderscore = parseHrAndDoubleUnderscore;
38
- constants_1.parsers['parseHrAndDoubleUnderscore'] = __filename;
@@ -1,36 +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 Parser = 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 = Parser.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, attr = new attributes_1.AttributesToken(params, 'html-attrs', name, config, accum), itemprop = attr.getAttr('itemprop');
24
- if (name === 'meta' && (itemprop === undefined || attr.getAttr('content') === undefined)
25
- || name === 'link' && (itemprop === undefined || attr.getAttr('href') === undefined)) {
26
- text += `<${x}`;
27
- accum.pop();
28
- continue;
29
- }
30
- text += `\0${accum.length}x\x7F${rest}`;
31
- new html_1.HtmlToken(t, attr, slash === '/', brace === '/>', config, accum);
32
- }
33
- return text;
34
- };
35
- exports.parseHtml = parseHtml;
36
- constants_1.parsers['parseHtml'] = __filename;
@@ -1,94 +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 Parser = require("../index");
6
- const index_1 = 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 = Parser.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 = Parser.normalizeTitle(link, 0, false, config, true, true, true), { ns, interwiki, valid, } = 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_1.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
- new SomeLinkToken(link, text, config, accum, delimiter);
90
- }
91
- return s;
92
- };
93
- exports.parseLinks = parseLinks;
94
- constants_1.parsers['parseLinks'] = __filename;
@@ -1,59 +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 Parser = 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 = Parser.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
- new list_1.ListToken(prefix, config, accum);
22
- if (!dt) {
23
- return text;
24
- }
25
- let regex = /:+|-\{/gu, ex = regex.exec(text), lc = 0;
26
- while (ex && dt) {
27
- const { 0: syntax, index } = ex;
28
- if (syntax.startsWith(':')) {
29
- if (syntax.length >= dt) {
30
- new dd_1.DdToken(':'.repeat(dt), config, accum);
31
- return `${text.slice(0, index)}\0${accum.length - 1}d\x7F${text.slice(index + dt)}`;
32
- }
33
- text = `${text.slice(0, index)}\0${accum.length}d\x7F${text.slice(regex.lastIndex)}`;
34
- dt -= syntax.length;
35
- regex.lastIndex = index + 4 + String(accum.length).length;
36
- new dd_1.DdToken(syntax, config, accum);
37
- }
38
- else if (syntax === '-{') {
39
- if (!lc) {
40
- const { lastIndex } = regex;
41
- regex = /-\{|\}-/gu;
42
- regex.lastIndex = lastIndex;
43
- }
44
- lc++;
45
- }
46
- else {
47
- lc--;
48
- if (!lc) {
49
- const { lastIndex } = regex;
50
- regex = /:+|-\{/gu;
51
- regex.lastIndex = lastIndex;
52
- }
53
- }
54
- ex = regex.exec(text);
55
- }
56
- return text;
57
- };
58
- exports.parseList = parseList;
59
- constants_1.parsers['parseList'] = __filename;