wikiparser-node 1.3.8 → 1.3.9-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 (155) 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/i18n/zh-hans.json +6 -1
  12. package/i18n/zh-hant.json +6 -1
  13. package/package.json +31 -13
  14. package/config/.schema.json +0 -172
  15. package/dist/addon/table.d.ts +0 -6
  16. package/dist/addon/table.js +0 -558
  17. package/dist/base.d.ts +0 -45
  18. package/dist/index.d.ts +0 -32
  19. package/dist/index.js +0 -209
  20. package/dist/internal.d.ts +0 -44
  21. package/dist/lib/element.d.ts +0 -154
  22. package/dist/lib/element.js +0 -630
  23. package/dist/lib/node.d.ts +0 -146
  24. package/dist/lib/node.js +0 -419
  25. package/dist/lib/range.d.ts +0 -104
  26. package/dist/lib/range.js +0 -385
  27. package/dist/lib/ranges.d.ts +0 -26
  28. package/dist/lib/ranges.js +0 -118
  29. package/dist/lib/text.d.ts +0 -62
  30. package/dist/lib/text.js +0 -255
  31. package/dist/lib/title.d.ts +0 -38
  32. package/dist/lib/title.js +0 -163
  33. package/dist/mixin/attributesParent.js +0 -89
  34. package/dist/mixin/fixed.js +0 -25
  35. package/dist/mixin/flagsParent.js +0 -70
  36. package/dist/mixin/hidden.js +0 -25
  37. package/dist/mixin/magicLinkParent.js +0 -41
  38. package/dist/mixin/singleLine.js +0 -25
  39. package/dist/mixin/sol.js +0 -43
  40. package/dist/mixin/syntax.js +0 -54
  41. package/dist/parser/braces.js +0 -128
  42. package/dist/parser/commentAndExt.js +0 -85
  43. package/dist/parser/converter.js +0 -40
  44. package/dist/parser/externalLinks.js +0 -31
  45. package/dist/parser/hrAndDoubleUnderscore.js +0 -38
  46. package/dist/parser/html.js +0 -36
  47. package/dist/parser/links.js +0 -94
  48. package/dist/parser/list.js +0 -66
  49. package/dist/parser/magicLinks.js +0 -42
  50. package/dist/parser/quotes.js +0 -67
  51. package/dist/parser/selector.js +0 -162
  52. package/dist/parser/table.js +0 -120
  53. package/dist/src/arg.d.ts +0 -58
  54. package/dist/src/arg.js +0 -194
  55. package/dist/src/atom.d.ts +0 -12
  56. package/dist/src/atom.js +0 -27
  57. package/dist/src/attribute.d.ts +0 -88
  58. package/dist/src/attribute.js +0 -399
  59. package/dist/src/attributes.d.ts +0 -109
  60. package/dist/src/attributes.js +0 -343
  61. package/dist/src/converter.d.ts +0 -53
  62. package/dist/src/converter.js +0 -79
  63. package/dist/src/converterFlags.d.ts +0 -87
  64. package/dist/src/converterFlags.js +0 -224
  65. package/dist/src/converterRule.d.ts +0 -77
  66. package/dist/src/converterRule.js +0 -208
  67. package/dist/src/extLink.d.ts +0 -55
  68. package/dist/src/extLink.js +0 -122
  69. package/dist/src/gallery.d.ts +0 -54
  70. package/dist/src/gallery.js +0 -121
  71. package/dist/src/heading.d.ts +0 -78
  72. package/dist/src/heading.js +0 -134
  73. package/dist/src/hidden.d.ts +0 -23
  74. package/dist/src/hidden.js +0 -23
  75. package/dist/src/html.d.ts +0 -106
  76. package/dist/src/html.js +0 -234
  77. package/dist/src/imageParameter.d.ts +0 -65
  78. package/dist/src/imageParameter.js +0 -247
  79. package/dist/src/imagemap.d.ts +0 -56
  80. package/dist/src/imagemap.js +0 -147
  81. package/dist/src/imagemapLink.d.ts +0 -61
  82. package/dist/src/imagemapLink.js +0 -40
  83. package/dist/src/index.d.ts +0 -140
  84. package/dist/src/index.js +0 -769
  85. package/dist/src/link/base.d.ts +0 -52
  86. package/dist/src/link/base.js +0 -209
  87. package/dist/src/link/category.d.ts +0 -13
  88. package/dist/src/link/category.js +0 -29
  89. package/dist/src/link/file.d.ts +0 -96
  90. package/dist/src/link/file.js +0 -256
  91. package/dist/src/link/galleryImage.d.ts +0 -45
  92. package/dist/src/link/galleryImage.js +0 -106
  93. package/dist/src/link/index.d.ts +0 -53
  94. package/dist/src/link/index.js +0 -124
  95. package/dist/src/magicLink.d.ts +0 -69
  96. package/dist/src/magicLink.js +0 -147
  97. package/dist/src/nested.d.ts +0 -43
  98. package/dist/src/nested.js +0 -86
  99. package/dist/src/nowiki/base.d.ts +0 -48
  100. package/dist/src/nowiki/base.js +0 -42
  101. package/dist/src/nowiki/comment.d.ts +0 -43
  102. package/dist/src/nowiki/comment.js +0 -74
  103. package/dist/src/nowiki/dd.d.ts +0 -8
  104. package/dist/src/nowiki/dd.js +0 -25
  105. package/dist/src/nowiki/doubleUnderscore.d.ts +0 -47
  106. package/dist/src/nowiki/doubleUnderscore.js +0 -50
  107. package/dist/src/nowiki/hr.d.ts +0 -33
  108. package/dist/src/nowiki/hr.js +0 -14
  109. package/dist/src/nowiki/index.d.ts +0 -16
  110. package/dist/src/nowiki/index.js +0 -21
  111. package/dist/src/nowiki/list.d.ts +0 -31
  112. package/dist/src/nowiki/list.js +0 -48
  113. package/dist/src/nowiki/listBase.d.ts +0 -20
  114. package/dist/src/nowiki/listBase.js +0 -12
  115. package/dist/src/nowiki/noinclude.d.ts +0 -26
  116. package/dist/src/nowiki/noinclude.js +0 -24
  117. package/dist/src/nowiki/quote.d.ts +0 -24
  118. package/dist/src/nowiki/quote.js +0 -45
  119. package/dist/src/onlyinclude.d.ts +0 -16
  120. package/dist/src/onlyinclude.js +0 -57
  121. package/dist/src/paramTag/index.d.ts +0 -37
  122. package/dist/src/paramTag/index.js +0 -68
  123. package/dist/src/paramTag/inputbox.d.ts +0 -8
  124. package/dist/src/paramTag/inputbox.js +0 -23
  125. package/dist/src/parameter.d.ts +0 -88
  126. package/dist/src/parameter.js +0 -214
  127. package/dist/src/pre.d.ts +0 -28
  128. package/dist/src/pre.js +0 -51
  129. package/dist/src/syntax.d.ts +0 -30
  130. package/dist/src/syntax.js +0 -34
  131. package/dist/src/table/base.d.ts +0 -59
  132. package/dist/src/table/base.js +0 -78
  133. package/dist/src/table/index.d.ts +0 -230
  134. package/dist/src/table/index.js +0 -386
  135. package/dist/src/table/td.d.ts +0 -109
  136. package/dist/src/table/td.js +0 -270
  137. package/dist/src/table/tr.d.ts +0 -32
  138. package/dist/src/table/tr.js +0 -56
  139. package/dist/src/table/trBase.d.ts +0 -53
  140. package/dist/src/table/trBase.js +0 -153
  141. package/dist/src/tagPair/ext.d.ts +0 -57
  142. package/dist/src/tagPair/ext.js +0 -134
  143. package/dist/src/tagPair/include.d.ts +0 -56
  144. package/dist/src/tagPair/include.js +0 -70
  145. package/dist/src/tagPair/index.d.ts +0 -45
  146. package/dist/src/tagPair/index.js +0 -76
  147. package/dist/src/transclude.d.ts +0 -167
  148. package/dist/src/transclude.js +0 -693
  149. package/dist/util/constants.js +0 -113
  150. package/dist/util/debug.js +0 -83
  151. package/dist/util/diff.js +0 -72
  152. package/dist/util/lint.js +0 -30
  153. package/dist/util/string.js +0 -51
  154. package/errors/README +0 -1
  155. package/printed/README +0 -1
@@ -1,66 +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
- /**
27
- * 创建`DdToken`
28
- * @param syntax `:`
29
- * @param index 起点
30
- */
31
- const dd = (syntax, index) => {
32
- new dd_1.DdToken(syntax, config, accum);
33
- return `${text.slice(0, index)}\0${accum.length - 1}d\x7F${text.slice(index + syntax.length)}`;
34
- };
35
- while (ex && dt) {
36
- const { 0: syntax, index } = ex;
37
- if (syntax.startsWith(':')) {
38
- if (syntax.length >= dt) {
39
- return dd(syntax.slice(0, dt), index);
40
- }
41
- dt -= syntax.length;
42
- regex.lastIndex = index + 4 + String(accum.length).length;
43
- text = dd(syntax, index);
44
- }
45
- else if (syntax === '-{') {
46
- if (!lc) {
47
- const { lastIndex } = regex;
48
- regex = /-\{|\}-/gu;
49
- regex.lastIndex = lastIndex;
50
- }
51
- lc++;
52
- }
53
- else {
54
- lc--;
55
- if (!lc) {
56
- const { lastIndex } = regex;
57
- regex = /:+|-\{/gu;
58
- regex.lastIndex = lastIndex;
59
- }
60
- }
61
- ex = regex.exec(text);
62
- }
63
- return text;
64
- };
65
- exports.parseList = parseList;
66
- constants_1.parsers['parseList'] = __filename;
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseMagicLinks = void 0;
4
- const string_1 = require("../util/string");
5
- const constants_1 = require("../util/constants");
6
- const Parser = require("../index");
7
- const magicLink_1 = require("../src/magicLink");
8
- /**
9
- * 解析自由外链
10
- * @param wikitext
11
- * @param config
12
- * @param accum
13
- */
14
- const parseMagicLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
15
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
16
- /(^|[^\p{L}\d_])((?:\[[\da-f:.]+\]|[^[\]<>"\t\n\p{Zs}])(?:[^[\]<>"\0\t\n\p{Zs}]|\0\d+c\x7F)*)/giu;
17
- const regex = new RegExp(`(^|[^\\p{L}\\d_])(?:${config.protocol})(${string_1.extUrlCharFirst}${string_1.extUrlChar})`, 'giu');
18
- return wikitext.replace(regex, (m, lead, p1) => {
19
- let trail = '', url = lead ? m.slice(1) : m;
20
- const m2 = /&(?:lt|gt|nbsp|#x0*(?:3[ce]|a0)|#0*(?:6[02]|160));/iu.exec(url);
21
- if (m2) {
22
- trail = url.slice(m2.index);
23
- url = url.slice(0, m2.index);
24
- }
25
- const sep = new RegExp(`[,;.:!?${url.includes('(') ? '' : ')'}]+$`, 'u'), sepChars = sep.exec(url);
26
- if (sepChars) {
27
- let correction = 0;
28
- if (sepChars[0].startsWith(';') && /&(?:[a-z]+|#x[\da-f]+|#\d+)$/iu.test(url.slice(0, sepChars.index))) {
29
- correction = 1;
30
- }
31
- trail = `${url.slice(sepChars.index + correction)}${trail}`;
32
- url = url.slice(0, sepChars.index + correction);
33
- }
34
- if (trail.length >= p1.length) {
35
- return m;
36
- }
37
- new magicLink_1.MagicLinkToken(url, false, config, accum);
38
- return `${lead}\0${accum.length - 1}w\x7F${trail}`;
39
- });
40
- };
41
- exports.parseMagicLinks = parseMagicLinks;
42
- constants_1.parsers['parseMagicLinks'] = __filename;
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseQuotes = void 0;
4
- const constants_1 = require("../util/constants");
5
- const Parser = require("../index");
6
- const quote_1 = require("../src/nowiki/quote");
7
- /**
8
- * 解析单引号
9
- * @param wikitext
10
- * @param config
11
- * @param accum
12
- */
13
- const parseQuotes = (wikitext, config = Parser.getConfig(), accum = []) => {
14
- const arr = wikitext.split(/('{2,})/u), { length } = arr;
15
- if (length === 1) {
16
- return wikitext;
17
- }
18
- let nBold = 0, nItalic = 0, firstSingle, firstMulti, firstSpace;
19
- for (let i = 1; i < length; i += 2) {
20
- const { length: len } = arr[i];
21
- switch (len) {
22
- case 2:
23
- nItalic++;
24
- break;
25
- case 4:
26
- arr[i - 1] += `'`;
27
- arr[i] = `'''`;
28
- // fall through
29
- case 3:
30
- nBold++;
31
- if (firstSingle !== undefined) {
32
- break;
33
- }
34
- else if (arr[i - 1].endsWith(' ')) {
35
- if (firstMulti === undefined && firstSpace === undefined) {
36
- firstSpace = i;
37
- }
38
- }
39
- else if (arr[i - 1].slice(-2, -1) === ' ') {
40
- firstSingle = i;
41
- }
42
- else {
43
- firstMulti ??= i;
44
- }
45
- break;
46
- default:
47
- arr[i - 1] += `'`.repeat(len - 5);
48
- arr[i] = `'''''`;
49
- nItalic++;
50
- nBold++;
51
- }
52
- }
53
- if (nItalic % 2 === 1 && nBold % 2 === 1) {
54
- const i = firstSingle ?? firstMulti ?? firstSpace;
55
- if (i !== undefined) {
56
- arr[i] = `''`;
57
- arr[i - 1] += `'`;
58
- }
59
- }
60
- for (let i = 1; i < length; i += 2) {
61
- new quote_1.QuoteToken(arr[i], config, accum);
62
- arr[i] = `\0${accum.length - 1}q\x7F`;
63
- }
64
- return arr.join('');
65
- };
66
- exports.parseQuotes = parseQuotes;
67
- constants_1.parsers['parseQuotes'] = __filename;
@@ -1,162 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseSelector = void 0;
4
- const constants_1 = require("../util/constants");
5
- const string_1 = require("../util/string");
6
- const Parser = require("../index");
7
- const simplePseudos = new Set([
8
- 'root',
9
- 'first-child',
10
- 'first-of-type',
11
- 'last-child',
12
- 'last-of-type',
13
- 'only-child',
14
- 'only-of-type',
15
- 'empty',
16
- 'parent',
17
- 'header',
18
- 'hidden',
19
- 'visible',
20
- 'only-whitespace',
21
- 'any-link',
22
- 'local-link',
23
- 'invalid',
24
- 'required',
25
- 'optional',
26
- ]);
27
- const complexPseudos = [
28
- 'is',
29
- 'not',
30
- 'nth-child',
31
- 'nth-of-type',
32
- 'nth-last-child',
33
- 'nth-last-of-type',
34
- 'contains',
35
- 'has',
36
- 'lang',
37
- 'regex',
38
- ];
39
- const specialChars = [
40
- ['[', '&lbrack;'],
41
- [']', '&rbrack;'],
42
- ['(', '&lpar;'],
43
- [')', '&rpar;'],
44
- ['"', '&quot;'],
45
- [`'`, '&apos;'],
46
- [':', '&colon;'],
47
- ['\\', '&bsol;'],
48
- ['&', '&amp;'],
49
- ];
50
- const pseudoRegex = new RegExp(`:(${complexPseudos.join('|')})$`, 'u'), regularRegex = /[[(,>+~]|\s+/u, attributeRegex = /^\s*(\w+)\s*(?:([~|^$*!]?=)\s*("[^"]*"|'[^']*'|[^\s[\]]+)(?:\s+(i))?\s*)?\]/u, functionRegex = /^(\s*"[^"]*"\s*|\s*'[^']*'\s*|[^()]*)\)/u, grouping = new Set([',', '>', '+', '~']), combinator = new Set(['>', '+', '~', '']);
51
- /**
52
- * 清理转义符号
53
- * @param selector
54
- */
55
- const sanitize = (selector) => {
56
- for (const [c, escaped] of specialChars) {
57
- selector = selector.replace(new RegExp((0, string_1.escapeRegExp)(`\\${c}`), 'gu'), escaped);
58
- }
59
- return selector;
60
- };
61
- /**
62
- * 还原转义符号
63
- * @param selector
64
- */
65
- const desanitize = (selector) => {
66
- for (const [c, escaped] of specialChars) {
67
- selector = selector.replace(new RegExp(escaped, 'gu'), c);
68
- }
69
- return selector.trim();
70
- };
71
- /**
72
- * 去除首尾的引号
73
- * @param val 属性值或伪选择器函数的参数
74
- */
75
- const deQuote = (val) => /^(["']).*\1$/u.test(val) ? val.slice(1, -1) : val.trim();
76
- /**
77
- * 解析选择器
78
- * @param selector
79
- * @throws `SyntaxError` 非法的选择器
80
- */
81
- const parseSelector = (selector) => {
82
- selector = selector.trim();
83
- const stack = [[[]]];
84
- let sanitized = sanitize(selector), regex = regularRegex, mt = regex.exec(sanitized), [condition] = stack, [step] = condition;
85
- /**
86
- * 解析简单伪选择器
87
- * @param index 伪选择器的终点位置
88
- * @throws `SyntaxError` 非法的选择器
89
- */
90
- const pushSimple = (index) => {
91
- const str = sanitized.slice(0, index), pieces = str.trim().split(':'),
92
- // eslint-disable-next-line unicorn/explicit-length-check
93
- i = pieces.slice(1).findIndex(pseudo => simplePseudos.has(pseudo)) + 1 || pieces.length;
94
- if (pieces.slice(i).some(pseudo => !simplePseudos.has(pseudo))) {
95
- throw new SyntaxError(`非法的选择器!\n${str}\n可能需要将':'转义为'\\:'。`);
96
- }
97
- step.push(desanitize(pieces.slice(0, i).join(':')), ...pieces.slice(i).map(piece => `:${piece}`));
98
- };
99
- while (mt) {
100
- let { 0: syntax, index } = mt;
101
- if (syntax.trim() === '') {
102
- index += syntax.length;
103
- const char = sanitized[index];
104
- syntax = grouping.has(char) ? char : '';
105
- }
106
- if (syntax === ',') { // 情形1:并列
107
- pushSimple(index);
108
- condition = [[]];
109
- [step] = condition;
110
- stack.push(condition);
111
- }
112
- else if (combinator.has(syntax)) { // 情形2:关系
113
- pushSimple(index);
114
- if (!step.some(Boolean)) {
115
- throw new SyntaxError(`非法的选择器!\n${selector}\n可能需要通用选择器'*'。`);
116
- }
117
- step.relation = syntax;
118
- step = [];
119
- condition.push(step);
120
- }
121
- else if (syntax === '[') { // 情形3:属性开启
122
- pushSimple(index);
123
- regex = attributeRegex;
124
- }
125
- else if (syntax.endsWith(']')) { // 情形4:属性闭合
126
- mt[3] &&= desanitize(deQuote(mt[3]));
127
- step.push(mt.slice(1));
128
- regex = regularRegex;
129
- }
130
- else if (syntax === '(') { // 情形5:伪选择器开启
131
- const pseudoExec = pseudoRegex.exec(sanitized.slice(0, index));
132
- if (!pseudoExec) {
133
- throw new SyntaxError(`非法的选择器!\n${desanitize(sanitized)}\n请检查伪选择器是否存在。`);
134
- }
135
- pushSimple(pseudoExec.index);
136
- step.push(pseudoExec[1]); // 临时存放复杂伪选择器
137
- regex = functionRegex;
138
- }
139
- else { // 情形6:伪选择器闭合
140
- mt.push(step.pop());
141
- mt[1] &&= deQuote(mt[1]);
142
- step.push(mt.slice(1));
143
- regex = regularRegex;
144
- }
145
- sanitized = sanitized.slice(index + syntax.length);
146
- if (grouping.has(syntax)) {
147
- sanitized = sanitized.trim();
148
- }
149
- mt = regex.exec(sanitized);
150
- }
151
- if (regex === regularRegex) {
152
- pushSimple(Infinity);
153
- const pseudos = new Set(stack.flat(2).filter((e) => typeof e === 'string' && e.startsWith(':')));
154
- if (pseudos.size > 0) {
155
- Parser.warn('检测到伪选择器,请确认是否需要将":"转义成"\\:"。', pseudos);
156
- }
157
- return stack;
158
- }
159
- throw new SyntaxError(`非法的选择器!\n${selector}\n检测到未闭合的'${regex === attributeRegex ? '[' : '('}'`);
160
- };
161
- exports.parseSelector = parseSelector;
162
- constants_1.parsers['parseSelector'] = __filename;
@@ -1,120 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseTable = void 0;
4
- const constants_1 = require("../util/constants");
5
- const Parser = require("../index");
6
- const index_1 = require("../src/index");
7
- const index_2 = require("../src/table/index");
8
- const tr_1 = require("../src/table/tr");
9
- const td_1 = require("../src/table/td");
10
- const dd_1 = require("../src/nowiki/dd");
11
- /**
12
- * 判断是否为表格行或表格
13
- * @param token 表格节点
14
- */
15
- const isTr = (token) => token.lastChild.constructor !== index_1.Token;
16
- /**
17
- * 解析表格,注意`tr`和`td`包含开头的换行
18
- * @param {Token & {firstChild: AstText}} root 根节点
19
- * @param config
20
- * @param accum
21
- */
22
- const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getConfig(), accum = []) => {
23
- const stack = [], lines = data.split('\n');
24
- let out = type === 'root' || type === 'parameter-value' || type === 'ext-inner' && name === 'poem'
25
- ? ''
26
- : `\n${lines.shift()}`, top;
27
- /**
28
- * 向表格中插入纯文本
29
- * @param str 待插入的文本
30
- * @param topToken 当前解析的表格或表格行
31
- */
32
- const push = (str, topToken) => {
33
- if (!topToken) {
34
- out += str;
35
- return;
36
- }
37
- const { lastChild } = topToken;
38
- if (isTr(topToken)) {
39
- const token = new index_1.Token(str, config, accum);
40
- token.type = 'table-inter';
41
- token.setAttribute('stage', 3);
42
- topToken.insertAt(token);
43
- }
44
- else {
45
- lastChild.setText(String(lastChild) + str);
46
- }
47
- },
48
- /** 取出最近的表格行 */
49
- pop = () => top.type === 'td' ? stack.pop() : top;
50
- for (const outLine of lines) {
51
- top = stack.pop();
52
- const [spaces] = /^(?:\s|\0\d+c\x7F)*/u.exec(outLine), line = outLine.slice(spaces.length), matchesStart = /^(:*)((?:\s|\0\d+c\x7F)*)(\{\||\{(?:\0\d+c\x7F)*\0\d+!\x7F|\0\d+\{\x7F)(.*)$/u
53
- .exec(line);
54
- if (matchesStart) {
55
- while (top && top.type !== 'td') {
56
- top = stack.pop();
57
- }
58
- const [, indent, moreSpaces, tableSyntax, attr] = matchesStart;
59
- if (indent) {
60
- new dd_1.DdToken(indent, config, accum);
61
- }
62
- push(`\n${spaces}${indent && `\0${accum.length - 1}d\x7F`}${moreSpaces}\0${accum.length}b\x7F`, top);
63
- stack.push(...top ? [top] : [], new index_2.TableToken(tableSyntax, attr, config, accum));
64
- continue;
65
- }
66
- else if (!top) {
67
- out += `\n${outLine}`;
68
- continue;
69
- }
70
- // eslint-disable-next-line @stylistic/operator-linebreak
71
- const matches = /^(?:(\|\}|\0\d+!\x7F\}|\0\d+\}\x7F)|(\|-+|\0\d+!\x7F-+|\0\d+-\x7F-*)(?!-)|(!|(?:\||\0\d+!\x7F)\+?))(.*)$/u
72
- .exec(line);
73
- if (!matches) {
74
- push(`\n${outLine}`, top);
75
- stack.push(top);
76
- continue;
77
- }
78
- const [, closing, row, cell, attr] = matches;
79
- if (closing) {
80
- while (top.type !== 'table') {
81
- top = stack.pop();
82
- }
83
- top.close(`\n${spaces}${closing}`, true);
84
- push(attr, stack[stack.length - 1]);
85
- }
86
- else if (row) {
87
- top = pop();
88
- if (top.type === 'tr') {
89
- top = stack.pop();
90
- }
91
- const tr = new tr_1.TrToken(`\n${spaces}${row}`, attr, config, accum);
92
- stack.push(top, tr);
93
- top.insertAt(tr);
94
- }
95
- else {
96
- top = pop();
97
- const regex = cell === '!' ? /!!|(?:\||\0\d+!\x7F){2}|\0\d+\+\x7F/gu : /(?:\||\0\d+!\x7F){2}|\0\d+\+\x7F/gu;
98
- let mt = regex.exec(attr), lastIndex = 0, lastSyntax = `\n${spaces}${cell}`;
99
- /**
100
- * 创建表格单元格
101
- * @param tr 当前表格行
102
- */
103
- const createTd = (tr) => {
104
- const td = new td_1.TdToken(lastSyntax, attr.slice(lastIndex, mt?.index), config, accum);
105
- tr.insertAt(td);
106
- return td;
107
- };
108
- while (mt) {
109
- createTd(top);
110
- ({ lastIndex } = regex);
111
- [lastSyntax] = mt;
112
- mt = regex.exec(attr);
113
- }
114
- stack.push(top, createTd(top));
115
- }
116
- }
117
- return out.slice(1);
118
- };
119
- exports.parseTable = parseTable;
120
- constants_1.parsers['parseTable'] = __filename;
package/dist/src/arg.d.ts DELETED
@@ -1,58 +0,0 @@
1
- import * as Parser from '../index';
2
- import { Token } from './index';
3
- import { AtomToken } from './atom';
4
- import { HiddenToken } from './hidden';
5
- import type { LintError } from '../base';
6
- /**
7
- * `{{{}}}`包裹的参数
8
- * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
9
- */
10
- export declare class ArgToken extends Token {
11
- #private;
12
- readonly type = "arg";
13
- readonly name: string;
14
- readonly childNodes: [AtomToken] | [AtomToken, Token, ...HiddenToken[]];
15
- abstract get children(): [AtomToken] | [AtomToken, Token, ...HiddenToken[]];
16
- abstract get firstChild(): AtomToken;
17
- abstract get firstElementChild(): AtomToken;
18
- abstract get lastChild(): Token;
19
- abstract get lastElementChild(): Token;
20
- /** 预设值 */
21
- get default(): string | false;
22
- set default(value: string | false);
23
- /** @param parts 以'|'分隔的各部分 */
24
- constructor(parts: readonly string[], config?: Parser.Config, accum?: Token[]);
25
- /** @override */
26
- text(): string;
27
- /** @override */
28
- lint(start?: number): LintError[];
29
- /** @override */
30
- print(): string;
31
- /** @override */
32
- json(): object;
33
- /** @override */
34
- cloneNode(): this;
35
- /** 移除无效部分 */
36
- removeRedundant(): void;
37
- /**
38
- * @override
39
- * @param i 移除位置
40
- */
41
- removeAt(i: number): Token;
42
- /**
43
- * @override
44
- * @param token 待插入的子节点
45
- * @param i 插入位置
46
- */
47
- insertAt<T extends Token>(token: T, i?: number): T;
48
- /**
49
- * 设置参数名
50
- * @param name 新参数名
51
- */
52
- setName(name: string): void;
53
- /**
54
- * 设置预设值
55
- * @param value 预设值
56
- */
57
- setDefault(value: string | false): void;
58
- }