wikiparser-node 1.12.4 → 1.12.5-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 (175) hide show
  1. package/bundle/bundle.min.js +37 -0
  2. package/config/default.json +29 -30
  3. package/config/enwiki.json +15 -829
  4. package/config/llwiki.json +21 -56
  5. package/config/minimum.json +6 -1
  6. package/config/moegirl.json +21 -65
  7. package/config/zhwiki.json +28 -494
  8. package/extensions/dist/base.js +163 -0
  9. package/extensions/dist/codejar.js +52 -0
  10. package/extensions/dist/editor.js +159 -0
  11. package/extensions/dist/highlight.js +30 -0
  12. package/extensions/dist/lint.js +72 -0
  13. package/extensions/editor.css +59 -0
  14. package/extensions/ui.css +162 -0
  15. package/package.json +28 -21
  16. package/config/.schema.json +0 -203
  17. package/dist/addon/table.js +0 -494
  18. package/dist/addon/token.js +0 -392
  19. package/dist/addon/transclude.js +0 -184
  20. package/dist/base.d.ts +0 -81
  21. package/dist/base.js +0 -40
  22. package/dist/index.d.ts +0 -33
  23. package/dist/index.js +0 -275
  24. package/dist/internal.d.ts +0 -47
  25. package/dist/lib/element.d.ts +0 -125
  26. package/dist/lib/element.js +0 -377
  27. package/dist/lib/node.d.ts +0 -173
  28. package/dist/lib/node.js +0 -478
  29. package/dist/lib/range.d.ts +0 -105
  30. package/dist/lib/range.js +0 -406
  31. package/dist/lib/ranges.d.ts +0 -28
  32. package/dist/lib/ranges.js +0 -126
  33. package/dist/lib/rect.d.ts +0 -18
  34. package/dist/lib/rect.js +0 -36
  35. package/dist/lib/text.d.ts +0 -58
  36. package/dist/lib/text.js +0 -414
  37. package/dist/lib/title.d.ts +0 -49
  38. package/dist/lib/title.js +0 -253
  39. package/dist/mixin/attributesParent.d.ts +0 -49
  40. package/dist/mixin/attributesParent.js +0 -80
  41. package/dist/mixin/fixed.d.ts +0 -5
  42. package/dist/mixin/fixed.js +0 -32
  43. package/dist/mixin/flagsParent.d.ts +0 -43
  44. package/dist/mixin/flagsParent.js +0 -64
  45. package/dist/mixin/hidden.d.ts +0 -7
  46. package/dist/mixin/hidden.js +0 -39
  47. package/dist/mixin/magicLinkParent.d.ts +0 -19
  48. package/dist/mixin/magicLinkParent.js +0 -43
  49. package/dist/mixin/singleLine.d.ts +0 -5
  50. package/dist/mixin/singleLine.js +0 -25
  51. package/dist/mixin/sol.d.ts +0 -6
  52. package/dist/mixin/sol.js +0 -45
  53. package/dist/mixin/syntax.d.ts +0 -8
  54. package/dist/mixin/syntax.js +0 -46
  55. package/dist/parser/braces.js +0 -152
  56. package/dist/parser/commentAndExt.js +0 -84
  57. package/dist/parser/converter.js +0 -41
  58. package/dist/parser/externalLinks.js +0 -39
  59. package/dist/parser/hrAndDoubleUnderscore.js +0 -44
  60. package/dist/parser/html.js +0 -40
  61. package/dist/parser/links.js +0 -103
  62. package/dist/parser/list.js +0 -116
  63. package/dist/parser/magicLinks.js +0 -55
  64. package/dist/parser/quotes.js +0 -69
  65. package/dist/parser/redirect.js +0 -28
  66. package/dist/parser/selector.js +0 -393
  67. package/dist/parser/table.js +0 -125
  68. package/dist/src/arg.d.ts +0 -49
  69. package/dist/src/arg.js +0 -219
  70. package/dist/src/atom.d.ts +0 -14
  71. package/dist/src/atom.js +0 -54
  72. package/dist/src/attribute.d.ts +0 -64
  73. package/dist/src/attribute.js +0 -478
  74. package/dist/src/attributes.d.ts +0 -103
  75. package/dist/src/attributes.js +0 -380
  76. package/dist/src/converter.d.ts +0 -28
  77. package/dist/src/converter.js +0 -153
  78. package/dist/src/converterFlags.d.ts +0 -80
  79. package/dist/src/converterFlags.js +0 -241
  80. package/dist/src/converterRule.d.ts +0 -71
  81. package/dist/src/converterRule.js +0 -218
  82. package/dist/src/extLink.d.ts +0 -36
  83. package/dist/src/extLink.js +0 -223
  84. package/dist/src/gallery.d.ts +0 -47
  85. package/dist/src/gallery.js +0 -145
  86. package/dist/src/heading.d.ts +0 -44
  87. package/dist/src/heading.js +0 -222
  88. package/dist/src/hidden.d.ts +0 -9
  89. package/dist/src/hidden.js +0 -82
  90. package/dist/src/html.d.ts +0 -61
  91. package/dist/src/html.js +0 -344
  92. package/dist/src/imageParameter.d.ts +0 -60
  93. package/dist/src/imageParameter.js +0 -262
  94. package/dist/src/imagemap.d.ts +0 -47
  95. package/dist/src/imagemap.js +0 -148
  96. package/dist/src/imagemapLink.d.ts +0 -35
  97. package/dist/src/imagemapLink.js +0 -99
  98. package/dist/src/index.d.ts +0 -136
  99. package/dist/src/index.js +0 -790
  100. package/dist/src/link/base.d.ts +0 -52
  101. package/dist/src/link/base.js +0 -258
  102. package/dist/src/link/category.d.ts +0 -22
  103. package/dist/src/link/category.js +0 -36
  104. package/dist/src/link/file.d.ts +0 -102
  105. package/dist/src/link/file.js +0 -335
  106. package/dist/src/link/galleryImage.d.ts +0 -29
  107. package/dist/src/link/galleryImage.js +0 -133
  108. package/dist/src/link/index.d.ts +0 -39
  109. package/dist/src/link/index.js +0 -100
  110. package/dist/src/link/redirectTarget.d.ts +0 -27
  111. package/dist/src/link/redirectTarget.js +0 -71
  112. package/dist/src/magicLink.d.ts +0 -57
  113. package/dist/src/magicLink.js +0 -261
  114. package/dist/src/nested.d.ts +0 -40
  115. package/dist/src/nested.js +0 -108
  116. package/dist/src/nowiki/base.d.ts +0 -28
  117. package/dist/src/nowiki/base.js +0 -90
  118. package/dist/src/nowiki/comment.d.ts +0 -14
  119. package/dist/src/nowiki/comment.js +0 -123
  120. package/dist/src/nowiki/dd.d.ts +0 -8
  121. package/dist/src/nowiki/dd.js +0 -74
  122. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -15
  123. package/dist/src/nowiki/doubleUnderscore.js +0 -101
  124. package/dist/src/nowiki/hr.d.ts +0 -5
  125. package/dist/src/nowiki/hr.js +0 -72
  126. package/dist/src/nowiki/index.d.ts +0 -14
  127. package/dist/src/nowiki/index.js +0 -30
  128. package/dist/src/nowiki/list.d.ts +0 -5
  129. package/dist/src/nowiki/list.js +0 -67
  130. package/dist/src/nowiki/listBase.d.ts +0 -23
  131. package/dist/src/nowiki/listBase.js +0 -100
  132. package/dist/src/nowiki/noinclude.d.ts +0 -6
  133. package/dist/src/nowiki/noinclude.js +0 -77
  134. package/dist/src/nowiki/quote.d.ts +0 -14
  135. package/dist/src/nowiki/quote.js +0 -149
  136. package/dist/src/onlyinclude.d.ts +0 -13
  137. package/dist/src/onlyinclude.js +0 -60
  138. package/dist/src/paramTag/index.d.ts +0 -28
  139. package/dist/src/paramTag/index.js +0 -80
  140. package/dist/src/paramTag/inputbox.d.ts +0 -8
  141. package/dist/src/paramTag/inputbox.js +0 -24
  142. package/dist/src/parameter.d.ts +0 -60
  143. package/dist/src/parameter.js +0 -267
  144. package/dist/src/pre.d.ts +0 -28
  145. package/dist/src/pre.js +0 -62
  146. package/dist/src/redirect.d.ts +0 -30
  147. package/dist/src/redirect.js +0 -128
  148. package/dist/src/syntax.d.ts +0 -15
  149. package/dist/src/syntax.js +0 -87
  150. package/dist/src/table/base.d.ts +0 -28
  151. package/dist/src/table/base.js +0 -81
  152. package/dist/src/table/index.d.ts +0 -230
  153. package/dist/src/table/index.js +0 -506
  154. package/dist/src/table/td.d.ts +0 -72
  155. package/dist/src/table/td.js +0 -375
  156. package/dist/src/table/tr.d.ts +0 -30
  157. package/dist/src/table/tr.js +0 -61
  158. package/dist/src/table/trBase.d.ts +0 -49
  159. package/dist/src/table/trBase.js +0 -165
  160. package/dist/src/tagPair/ext.d.ts +0 -29
  161. package/dist/src/tagPair/ext.js +0 -217
  162. package/dist/src/tagPair/include.d.ts +0 -33
  163. package/dist/src/tagPair/include.js +0 -132
  164. package/dist/src/tagPair/index.d.ts +0 -23
  165. package/dist/src/tagPair/index.js +0 -130
  166. package/dist/src/transclude.d.ts +0 -159
  167. package/dist/src/transclude.js +0 -598
  168. package/dist/util/constants.js +0 -26
  169. package/dist/util/debug.js +0 -95
  170. package/dist/util/diff.js +0 -83
  171. package/dist/util/html.js +0 -146
  172. package/dist/util/lint.js +0 -32
  173. package/dist/util/string.js +0 -107
  174. package/errors/README +0 -3
  175. package/printed/README +0 -3
package/dist/mixin/sol.js DELETED
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sol = void 0;
4
- const debug_1 = require("../util/debug");
5
- const constants_1 = require("../util/constants");
6
- /**
7
- * 只能位于行首的类
8
- * @param self 是否允许同类节点相邻
9
- * @param constructor 基类
10
- * @param _ context
11
- */
12
- const sol = (self) => (constructor, _) => {
13
- /** 只能位于行首的类 */
14
- class SolToken extends constructor {
15
- /** @implements */
16
- #prependNewLine() {
17
- const { previousVisibleSibling, parentNode, type } = this;
18
- if (previousVisibleSibling) {
19
- return self && previousVisibleSibling.type === type || previousVisibleSibling.toString().endsWith('\n')
20
- ? ''
21
- : '\n';
22
- }
23
- return parentNode?.type === 'root'
24
- || type === 'list' && parentNode?.type === 'list-range'
25
- || type !== 'heading' && parentNode?.type === 'ext-inner' && parentNode.name === 'poem'
26
- ? ''
27
- : '\n';
28
- }
29
- toString(skip) {
30
- return this.#prependNewLine() + super.toString(skip);
31
- }
32
- getAttribute(key) {
33
- return key === 'padding'
34
- ? this.#prependNewLine().length + super.getAttribute('padding')
35
- : super.getAttribute(key);
36
- }
37
- text() {
38
- return this.#prependNewLine() + super.text();
39
- }
40
- }
41
- (0, debug_1.mixin)(SolToken, constructor);
42
- return SolToken;
43
- };
44
- exports.sol = sol;
45
- constants_1.mixins['sol'] = __filename;
@@ -1,8 +0,0 @@
1
- export interface SyntaxBase {
2
- }
3
- /**
4
- * 满足特定语法格式的Token
5
- * @param pattern 语法正则
6
- * @param constructor 基类
7
- * @param _ context
8
- */
@@ -1,46 +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
- /**
8
- * 满足特定语法格式的Token
9
- * @param pattern 语法正则
10
- * @param constructor 基类
11
- * @param _ context
12
- */
13
- const syntax = (pattern) => (constructor, _) => {
14
- /** 满足特定语法格式的Token */
15
- class SyntaxToken extends constructor {
16
- /** @class */
17
- constructor(...args) {
18
- super(...args); // eslint-disable-line @typescript-eslint/no-unsafe-argument
19
- if (pattern) {
20
- this.pattern = pattern;
21
- }
22
- this.seal('pattern', true);
23
- }
24
- afterBuild() {
25
- super.afterBuild();
26
- const /** @implements */ syntaxListener = (e, data) => {
27
- if (!debug_1.Shadow.running && !this.pattern.test((0, string_1.text)(this.childNodes))) {
28
- (0, debug_1.undo)(e, data);
29
- this.constructorError('cannot modify the syntax pattern');
30
- }
31
- };
32
- this.addEventListener(['remove', 'insert', 'replace', 'text'], syntaxListener);
33
- }
34
- replaceChildren(...elements) {
35
- if (debug_1.Shadow.running || this.pattern.test((0, string_1.text)(elements))) {
36
- debug_1.Shadow.run(() => {
37
- super.replaceChildren(...elements);
38
- });
39
- }
40
- }
41
- }
42
- (0, debug_1.mixin)(SyntaxToken, constructor);
43
- return SyntaxToken;
44
- };
45
- exports.syntax = syntax;
46
- constants_1.mixins['syntax'] = __filename;
@@ -1,152 +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 heading_1 = require("../src/heading");
6
- const transclude_1 = require("../src/transclude");
7
- const arg_1 = require("../src/arg");
8
- /* NOT FOR BROWSER */
9
- const constants_1 = require("../util/constants");
10
- /* NOT FOR BROWSER END */
11
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
12
- /\{\{\s*([!=]|!!|\(!|!\)|!-)\s*\}\}(?!\})/gu;
13
- const closes = {
14
- '=': String.raw `\n(?!(?:[^\S\n]|\0\d+[cn]\x7F)*\n)`,
15
- '{': String.raw `\}{2,}|\|`,
16
- '-': String.raw `\}-`,
17
- '[': String.raw `\]\]`,
18
- }, marks = new Map([['!', '!'], ['!!', '+'], ['(!', '{'], ['!)', '}'], ['!-', '-'], ['=', '~']]), re = new RegExp(String.raw `\{\{\s*(${[...marks.keys()].map(string_1.escapeRegExp).join('|')})\s*\}\}(?!\})`, 'gu');
19
- /**
20
- * 解析花括号
21
- * @param wikitext
22
- * @param config
23
- * @param accum
24
- * @throws TranscludeToken.constructor()
25
- */
26
- const parseBraces = (wikitext, config, accum) => {
27
- const source = String.raw `${config.excludes?.includes('heading') ? '' : String.raw `^((?:\0\d+[cno]\x7F)*)={1,6}|`}\[\[|-\{(?!\{)`, openBraces = String.raw `|\{{2,}`, { parserFunction: [, , , subst] } = config, stack = [];
28
- wikitext = wikitext.replace(re, (m, p1) => {
29
- // @ts-expect-error abstract class
30
- new transclude_1.TranscludeToken(m.slice(2, -2), [], config, accum);
31
- return `\0${accum.length - 2}${marks.get(p1)}\x7F`;
32
- });
33
- const lastBraces = wikitext.lastIndexOf('}}') - wikitext.length;
34
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
35
- /^((?:\0\d+[cno]\x7F)*)={1,6}|\[\[|-\{(?!\{)|\{{2,}|\n(?!(?:[^\S\n]|\0\d+[cn]\x7F)*\n)|[|=]|\}{2,}|\}-|\]\]/gmu;
36
- let moreBraces = lastBraces + wikitext.length !== -1, regex = new RegExp(source + (moreBraces ? openBraces : ''), 'gmu'), mt = regex.exec(wikitext), lastIndex;
37
- while (mt
38
- || lastIndex !== undefined && lastIndex <= wikitext.length && stack[stack.length - 1]?.[0]?.startsWith('=')) {
39
- if (mt?.[1]) {
40
- const [, { length }] = mt;
41
- mt[0] = mt[0].slice(length);
42
- mt.index += length;
43
- }
44
- 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;
45
- /**
46
- * 填入模板内容
47
- * @param text wikitext全文
48
- */
49
- const push = (text) => {
50
- parts[parts.length - 1].push(text.slice(topPos, curIndex));
51
- };
52
- if (syntax === ']]' || syntax === '}-') { // 情形1:闭合内链或转换
53
- lastIndex = curIndex + 2;
54
- }
55
- else if (syntax === '\n') { // 情形2:闭合标题或文末
56
- lastIndex = curIndex + 1;
57
- const { pos, findEqual } = stack[stack.length - 1] ?? {};
58
- if (pos === undefined || findEqual || (0, string_1.removeComment)(wikitext.slice(pos, index)) !== '') {
59
- const rmt = /^(={1,6})(.+)\1((?:\s|\0\d+[cn]\x7F)*)$/u
60
- .exec(wikitext.slice(index, curIndex));
61
- if (rmt) {
62
- wikitext = `${wikitext.slice(0, index)}\0${accum.length}h\x7F${wikitext.slice(curIndex)}`;
63
- lastIndex = index + 4 + String(accum.length).length;
64
- // @ts-expect-error abstract class
65
- new heading_1.HeadingToken(rmt[1].length, rmt.slice(2), config, accum);
66
- }
67
- }
68
- }
69
- else if (syntax === '|' || innerEqual) { // 情形3:模板内部,含行首单个'='
70
- lastIndex = curIndex + 1;
71
- push(wikitext);
72
- if (syntax === '|') {
73
- parts.push([]);
74
- }
75
- top.pos = lastIndex;
76
- top.findEqual = syntax === '|';
77
- stack.push(top);
78
- }
79
- else if (syntax.startsWith('}}')) { // 情形4:闭合模板
80
- const close = syntax.slice(0, Math.min(open.length, 3)), rest = open.length - close.length, { length } = accum;
81
- lastIndex = curIndex + close.length; // 这不是最终的lastIndex
82
- push(wikitext);
83
- let skip = false, ch = 't';
84
- if (close.length === 3) {
85
- const argParts = parts.map(part => part.join('=')), str = argParts.length > 1 && (0, string_1.removeComment)(argParts[1]).trim();
86
- // @ts-expect-error abstract class
87
- new arg_1.ArgToken(argParts, config, accum);
88
- if (str && str.endsWith(':') && subst.includes(str.slice(0, -1).toLowerCase())) {
89
- ch = 's';
90
- }
91
- }
92
- else {
93
- try {
94
- // @ts-expect-error abstract class
95
- new transclude_1.TranscludeToken(parts[0][0], parts.slice(1), config, accum);
96
- const name = (0, string_1.removeComment)(parts[0][0]).trim();
97
- if (marks.has(name)) {
98
- ch = marks.get(name); // 标记{{!}}等
99
- }
100
- else if (/^(?:filepath|(?:full|canonical)urle?):.|^server$/iu.test(name)) {
101
- ch = 'm';
102
- }
103
- else if (/^#vardefine:./iu.test(name)) {
104
- ch = 'n';
105
- }
106
- }
107
- catch (e) {
108
- if (e instanceof SyntaxError && e.message === 'Invalid template name') {
109
- skip = true;
110
- }
111
- else {
112
- throw e;
113
- }
114
- }
115
- }
116
- if (!skip) {
117
- wikitext = `${wikitext.slice(0, index + rest)}\0${length}${ch}\x7F${wikitext.slice(lastIndex)}`;
118
- lastIndex = index + rest + 3 + String(length).length;
119
- if (rest > 1) {
120
- stack.push({ 0: open.slice(0, rest), index: index, pos: index + rest, parts: [[]] });
121
- }
122
- else if (rest === 1 && wikitext[index - 1] === '-') {
123
- stack.push({ 0: '-{', index: index - 1, pos: index + 1, parts: [[]] });
124
- }
125
- }
126
- }
127
- else { // 情形5:开启
128
- lastIndex = curIndex + syntax.length;
129
- if (syntax.startsWith('{')) {
130
- mt.pos = lastIndex;
131
- mt.parts = [[]];
132
- }
133
- stack.push(...'0' in top ? [top] : [], mt);
134
- }
135
- let curTop = stack[stack.length - 1];
136
- if (moreBraces && lastBraces + wikitext.length < lastIndex) {
137
- moreBraces = false;
138
- while (curTop?.[0]?.startsWith('{')) {
139
- stack.pop();
140
- curTop = stack[stack.length - 1];
141
- }
142
- }
143
- regex = new RegExp(source
144
- + (moreBraces ? openBraces : '')
145
- + (curTop ? `|${closes[curTop[0][0]]}${curTop.findEqual ? '|=' : ''}` : ''), 'gmu');
146
- regex.lastIndex = lastIndex;
147
- mt = regex.exec(wikitext);
148
- }
149
- return wikitext;
150
- };
151
- exports.parseBraces = parseBraces;
152
- constants_1.parsers['parseBraces'] = __filename;
@@ -1,84 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseCommentAndExt = void 0;
4
- const onlyinclude_1 = require("../src/onlyinclude");
5
- const noinclude_1 = require("../src/nowiki/noinclude");
6
- const include_1 = require("../src/tagPair/include");
7
- const ext_1 = require("../src/tagPair/ext");
8
- const comment_1 = require("../src/nowiki/comment");
9
- /* NOT FOR BROWSER */
10
- const constants_1 = require("../util/constants");
11
- /* NOT FOR BROWSER END */
12
- /**
13
- * 解析HTML注释和扩展标签
14
- * @param wikitext
15
- * @param config
16
- * @param accum
17
- * @param includeOnly 是否嵌入
18
- */
19
- const parseCommentAndExt = (wikitext, config, accum, includeOnly) => {
20
- const onlyincludeLeft = '<onlyinclude>', onlyincludeRight = '</onlyinclude>', { length } = onlyincludeLeft;
21
- /** 更新`<onlyinclude>`和`</onlyinclude>`的位置 */
22
- const update = () => {
23
- const i = wikitext.indexOf(onlyincludeLeft);
24
- return { i, j: wikitext.indexOf(onlyincludeRight, i + length) };
25
- };
26
- if (includeOnly) {
27
- let { i, j } = update();
28
- if (i !== -1 && j !== -1) { // `<onlyinclude>`拥有最高优先级
29
- let str = '';
30
- /**
31
- * 忽略未被`<onlyinclude>`和`</onlyinclude>`包裹的内容
32
- * @param text 未被包裹的内容
33
- */
34
- const noinclude = (text) => {
35
- // @ts-expect-error abstract class
36
- new noinclude_1.NoincludeToken(text, config, accum);
37
- str += `\0${accum.length - 1}n\x7F`;
38
- };
39
- while (i !== -1 && j !== -1) {
40
- const token = `\0${accum.length}e\x7F`;
41
- new onlyinclude_1.OnlyincludeToken(wikitext.slice(i + length, j), config, accum);
42
- if (i > 0) {
43
- noinclude(wikitext.slice(0, i));
44
- }
45
- str += token;
46
- wikitext = wikitext.slice(j + length + 1);
47
- ({ i, j } = update());
48
- }
49
- if (wikitext) {
50
- noinclude(wikitext);
51
- }
52
- return str;
53
- }
54
- }
55
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
56
- /<!--.*?(?:-->|$)|<foo(?:\s[^>]*)?\/?>|<\/foo\s*>|<(bar)(\s[^>]*?)?(?:\/>|>(.*?)<\/(\1\s*)>)|<(baz)(\s[^>]*?)?(?:\/>|>(.*?)(?:<\/(baz\s*)>|$))/gisu;
57
- const ext = config.ext.join('|'), noincludeRegex = includeOnly ? 'includeonly' : '(?:no|only)include', includeRegex = includeOnly ? 'noinclude' : 'includeonly', regex = new RegExp(String.raw `<!--.*?(?:-->|$)|<${noincludeRegex}(?:\s[^>]*)?/?>|</${noincludeRegex}\s*>|<(${ext})(\s[^>]*?)?(?:/>|>(.*?)</(\1\s*)>)|<(${includeRegex})(\s[^>]*?)?(?:/>|>(.*?)(?:</(${includeRegex}\s*)>|$))`, 'gisu');
58
- return wikitext.replace(regex, (substr, name, attr, inner, closing, include, includeAttr, includeInner, includeClosing) => {
59
- const l = accum.length;
60
- let ch = 'n';
61
- if (name) {
62
- ch = 'e';
63
- // @ts-expect-error abstract class
64
- new ext_1.ExtToken(name, attr, inner, closing, config, accum);
65
- }
66
- else if (substr.startsWith('<!--')) {
67
- ch = 'c';
68
- const closed = substr.endsWith('-->');
69
- // @ts-expect-error abstract class
70
- new comment_1.CommentToken(substr.slice(4, closed ? -3 : undefined), closed, config, accum);
71
- }
72
- else if (include) {
73
- // @ts-expect-error abstract class
74
- new include_1.IncludeToken(include, includeAttr, includeInner, includeClosing, config, accum);
75
- }
76
- else {
77
- // @ts-expect-error abstract class
78
- new noinclude_1.NoincludeToken(substr, config, accum);
79
- }
80
- return `\0${l}${ch}\x7F`;
81
- });
82
- };
83
- exports.parseCommentAndExt = parseCommentAndExt;
84
- constants_1.parsers['parseCommentAndExt'] = __filename;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseConverter = void 0;
4
- const converter_1 = require("../src/converter");
5
- /* NOT FOR BROWSER */
6
- const constants_1 = require("../util/constants");
7
- /* NOT FOR BROWSER END */
8
- /**
9
- * 解析语言变体转换
10
- * @param text
11
- * @param config
12
- * @param accum
13
- */
14
- const parseConverter = (text, config, accum) => {
15
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
16
- /;(?=(?:[^;]*?=>)?\s*zh\s*:|(?:\s|\0\d+[cn]\x7F)*$)/u;
17
- const variants = `(?:${config.variants.join('|')})`, regex1 = /-\{/gu, regex2 = /-\{|\}-/gu, regex3 = new RegExp(String.raw `;(?=(?:[^;]*?=>)?\s*${variants}\s*:|(?:\s|\0\d+[cn]\x7F)*$)`, 'u'), stack = [];
18
- let regex = regex1, mt = regex.exec(text);
19
- while (mt) {
20
- const { 0: syntax, index } = mt;
21
- if (syntax === '}-') {
22
- const top = stack.pop(), { length } = accum, str = text.slice(top.index + 2, index), i = str.indexOf('|'), [flags, raw] = i === -1 ? [[], str] : [str.slice(0, i).split(';'), str.slice(i + 1)], temp = raw.replace(/(&[#a-z\d]+);/giu, '$1\x01'), rules = temp.split(regex3).map(rule => rule.replace(/\x01/gu, ';'));
23
- // @ts-expect-error abstract class
24
- new converter_1.ConverterToken(flags, rules, config, accum);
25
- text = `${text.slice(0, top.index)}\0${length}v\x7F${text.slice(index + 2)}`;
26
- if (stack.length === 0) {
27
- regex = regex1;
28
- }
29
- regex.lastIndex = top.index + 3 + String(length).length;
30
- }
31
- else {
32
- stack.push(mt);
33
- regex = regex2;
34
- regex.lastIndex = index + 2;
35
- }
36
- mt = regex.exec(text);
37
- }
38
- return text;
39
- };
40
- exports.parseConverter = parseConverter;
41
- constants_1.parsers['parseConverter'] = __filename;
@@ -1,39 +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 extLink_1 = require("../src/extLink");
6
- const magicLink_1 = require("../src/magicLink");
7
- /* NOT FOR BROWSER */
8
- const constants_1 = require("../util/constants");
9
- /* NOT FOR BROWSER END */
10
- /**
11
- * 解析外部链接
12
- * @param wikitext
13
- * @param config
14
- * @param accum
15
- * @param inFile 是否在图链中
16
- */
17
- const parseExternalLinks = (wikitext, config, accum, inFile) => {
18
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
19
- /\[((?:ftp:\/\/|\/\/)(?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])[^[\]<>"\t\n\p{Zs}]*(?=[[\]<>"\t\p{Zs}]|\0\d))(\p{Zs}*(?!\p{Zs}))([^\]\n]*)\]/giu;
20
- const regex = new RegExp(String.raw `\[(\0\d+f\x7F|(?:(?:${config.protocol}|//)${string_1.extUrlCharFirst}|\0\d+m\x7F)${string_1.extUrlChar}(?=[[\]<>"\t\p{Zs}]|\0\d))(\p{Zs}*(?!\p{Zs}))([^\]\x01-\x08\x0A-\x1F\uFFFD]*)\]`, 'giu');
21
- return wikitext.replace(regex, (_, url, space, text) => {
22
- const { length } = accum, mt = /&[lg]t;/u.exec(url);
23
- if (mt) {
24
- url = url.slice(0, mt.index);
25
- space = '';
26
- text = url.slice(mt.index) + space + text;
27
- }
28
- if (inFile) {
29
- // @ts-expect-error abstract class
30
- new magicLink_1.MagicLinkToken(url, 'ext-link-url', config, accum);
31
- return `[\0${length}f\x7F${space}${text}]`;
32
- }
33
- // @ts-expect-error abstract class
34
- new extLink_1.ExtLinkToken(url, space, text, config, accum);
35
- return `\0${length}w\x7F`;
36
- });
37
- };
38
- exports.parseExternalLinks = parseExternalLinks;
39
- constants_1.parsers['parseExternalLinks'] = __filename;
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseHrAndDoubleUnderscore = void 0;
4
- const hr_1 = require("../src/nowiki/hr");
5
- const doubleUnderscore_1 = require("../src/nowiki/doubleUnderscore");
6
- const heading_1 = require("../src/heading");
7
- /* NOT FOR BROWSER */
8
- const constants_1 = require("../util/constants");
9
- /* NOT FOR BROWSER END */
10
- /**
11
- * 解析`<hr>`和状态开关
12
- * @param {Token} root 根节点
13
- * @param config
14
- * @param accum
15
- */
16
- const parseHrAndDoubleUnderscore = ({ firstChild: { data }, type, name }, config, accum) => {
17
- const { doubleUnderscore } = config, insensitive = new Set(doubleUnderscore[0]), sensitive = new Set(doubleUnderscore[1]);
18
- if (type !== 'root' && (type !== 'ext-inner' || name !== 'poem')) {
19
- data = `\0${data}`;
20
- }
21
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
22
- /__(toc|notoc)__/giu;
23
- data = data.replace(/^((?:\0\d+[cno]\x7F)*)(-{4,})/gmu, (_, lead, m) => {
24
- // @ts-expect-error abstract class
25
- new hr_1.HrToken(m, config, accum);
26
- return `${lead}\0${accum.length - 1}r\x7F`;
27
- }).replace(new RegExp(`__(${[...insensitive, ...sensitive].join('|')})__`, 'giu'), (m, p1) => {
28
- const caseSensitive = sensitive.has(p1), lc = p1.toLowerCase(), caseInsensitive = insensitive.has(lc);
29
- if (caseSensitive || caseInsensitive) {
30
- // @ts-expect-error abstract class
31
- new doubleUnderscore_1.DoubleUnderscoreToken(p1, caseSensitive, config, accum);
32
- return `\0${accum.length - 1}${caseInsensitive && (doubleUnderscore[2]?.[lc] ?? lc) === 'toc' ? 'u' : 'n'}\x7F`;
33
- }
34
- return m;
35
- }).replace(/^((?:\0\d+[cn]\x7F)*)(={1,6})(.+)\2((?:\s|\0\d+[cn]\x7F)*)$/gmu, (_, lead, equals, heading, trail) => {
36
- const text = `${lead}\0${accum.length}h\x7F`;
37
- // @ts-expect-error abstract class
38
- new heading_1.HeadingToken(equals.length, [heading, trail], config, accum);
39
- return text;
40
- });
41
- return type === 'root' || type === 'ext-inner' && name === 'poem' ? data : data.slice(1);
42
- };
43
- exports.parseHrAndDoubleUnderscore = parseHrAndDoubleUnderscore;
44
- constants_1.parsers['parseHrAndDoubleUnderscore'] = __filename;
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseHtml = void 0;
4
- const attributes_1 = require("../src/attributes");
5
- const html_1 = require("../src/html");
6
- /* NOT FOR BROWSER */
7
- const constants_1 = require("../util/constants");
8
- /* NOT FOR BROWSER END */
9
- /**
10
- * 解析HTML标签
11
- * @param wikitext
12
- * @param config
13
- * @param accum
14
- */
15
- const parseHtml = (wikitext, config, accum) => {
16
- const regex = /^(\/?)([a-z][^\s/>]*)((?:\s|\/(?!>))[^>]*?)?(\/?>)([^<]*)$/iu, { html } = config, elements = new Set([...html[0], ...html[1], ...html[2]]), bits = wikitext.split('<');
17
- let text = bits.shift();
18
- for (const x of bits) {
19
- const mt = regex.exec(x), t = mt?.[2], name = t?.toLowerCase();
20
- if (!mt || !elements.has(name)) {
21
- text += `<${x}`;
22
- continue;
23
- }
24
- const [, slash, , params = '', brace, rest] = mt, { length } = accum,
25
- // @ts-expect-error abstract class
26
- attrs = new attributes_1.AttributesToken(params, 'html-attrs', name, config, accum), itemprop = attrs.getAttr('itemprop');
27
- if (name === 'meta' && (itemprop === undefined || attrs.getAttr('content') === undefined)
28
- || name === 'link' && (itemprop === undefined || attrs.getAttr('href') === undefined)) {
29
- text += `<${x}`;
30
- accum.length = length;
31
- continue;
32
- }
33
- text += `\0${accum.length}x\x7F${rest}`;
34
- // @ts-expect-error abstract class
35
- new html_1.HtmlToken(t, attrs, slash === '/', brace === '/>', config, accum);
36
- }
37
- return text;
38
- };
39
- exports.parseHtml = parseHtml;
40
- constants_1.parsers['parseHtml'] = __filename;
@@ -1,103 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseLinks = void 0;
4
- const index_1 = require("../index");
5
- const quotes_1 = require("./quotes");
6
- const externalLinks_1 = require("./externalLinks");
7
- const index_2 = require("../src/link/index");
8
- const file_1 = require("../src/link/file");
9
- const category_1 = require("../src/link/category");
10
- /* NOT FOR BROWSER */
11
- const constants_1 = require("../util/constants");
12
- /* NOT FOR BROWSER END */
13
- /**
14
- * 解析内部链接
15
- * @param wikitext
16
- * @param config
17
- * @param accum
18
- */
19
- const parseLinks = (wikitext, config, accum) => {
20
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
21
- /^\s*(?:ftp:\/\/|\/\/)/iu;
22
- const regex = true // eslint-disable-line no-constant-condition, @typescript-eslint/no-unnecessary-condition
23
- ? /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(?:(\||\0\d+!\x7F)(.*?[^\]]))?\]\](.*)$/su
24
- : /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(?:(\||\0\d+!\x7F)(.*?[^\]])?)?\]\](.*)$/su, regexImg = /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(\||\0\d+!\x7F)(.*)$/su, regexExt = new RegExp(String.raw `^\s*(?:${config.protocol}|//)`, 'iu'), bits = wikitext.split('[[');
25
- let s = bits.shift();
26
- for (let i = 0; i < bits.length; i++) {
27
- let mightBeImg = false, link, delimiter, text, after;
28
- const x = bits[i], m = regex.exec(x);
29
- if (m) {
30
- [, link, delimiter, text, after] = m;
31
- if (after.startsWith(']') && text?.includes('[')) {
32
- text += ']';
33
- after = after.slice(1);
34
- }
35
- }
36
- else {
37
- const m2 = regexImg.exec(x);
38
- if (m2) {
39
- mightBeImg = true;
40
- [, link, delimiter, text] = m2;
41
- }
42
- }
43
- if (link === undefined || regexExt.test(link) || /\0\d+[exhbru]\x7F/u.test(link)) {
44
- s += `[[${x}`;
45
- continue;
46
- }
47
- const force = link.trim().startsWith(':');
48
- if (force && mightBeImg) {
49
- s += `[[${x}`;
50
- continue;
51
- }
52
- const title = index_1.default.normalizeTitle(link, 0, false, config, true, true, true), { ns, valid, interwiki } = title;
53
- if (!valid) {
54
- s += `[[${x}`;
55
- continue;
56
- }
57
- else if (mightBeImg) {
58
- if (interwiki || ns !== 6) {
59
- s += `[[${x}`;
60
- continue;
61
- }
62
- let found = false;
63
- for (i++; i < bits.length; i++) {
64
- const next = bits[i], p = next.split(']]');
65
- if (p.length > 2) {
66
- found = true;
67
- text += `[[${p[0]}]]${p[1]}`;
68
- after = p.slice(2).join(']]');
69
- break;
70
- }
71
- else if (p.length === 2) {
72
- text += `[[${p[0]}]]${p[1]}`;
73
- }
74
- else {
75
- text += `[[${next}`;
76
- break;
77
- }
78
- }
79
- text = (0, exports.parseLinks)(text, config, accum);
80
- if (!found) {
81
- s += `[[${link}${delimiter}${text}`;
82
- continue;
83
- }
84
- }
85
- text &&= (0, quotes_1.parseQuotes)(text, config, accum);
86
- let SomeLinkToken = index_2.LinkToken;
87
- if (!force) {
88
- if (!interwiki && ns === 6) {
89
- text &&= (0, externalLinks_1.parseExternalLinks)(text, config, accum, true);
90
- SomeLinkToken = file_1.FileToken;
91
- }
92
- else if (!interwiki && ns === 14) {
93
- SomeLinkToken = category_1.CategoryToken;
94
- }
95
- }
96
- s += `\0${accum.length}l\x7F${after}`;
97
- // @ts-expect-error abstract class
98
- new SomeLinkToken(link, text, config, accum, delimiter);
99
- }
100
- return s;
101
- };
102
- exports.parseLinks = parseLinks;
103
- constants_1.parsers['parseLinks'] = __filename;