wikiparser-node 1.3.7 → 1.3.8-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 (153) 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 +64 -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 +31 -13
  12. package/config/.schema.json +0 -172
  13. package/dist/addon/table.d.ts +0 -6
  14. package/dist/addon/table.js +0 -558
  15. package/dist/base.d.ts +0 -45
  16. package/dist/index.d.ts +0 -32
  17. package/dist/index.js +0 -209
  18. package/dist/internal.d.ts +0 -44
  19. package/dist/lib/element.d.ts +0 -154
  20. package/dist/lib/element.js +0 -630
  21. package/dist/lib/node.d.ts +0 -146
  22. package/dist/lib/node.js +0 -417
  23. package/dist/lib/range.d.ts +0 -104
  24. package/dist/lib/range.js +0 -385
  25. package/dist/lib/ranges.d.ts +0 -26
  26. package/dist/lib/ranges.js +0 -118
  27. package/dist/lib/text.d.ts +0 -62
  28. package/dist/lib/text.js +0 -255
  29. package/dist/lib/title.d.ts +0 -38
  30. package/dist/lib/title.js +0 -162
  31. package/dist/mixin/attributesParent.js +0 -89
  32. package/dist/mixin/fixed.js +0 -25
  33. package/dist/mixin/flagsParent.js +0 -70
  34. package/dist/mixin/hidden.js +0 -26
  35. package/dist/mixin/magicLinkParent.js +0 -41
  36. package/dist/mixin/singleLine.js +0 -25
  37. package/dist/mixin/sol.js +0 -43
  38. package/dist/mixin/syntax.js +0 -54
  39. package/dist/parser/braces.js +0 -128
  40. package/dist/parser/commentAndExt.js +0 -80
  41. package/dist/parser/converter.js +0 -40
  42. package/dist/parser/externalLinks.js +0 -28
  43. package/dist/parser/hrAndDoubleUnderscore.js +0 -38
  44. package/dist/parser/html.js +0 -36
  45. package/dist/parser/links.js +0 -94
  46. package/dist/parser/list.js +0 -66
  47. package/dist/parser/magicLinks.js +0 -40
  48. package/dist/parser/quotes.js +0 -67
  49. package/dist/parser/selector.js +0 -162
  50. package/dist/parser/table.js +0 -120
  51. package/dist/src/arg.d.ts +0 -56
  52. package/dist/src/arg.js +0 -187
  53. package/dist/src/atom.d.ts +0 -12
  54. package/dist/src/atom.js +0 -27
  55. package/dist/src/attribute.d.ts +0 -88
  56. package/dist/src/attribute.js +0 -398
  57. package/dist/src/attributes.d.ts +0 -109
  58. package/dist/src/attributes.js +0 -343
  59. package/dist/src/converter.d.ts +0 -53
  60. package/dist/src/converter.js +0 -79
  61. package/dist/src/converterFlags.d.ts +0 -87
  62. package/dist/src/converterFlags.js +0 -224
  63. package/dist/src/converterRule.d.ts +0 -77
  64. package/dist/src/converterRule.js +0 -208
  65. package/dist/src/extLink.d.ts +0 -55
  66. package/dist/src/extLink.js +0 -122
  67. package/dist/src/gallery.d.ts +0 -54
  68. package/dist/src/gallery.js +0 -121
  69. package/dist/src/heading.d.ts +0 -76
  70. package/dist/src/heading.js +0 -127
  71. package/dist/src/hidden.d.ts +0 -23
  72. package/dist/src/hidden.js +0 -23
  73. package/dist/src/html.d.ts +0 -104
  74. package/dist/src/html.js +0 -226
  75. package/dist/src/imageParameter.d.ts +0 -65
  76. package/dist/src/imageParameter.js +0 -245
  77. package/dist/src/imagemap.d.ts +0 -56
  78. package/dist/src/imagemap.js +0 -147
  79. package/dist/src/imagemapLink.d.ts +0 -61
  80. package/dist/src/imagemapLink.js +0 -40
  81. package/dist/src/index.d.ts +0 -140
  82. package/dist/src/index.js +0 -769
  83. package/dist/src/link/base.d.ts +0 -52
  84. package/dist/src/link/base.js +0 -209
  85. package/dist/src/link/category.d.ts +0 -13
  86. package/dist/src/link/category.js +0 -29
  87. package/dist/src/link/file.d.ts +0 -96
  88. package/dist/src/link/file.js +0 -257
  89. package/dist/src/link/galleryImage.d.ts +0 -45
  90. package/dist/src/link/galleryImage.js +0 -106
  91. package/dist/src/link/index.d.ts +0 -53
  92. package/dist/src/link/index.js +0 -124
  93. package/dist/src/magicLink.d.ts +0 -69
  94. package/dist/src/magicLink.js +0 -147
  95. package/dist/src/nested.d.ts +0 -43
  96. package/dist/src/nested.js +0 -86
  97. package/dist/src/nowiki/base.d.ts +0 -48
  98. package/dist/src/nowiki/base.js +0 -42
  99. package/dist/src/nowiki/comment.d.ts +0 -41
  100. package/dist/src/nowiki/comment.js +0 -67
  101. package/dist/src/nowiki/dd.d.ts +0 -8
  102. package/dist/src/nowiki/dd.js +0 -25
  103. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -47
  104. package/dist/src/nowiki/doubleUnderscore.js +0 -50
  105. package/dist/src/nowiki/hr.d.ts +0 -33
  106. package/dist/src/nowiki/hr.js +0 -14
  107. package/dist/src/nowiki/index.d.ts +0 -16
  108. package/dist/src/nowiki/index.js +0 -21
  109. package/dist/src/nowiki/list.d.ts +0 -31
  110. package/dist/src/nowiki/list.js +0 -48
  111. package/dist/src/nowiki/listBase.d.ts +0 -20
  112. package/dist/src/nowiki/listBase.js +0 -12
  113. package/dist/src/nowiki/noinclude.d.ts +0 -26
  114. package/dist/src/nowiki/noinclude.js +0 -24
  115. package/dist/src/nowiki/quote.d.ts +0 -24
  116. package/dist/src/nowiki/quote.js +0 -45
  117. package/dist/src/onlyinclude.d.ts +0 -16
  118. package/dist/src/onlyinclude.js +0 -57
  119. package/dist/src/paramTag/index.d.ts +0 -37
  120. package/dist/src/paramTag/index.js +0 -68
  121. package/dist/src/paramTag/inputbox.d.ts +0 -8
  122. package/dist/src/paramTag/inputbox.js +0 -23
  123. package/dist/src/parameter.d.ts +0 -86
  124. package/dist/src/parameter.js +0 -205
  125. package/dist/src/pre.d.ts +0 -28
  126. package/dist/src/pre.js +0 -51
  127. package/dist/src/syntax.d.ts +0 -30
  128. package/dist/src/syntax.js +0 -34
  129. package/dist/src/table/base.d.ts +0 -59
  130. package/dist/src/table/base.js +0 -78
  131. package/dist/src/table/index.d.ts +0 -228
  132. package/dist/src/table/index.js +0 -379
  133. package/dist/src/table/td.d.ts +0 -107
  134. package/dist/src/table/td.js +0 -263
  135. package/dist/src/table/tr.d.ts +0 -32
  136. package/dist/src/table/tr.js +0 -56
  137. package/dist/src/table/trBase.d.ts +0 -53
  138. package/dist/src/table/trBase.js +0 -153
  139. package/dist/src/tagPair/ext.d.ts +0 -58
  140. package/dist/src/tagPair/ext.js +0 -140
  141. package/dist/src/tagPair/include.d.ts +0 -54
  142. package/dist/src/tagPair/include.js +0 -63
  143. package/dist/src/tagPair/index.d.ts +0 -49
  144. package/dist/src/tagPair/index.js +0 -93
  145. package/dist/src/transclude.d.ts +0 -167
  146. package/dist/src/transclude.js +0 -698
  147. package/dist/util/constants.js +0 -113
  148. package/dist/util/debug.js +0 -83
  149. package/dist/util/diff.js +0 -72
  150. package/dist/util/lint.js +0 -30
  151. package/dist/util/string.js +0 -51
  152. package/errors/README +0 -1
  153. 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).replace(/\n/gu, ' ');
15
- }
16
- /** @override */
17
- text() {
18
- return super.text().replace(/\n/gu, ' ');
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,54 +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 constructor 基类
10
- * @param pattern 语法正则
11
- */
12
- const syntax = (constructor, pattern) => {
13
- /** 满足特定语法格式的Token */
14
- class SyntaxToken extends constructor {
15
- #pattern = pattern;
16
- /** @private */
17
- afterBuild() {
18
- const /** @implements */ syntaxListener = (e, data) => {
19
- if (!debug_1.Shadow.running && !this.#pattern.test(this.text())) {
20
- (0, debug_1.undo)(e, data);
21
- this.constructorError('不可修改语法');
22
- }
23
- };
24
- this.addEventListener(['remove', 'insert', 'replace', 'text'], syntaxListener);
25
- }
26
- /** @private */
27
- getAttribute(key) {
28
- return key === 'pattern' ? this.#pattern : super.getAttribute(key);
29
- }
30
- /** @private */
31
- setAttribute(key, value) {
32
- if (key === 'pattern') {
33
- this.#pattern = value;
34
- }
35
- else {
36
- super.setAttribute(key, value);
37
- }
38
- }
39
- /**
40
- * @override
41
- * @param elements 待替换的子节点
42
- */
43
- replaceChildren(...elements) {
44
- if (debug_1.Shadow.running || this.#pattern.test((0, string_1.text)(elements))) {
45
- debug_1.Shadow.run(() => {
46
- super.replaceChildren(...elements);
47
- });
48
- }
49
- }
50
- }
51
- return SyntaxToken;
52
- };
53
- exports.syntax = syntax;
54
- constants_1.mixins['syntax'] = __filename;
@@ -1,128 +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[stack.length - 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
- /**
29
- * 填入模板内容
30
- * @param text wikitext全文
31
- */
32
- const push = (text) => {
33
- parts[parts.length - 1].push(text.slice(topPos, curIndex));
34
- };
35
- if (syntax === ']]' || syntax === '}-') { // 情形1:闭合内链或转换
36
- lastIndex = curIndex + 2;
37
- }
38
- else if (syntax === '\n') { // 情形2:闭合标题或文末
39
- lastIndex = curIndex + 1;
40
- const { pos, findEqual } = stack[stack.length - 1] ?? {};
41
- if (pos === undefined || findEqual || (0, string_1.removeComment)(wikitext.slice(pos, index)) !== '') {
42
- const rmt = /^(={1,6})(.+)\1((?:\s|\0\d+c\x7F)*)$/u
43
- .exec(wikitext.slice(index, curIndex));
44
- if (rmt) {
45
- wikitext = `${wikitext.slice(0, index)}\0${accum.length}h\x7F${wikitext.slice(curIndex)}`;
46
- lastIndex = index + 4 + String(accum.length).length;
47
- new heading_1.HeadingToken(rmt[1].length, rmt.slice(2), config, accum);
48
- }
49
- }
50
- }
51
- else if (syntax === '|' || innerEqual) { // 情形3:模板内部,含行首单个'='
52
- lastIndex = curIndex + 1;
53
- push(wikitext);
54
- if (syntax === '|') {
55
- parts.push([]);
56
- }
57
- top.pos = lastIndex;
58
- top.findEqual = syntax === '|';
59
- stack.push(top);
60
- }
61
- else if (syntax.startsWith('}}')) { // 情形4:闭合模板
62
- const close = syntax.slice(0, Math.min(open.length, 3)), rest = open.length - close.length, { length } = accum;
63
- lastIndex = curIndex + close.length; // 这不是最终的lastIndex
64
- push(wikitext);
65
- let skip = false, ch = 't';
66
- if (close.length === 3) {
67
- const argParts = parts.map(part => part.join('=')), str = argParts.length > 1 && (0, string_1.removeComment)(argParts[1]).trim();
68
- new arg_1.ArgToken(argParts, config, accum);
69
- if (str && str.endsWith(':') && subst.includes(str.slice(0, -1).toLowerCase())) {
70
- ch = 's';
71
- }
72
- }
73
- else {
74
- try {
75
- new transclude_1.TranscludeToken(parts[0][0], parts.slice(1), config, accum);
76
- const name = (0, string_1.removeComment)(parts[0][0]).trim();
77
- if (marks.has(name)) {
78
- ch = marks.get(name); // 标记{{!}}等
79
- }
80
- else if (/^(?:filepath|(?:full|canonical)urle?):.|^server$/iu.test(name)) {
81
- ch = 'm';
82
- }
83
- else if (/^#vardefine:./iu.test(name)) {
84
- ch = 'c';
85
- }
86
- }
87
- catch (e) {
88
- if (e instanceof SyntaxError && e.message.startsWith('非法的模板名称:')) {
89
- skip = true;
90
- }
91
- else {
92
- throw e;
93
- }
94
- }
95
- }
96
- if (!skip) {
97
- wikitext = `${wikitext.slice(0, index + rest)}\0${length}${ch}\x7F${wikitext.slice(lastIndex)}`;
98
- lastIndex = index + rest + 3 + String(length).length;
99
- if (rest > 1) {
100
- stack.push({ 0: open.slice(0, rest), index: index, pos: index + rest, parts: [[]] });
101
- }
102
- else if (rest === 1 && wikitext[index - 1] === '-') {
103
- stack.push({ 0: '-{', index: index - 1, pos: index + 1, parts: [[]] });
104
- }
105
- }
106
- }
107
- else { // 情形5:开启
108
- lastIndex = curIndex + syntax.length;
109
- if (syntax.startsWith('{')) {
110
- mt.pos = lastIndex;
111
- mt.parts = [[]];
112
- }
113
- stack.push(...'0' in top ? [top] : [], mt);
114
- }
115
- moreBraces &&= wikitext.slice(lastIndex).includes('}}');
116
- let curTop = stack[stack.length - 1];
117
- if (!moreBraces && curTop?.[0]?.startsWith('{')) {
118
- stack.pop();
119
- curTop = stack[stack.length - 1];
120
- }
121
- regex = new RegExp(source + (curTop ? `|${closes[curTop[0][0]]}${curTop.findEqual ? '|=' : ''}` : ''), 'gmu');
122
- regex.lastIndex = lastIndex;
123
- mt = regex.exec(wikitext);
124
- }
125
- return wikitext;
126
- };
127
- exports.parseBraces = parseBraces;
128
- constants_1.parsers['parseBraces'] = __filename;
@@ -1,80 +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
- /** 更新`<onlyinclude>`和`</onlyinclude>`的位置 */
21
- const update = () => {
22
- const i = wikitext.indexOf(onlyincludeLeft);
23
- return { i, j: wikitext.indexOf(onlyincludeRight, i + length) };
24
- };
25
- if (includeOnly) {
26
- let { i, j } = update();
27
- if (i !== -1 && j !== -1) { // `<onlyinclude>`拥有最高优先级
28
- let str = '';
29
- /**
30
- * 忽略未被`<onlyinclude>`和`</onlyinclude>`包裹的内容
31
- * @param text 未被包裹的内容
32
- */
33
- const noinclude = (text) => {
34
- new noinclude_1.NoincludeToken(text, config, accum);
35
- str += `\0${accum.length - 1}c\x7F`;
36
- };
37
- while (i !== -1 && j !== -1) {
38
- const token = `\0${accum.length}e\x7F`;
39
- new onlyinclude_1.OnlyincludeToken(wikitext.slice(i + length, j), config, accum);
40
- if (i > 0) {
41
- noinclude(wikitext.slice(0, i));
42
- }
43
- str += token;
44
- wikitext = wikitext.slice(j + length + 1);
45
- ({ i, j } = update());
46
- }
47
- if (wikitext) {
48
- noinclude(wikitext);
49
- }
50
- return str;
51
- }
52
- }
53
- const ext = config.ext.join('|'), noincludeRegex = includeOnly ? 'includeonly' : '(?:no|only)include', includeRegex = includeOnly ? 'noinclude' : 'includeonly', regex = new RegExp('<!--.*?(?:-->|$)' // comment
54
- + '|'
55
- + `<${noincludeRegex}(?:\\s[^>]*?)?>|</${noincludeRegex}\\s*>` // <noinclude>
56
- + '|'
57
- + `<(${ext})(\\s[^>]*?)?(?:/>|>(.*?)</(\\1\\s*)>)` // 扩展标签
58
- + '|'
59
- + `<(${includeRegex})(\\s[^>]*?)?(?:/>|>(.*?)(?:</(${includeRegex}\\s*)>|$))`, // <includeonly>
60
- 'gisu');
61
- return wikitext.replace(regex, (substr, name, attr, inner, closing, include, includeAttr, includeInner, includeClosing) => {
62
- const str = `\0${accum.length}${name ? 'e' : 'c'}\x7F`;
63
- if (name) {
64
- new ext_1.ExtToken(name, attr, inner, closing, config, accum);
65
- }
66
- else if (substr.startsWith('<!--')) {
67
- const closed = substr.endsWith('-->');
68
- new comment_1.CommentToken(substr.slice(4, closed ? -3 : undefined), closed, config, accum);
69
- }
70
- else if (include) {
71
- new include_1.IncludeToken(include, includeAttr, includeInner, includeClosing, config, accum);
72
- }
73
- else {
74
- new noinclude_1.NoincludeToken(substr, config, accum);
75
- }
76
- return str;
77
- });
78
- };
79
- exports.parseCommentAndExt = parseCommentAndExt;
80
- 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)], temp = raw.replace(/(&[#a-z\d]+);/giu, '$1\x01'), variants = `(?:${config.variants.join('|')})`, rules = temp.split(new RegExp(`;(?=\\s*(?:${`(?:${variants}|[^;]*?=>\\s*${variants})\\s*:`
20
- + '|'
21
- + '(?:\0\\d+c\x7f(?:\\s|\0\\d+c\x7f)*)?$' // 末尾的空白
22
- }))`, 'u')).map(rule => rule.replace(/\x01/gu, ';'));
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;