wikiparser-node 0.11.0 → 1.0.0-beta.1

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 (252) hide show
  1. package/config/.schema.json +26 -0
  2. package/dist/index.d.ts +61 -113
  3. package/dist/index.js +314 -0
  4. package/dist/lib/element.d.ts +122 -108
  5. package/dist/lib/element.js +656 -0
  6. package/dist/lib/node.d.ts +115 -221
  7. package/dist/lib/node.js +473 -0
  8. package/dist/lib/ranges.d.ts +27 -26
  9. package/dist/lib/ranges.js +130 -0
  10. package/dist/lib/text.d.ts +36 -28
  11. package/dist/lib/text.js +215 -0
  12. package/dist/lib/title.d.ts +26 -12
  13. package/dist/lib/title.js +108 -0
  14. package/dist/mixin/attributesParent.js +90 -0
  15. package/dist/mixin/fixed.js +29 -0
  16. package/dist/mixin/hidden.js +19 -0
  17. package/dist/mixin/singleLine.js +23 -0
  18. package/dist/mixin/sol.js +41 -0
  19. package/dist/parser/brackets.js +118 -0
  20. package/dist/parser/commentAndExt.js +48 -0
  21. package/dist/parser/converter.js +31 -0
  22. package/dist/parser/externalLinks.js +22 -0
  23. package/dist/parser/hrAndDoubleUnderscore.js +35 -0
  24. package/dist/parser/html.js +29 -0
  25. package/dist/parser/links.js +86 -0
  26. package/dist/parser/list.js +51 -0
  27. package/dist/parser/magicLinks.js +32 -0
  28. package/dist/parser/quotes.js +57 -0
  29. package/dist/parser/selector.js +158 -0
  30. package/dist/parser/table.js +108 -0
  31. package/dist/src/arg.d.ts +47 -23
  32. package/dist/src/arg.js +196 -0
  33. package/dist/src/atom.d.ts +12 -0
  34. package/dist/src/atom.js +22 -0
  35. package/dist/src/attribute.d.ts +74 -33
  36. package/dist/src/attribute.js +433 -0
  37. package/dist/src/attributes.d.ts +61 -55
  38. package/dist/src/attributes.js +371 -0
  39. package/dist/src/converter.d.ts +45 -71
  40. package/dist/src/converter.js +135 -0
  41. package/dist/src/converterFlags.d.ts +64 -39
  42. package/dist/src/converterFlags.js +235 -0
  43. package/dist/src/converterRule.d.ts +49 -27
  44. package/dist/src/converterRule.js +255 -0
  45. package/dist/src/extLink.d.ts +41 -38
  46. package/dist/src/extLink.js +154 -0
  47. package/dist/src/gallery.d.ts +59 -18
  48. package/dist/src/gallery.js +132 -0
  49. package/dist/src/heading.d.ts +60 -22
  50. package/dist/src/heading.js +135 -0
  51. package/dist/src/hidden.d.ts +20 -0
  52. package/dist/src/hidden.js +24 -0
  53. package/dist/src/html.d.ts +83 -29
  54. package/dist/src/html.js +242 -0
  55. package/dist/src/imageParameter.d.ts +59 -40
  56. package/dist/src/imageParameter.js +251 -0
  57. package/dist/src/imagemap.d.ts +65 -21
  58. package/dist/src/imagemap.js +169 -0
  59. package/dist/src/imagemapLink.d.ts +46 -14
  60. package/dist/src/imagemapLink.js +38 -0
  61. package/dist/src/index.d.ts +71 -105
  62. package/dist/src/index.js +826 -0
  63. package/dist/src/link/base.d.ts +71 -0
  64. package/dist/src/link/base.js +225 -0
  65. package/dist/src/link/category.d.ts +10 -11
  66. package/dist/src/link/category.js +26 -0
  67. package/dist/src/link/file.d.ts +61 -39
  68. package/dist/src/link/file.js +242 -0
  69. package/dist/src/link/galleryImage.d.ts +34 -12
  70. package/dist/src/link/galleryImage.js +98 -0
  71. package/dist/src/link/index.d.ts +25 -63
  72. package/dist/src/link/index.js +136 -0
  73. package/dist/src/magicLink.d.ts +22 -15
  74. package/dist/src/magicLink.js +126 -0
  75. package/dist/src/nested.d.ts +47 -0
  76. package/dist/src/nested.js +84 -0
  77. package/dist/src/nowiki/base.d.ts +39 -0
  78. package/dist/src/nowiki/base.js +29 -0
  79. package/dist/src/nowiki/comment.d.ts +31 -20
  80. package/dist/src/nowiki/comment.js +61 -0
  81. package/dist/src/nowiki/dd.d.ts +17 -11
  82. package/dist/src/nowiki/dd.js +50 -0
  83. package/dist/src/nowiki/doubleUnderscore.d.ts +28 -13
  84. package/dist/src/nowiki/doubleUnderscore.js +45 -0
  85. package/dist/src/nowiki/hr.d.ts +28 -10
  86. package/dist/src/nowiki/hr.js +33 -0
  87. package/dist/src/nowiki/index.d.ts +17 -23
  88. package/dist/src/nowiki/index.js +21 -0
  89. package/dist/src/nowiki/list.d.ts +15 -7
  90. package/dist/src/nowiki/list.js +11 -0
  91. package/dist/src/nowiki/noinclude.d.ts +20 -7
  92. package/dist/src/nowiki/noinclude.js +22 -0
  93. package/dist/src/nowiki/quote.d.ts +25 -10
  94. package/dist/src/nowiki/quote.js +55 -0
  95. package/dist/src/onlyinclude.d.ts +28 -12
  96. package/dist/src/onlyinclude.js +64 -0
  97. package/dist/src/paramTag/index.d.ts +40 -17
  98. package/dist/src/paramTag/index.js +76 -0
  99. package/dist/src/paramTag/inputbox.d.ts +8 -7
  100. package/dist/src/paramTag/inputbox.js +19 -0
  101. package/dist/src/parameter.d.ts +62 -41
  102. package/dist/src/parameter.js +201 -0
  103. package/dist/src/pre.d.ts +32 -0
  104. package/dist/src/pre.js +39 -0
  105. package/dist/src/syntax.d.ts +17 -14
  106. package/dist/src/syntax.js +65 -0
  107. package/dist/src/table/base.d.ts +55 -0
  108. package/dist/src/table/base.js +77 -0
  109. package/dist/src/table/index.d.ts +123 -156
  110. package/dist/src/table/index.js +811 -0
  111. package/dist/src/table/td.d.ts +90 -67
  112. package/dist/src/table/td.js +276 -0
  113. package/dist/src/table/tr.d.ts +30 -85
  114. package/dist/src/table/tr.js +48 -0
  115. package/dist/src/table/trBase.d.ts +72 -0
  116. package/dist/src/table/trBase.js +153 -0
  117. package/dist/src/tagPair/ext.d.ts +47 -11
  118. package/dist/src/tagPair/ext.js +127 -0
  119. package/dist/src/tagPair/include.d.ts +32 -13
  120. package/dist/src/tagPair/include.js +40 -0
  121. package/dist/src/tagPair/index.d.ts +44 -29
  122. package/dist/src/tagPair/index.js +111 -0
  123. package/dist/src/transclude.d.ts +88 -85
  124. package/dist/src/transclude.js +739 -0
  125. package/dist/util/base.js +26 -0
  126. package/dist/util/debug.js +52 -0
  127. package/dist/util/diff.js +69 -0
  128. package/dist/util/lint.js +38 -0
  129. package/dist/util/string.js +103 -0
  130. package/errors/README +1 -0
  131. package/i18n/zh-hans.json +1 -0
  132. package/i18n/zh-hant.json +1 -0
  133. package/package.json +21 -24
  134. package/printed/README +1 -0
  135. package/dist/mixin/attributeParent.d.ts +0 -9
  136. package/dist/mixin/fixedToken.d.ts +0 -8
  137. package/dist/mixin/hidden.d.ts +0 -8
  138. package/dist/mixin/singleLine.d.ts +0 -8
  139. package/dist/mixin/sol.d.ts +0 -8
  140. package/dist/parser/brackets.d.ts +0 -12
  141. package/dist/parser/commentAndExt.d.ts +0 -8
  142. package/dist/parser/converter.d.ts +0 -7
  143. package/dist/parser/externalLinks.d.ts +0 -7
  144. package/dist/parser/hrAndDoubleUnderscore.d.ts +0 -11
  145. package/dist/parser/html.d.ts +0 -7
  146. package/dist/parser/links.d.ts +0 -7
  147. package/dist/parser/list.d.ts +0 -7
  148. package/dist/parser/magicLinks.d.ts +0 -7
  149. package/dist/parser/quotes.d.ts +0 -7
  150. package/dist/parser/selector.d.ts +0 -12
  151. package/dist/parser/table.d.ts +0 -11
  152. package/dist/src/atom/hidden.d.ts +0 -5
  153. package/dist/src/atom/index.d.ts +0 -15
  154. package/dist/src/charinsert.d.ts +0 -32
  155. package/dist/src/hasNowiki/index.d.ts +0 -14
  156. package/dist/src/hasNowiki/pre.d.ts +0 -13
  157. package/dist/src/nested/choose.d.ts +0 -13
  158. package/dist/src/nested/combobox.d.ts +0 -13
  159. package/dist/src/nested/index.d.ts +0 -18
  160. package/dist/src/nested/references.d.ts +0 -13
  161. package/dist/tool/index.d.ts +0 -420
  162. package/dist/util/base.d.ts +0 -10
  163. package/dist/util/debug.d.ts +0 -20
  164. package/dist/util/diff.d.ts +0 -8
  165. package/dist/util/lint.d.ts +0 -28
  166. package/dist/util/string.d.ts +0 -55
  167. package/index.js +0 -333
  168. package/lib/element.js +0 -618
  169. package/lib/node.js +0 -730
  170. package/lib/ranges.js +0 -130
  171. package/lib/text.js +0 -265
  172. package/lib/title.js +0 -83
  173. package/mixin/attributeParent.js +0 -117
  174. package/mixin/fixedToken.js +0 -40
  175. package/mixin/hidden.js +0 -21
  176. package/mixin/singleLine.js +0 -31
  177. package/mixin/sol.js +0 -54
  178. package/parser/brackets.js +0 -128
  179. package/parser/commentAndExt.js +0 -62
  180. package/parser/converter.js +0 -46
  181. package/parser/externalLinks.js +0 -33
  182. package/parser/hrAndDoubleUnderscore.js +0 -49
  183. package/parser/html.js +0 -42
  184. package/parser/links.js +0 -94
  185. package/parser/list.js +0 -59
  186. package/parser/magicLinks.js +0 -41
  187. package/parser/quotes.js +0 -64
  188. package/parser/selector.js +0 -180
  189. package/parser/table.js +0 -114
  190. package/src/arg.js +0 -207
  191. package/src/atom/hidden.js +0 -13
  192. package/src/atom/index.js +0 -43
  193. package/src/attribute.js +0 -472
  194. package/src/attributes.js +0 -453
  195. package/src/charinsert.js +0 -97
  196. package/src/converter.js +0 -176
  197. package/src/converterFlags.js +0 -284
  198. package/src/converterRule.js +0 -256
  199. package/src/extLink.js +0 -180
  200. package/src/gallery.js +0 -149
  201. package/src/hasNowiki/index.js +0 -44
  202. package/src/hasNowiki/pre.js +0 -40
  203. package/src/heading.js +0 -134
  204. package/src/html.js +0 -254
  205. package/src/imageParameter.js +0 -303
  206. package/src/imagemap.js +0 -199
  207. package/src/imagemapLink.js +0 -41
  208. package/src/index.js +0 -938
  209. package/src/link/category.js +0 -44
  210. package/src/link/file.js +0 -287
  211. package/src/link/galleryImage.js +0 -120
  212. package/src/link/index.js +0 -388
  213. package/src/magicLink.js +0 -151
  214. package/src/nested/choose.js +0 -24
  215. package/src/nested/combobox.js +0 -23
  216. package/src/nested/index.js +0 -96
  217. package/src/nested/references.js +0 -23
  218. package/src/nowiki/comment.js +0 -71
  219. package/src/nowiki/dd.js +0 -59
  220. package/src/nowiki/doubleUnderscore.js +0 -56
  221. package/src/nowiki/hr.js +0 -41
  222. package/src/nowiki/index.js +0 -56
  223. package/src/nowiki/list.js +0 -16
  224. package/src/nowiki/noinclude.js +0 -28
  225. package/src/nowiki/quote.js +0 -69
  226. package/src/onlyinclude.js +0 -64
  227. package/src/paramTag/index.js +0 -89
  228. package/src/paramTag/inputbox.js +0 -35
  229. package/src/parameter.js +0 -239
  230. package/src/syntax.js +0 -91
  231. package/src/table/index.js +0 -985
  232. package/src/table/td.js +0 -343
  233. package/src/table/tr.js +0 -319
  234. package/src/tagPair/ext.js +0 -146
  235. package/src/tagPair/include.js +0 -50
  236. package/src/tagPair/index.js +0 -131
  237. package/src/transclude.js +0 -843
  238. package/tool/index.js +0 -1209
  239. package/typings/api.d.ts +0 -9
  240. package/typings/array.d.ts +0 -29
  241. package/typings/event.d.ts +0 -22
  242. package/typings/index.d.ts +0 -118
  243. package/typings/node.d.ts +0 -35
  244. package/typings/parser.d.ts +0 -12
  245. package/typings/table.d.ts +0 -10
  246. package/typings/token.d.ts +0 -31
  247. package/typings/tool.d.ts +0 -6
  248. package/util/base.js +0 -17
  249. package/util/debug.js +0 -73
  250. package/util/diff.js +0 -76
  251. package/util/lint.js +0 -57
  252. package/util/string.js +0 -126
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ const Parser = require("../index");
3
+ const Token = require("../src");
4
+ const TableToken = require("../src/table");
5
+ const TrToken = require("../src/table/tr");
6
+ const TdToken = require("../src/table/td");
7
+ const DdToken = require("../src/nowiki/dd");
8
+ /**
9
+ * 解析表格,注意`tr`和`td`包含开头的换行
10
+ * @param {Token & {firstChild: AstText}} root 根节点
11
+ */
12
+ const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getConfig(), accum = []) => {
13
+ const stack = [], lines = data.split('\n');
14
+ let out = type === 'root' || type === 'parameter-value' || type === 'ext-inner' && name === 'poem'
15
+ ? ''
16
+ : `\n${lines.shift()}`;
17
+ /**
18
+ * 向表格中插入纯文本
19
+ * @param str 待插入的文本
20
+ * @param top 当前解析的表格或表格行
21
+ */
22
+ const push = (str, top) => {
23
+ if (!top) {
24
+ out += str;
25
+ return;
26
+ }
27
+ const { lastChild } = top;
28
+ if (lastChild.constructor === Token) {
29
+ lastChild.setText(String(lastChild) + str);
30
+ }
31
+ else {
32
+ const token = new Token(str, config, true, accum);
33
+ token.type = 'table-inter';
34
+ top.insertAt(token.setAttribute('stage', 3));
35
+ }
36
+ };
37
+ for (const outLine of lines) {
38
+ let top = stack.pop();
39
+ 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
40
+ .exec(line);
41
+ if (matchesStart) {
42
+ while (top && top.type !== 'td') {
43
+ top = stack.pop();
44
+ }
45
+ const [, indent, moreSpaces, tableSyntax, attr] = matchesStart;
46
+ if (indent) {
47
+ new DdToken(indent, config, accum);
48
+ }
49
+ push(`\n${spaces}${indent && `\0${accum.length - 1}d\x7F`}${moreSpaces}\0${accum.length}b\x7F`, top);
50
+ const table = new TableToken(tableSyntax, attr, config, accum);
51
+ stack.push(...top ? [top] : [], table);
52
+ continue;
53
+ }
54
+ else if (!top) {
55
+ out += `\n${outLine}`;
56
+ continue;
57
+ }
58
+ // eslint-disable-next-line operator-linebreak
59
+ const matches = /^(?:(\|\}|\0\d+!\x7F\}|\0\d+\}\x7F)|(\|-+|\0\d+!\x7F-+|\0\d+-\x7F-*)(?!-)|(!|(?:\||\0\d+!\x7F)\+?))(.*)$/u
60
+ .exec(line);
61
+ if (!matches) {
62
+ push(`\n${outLine}`, top);
63
+ stack.push(top);
64
+ continue;
65
+ }
66
+ const [, closing, row, cell, attr] = matches;
67
+ if (closing) {
68
+ while (top.type !== 'table') {
69
+ top = stack.pop();
70
+ }
71
+ top.close(`\n${spaces}${closing}`, true);
72
+ push(attr, stack.at(-1));
73
+ }
74
+ else if (row) {
75
+ if (top.type === 'td') {
76
+ top = stack.pop();
77
+ }
78
+ if (top.type === 'tr') {
79
+ top = stack.pop();
80
+ }
81
+ const tr = new TrToken(`\n${spaces}${row}`, attr, config, accum);
82
+ stack.push(top, tr);
83
+ top.insertAt(tr);
84
+ }
85
+ else {
86
+ if (top.type === 'td') {
87
+ top = stack.pop();
88
+ }
89
+ const regex = cell === '!'
90
+ ? /!!|(?:\||\0\d+!\x7F){2}|\0\d+\+\x7F/gu
91
+ : /(?:\||\0\d+!\x7F){2}|\0\d+\+\x7F/gu;
92
+ let mt = regex.exec(attr), lastIndex = 0, lastSyntax = `\n${spaces}${cell}`;
93
+ while (mt) {
94
+ const td = new TdToken(lastSyntax, attr.slice(lastIndex, mt.index), config, accum);
95
+ top.insertAt(td);
96
+ ({ lastIndex } = regex);
97
+ [lastSyntax] = mt;
98
+ mt = regex.exec(attr);
99
+ }
100
+ const td = new TdToken(lastSyntax, attr.slice(lastIndex), config, accum);
101
+ stack.push(top, td);
102
+ top.insertAt(td);
103
+ }
104
+ }
105
+ return out.slice(1);
106
+ };
107
+ Parser.parsers['parseTable'] = __filename;
108
+ module.exports = parseTable;
package/dist/src/arg.d.ts CHANGED
@@ -1,54 +1,78 @@
1
- export = ArgToken;
1
+ import * as Parser from '../index';
2
+ import Token = require('.');
3
+ import AtomToken = require('./atom');
4
+ import HiddenToken = require('./hidden');
2
5
  /**
3
6
  * `{{{}}}`包裹的参数
4
7
  * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
5
8
  */
6
- declare class ArgToken extends Token {
9
+ declare abstract class ArgToken extends Token {
10
+ /** @browser */
11
+ readonly type = "arg";
12
+ name: string;
13
+ childNodes: [AtomToken] | [AtomToken, Token, ...HiddenToken[]];
14
+ abstract get firstChild(): AtomToken;
15
+ abstract get firstElementChild(): AtomToken;
16
+ abstract get lastChild(): Token;
17
+ abstract get lastElementChild(): Token;
7
18
  /**
8
- * @param {string[]} parts 以'|'分隔的各部分
9
- * @param {import('../../typings/token').accum} accum
10
- * @complexity `n`
19
+ * 预设值
20
+ * @browser
11
21
  */
12
- constructor(parts: string[], config?: import("../../typings/token").ParserConfig, accum?: import('../../typings/token').accum);
13
- /** default */
14
22
  get default(): string | false;
23
+ /**
24
+ * @browser
25
+ * @param parts 以'|'分隔的各部分
26
+ */
27
+ constructor(parts: string[], config?: Parser.Config, accum?: Token[]);
15
28
  /**
16
29
  * @override
17
- * @param {string} selector
30
+ * @browser
18
31
  */
19
- override toString(selector: string): string;
32
+ toString(selector?: string): string;
20
33
  /**
21
34
  * @override
22
- * @returns {string}
35
+ * @browser
23
36
  */
24
- override text(): string;
25
- /** @override */
26
- override print(): string;
27
- /** @override */
28
- override cloneNode(): ArgToken;
37
+ text(): string;
38
+ /**
39
+ * @override
40
+ * @browser
41
+ */
42
+ print(): string;
29
43
  /**
30
- * 移除无效部分
31
- * @complexity `n`
44
+ * @override
45
+ * @browser
32
46
  */
47
+ lint(start?: number): Parser.LintError[];
48
+ /** @override */
49
+ cloneNode(): this;
50
+ /** 移除无效部分 */
33
51
  removeRedundant(): void;
34
52
  /**
35
53
  * @override
36
- * @param {Token} token 待插入的子节点
37
- * @param {number} i 插入位置
54
+ * @param i 移除位置
55
+ */
56
+ removeAt(i: number): Token;
57
+ /**
58
+ * @override
59
+ * @param token 待插入的子节点
60
+ * @param i 插入位置
38
61
  * @throws `RangeError` 不可插入多余子节点
62
+ * @throws `TypeError` 不可插入文本节点
39
63
  */
40
- override insertAt(token: Token, i?: number): Token;
64
+ insertAt<T extends Token>(token: T, i?: number): T;
41
65
  /**
42
66
  * 设置参数名
43
- * @param {string} name 新参数名
67
+ * @param name 新参数名
44
68
  * @throws `SyntaxError` 非法的参数名
45
69
  */
46
70
  setName(name: string): void;
47
71
  /**
48
72
  * 设置预设值
49
- * @param {string} value 预设值
73
+ * @param value 预设值
50
74
  * @throws `SyntaxError` 非法的参数预设值
51
75
  */
52
76
  setDefault(value: string): void;
53
77
  }
54
- import Token = require(".");
78
+ export = ArgToken;
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ const string_1 = require("../util/string");
3
+ const lint_1 = require("../util/lint");
4
+ const Parser = require("../index");
5
+ const Token = require(".");
6
+ const AtomToken = require("./atom");
7
+ const HiddenToken = require("./hidden");
8
+ /**
9
+ * `{{{}}}`包裹的参数
10
+ * @classdesc `{childNodes: [AtomToken, ?Token, ...HiddenToken]}`
11
+ */
12
+ class ArgToken extends Token {
13
+ /** @browser */
14
+ type = 'arg';
15
+ /**
16
+ * 预设值
17
+ * @browser
18
+ */
19
+ get default() {
20
+ return this.childNodes[1]?.text() ?? false;
21
+ }
22
+ /**
23
+ * @browser
24
+ * @param parts 以'|'分隔的各部分
25
+ */
26
+ constructor(parts, config = Parser.getConfig(), accum = []) {
27
+ super(undefined, config, true, accum, {
28
+ AtomToken: 0, Token: 1, HiddenToken: '2:',
29
+ });
30
+ for (let i = 0; i < parts.length; i++) {
31
+ if (i === 0) {
32
+ const token = new AtomToken(parts[i], 'arg-name', config, accum, {
33
+ 'Stage-2': ':', '!HeadingToken': '',
34
+ });
35
+ super.insertAt(token);
36
+ }
37
+ else if (i > 1) {
38
+ const token = new HiddenToken(parts[i], config, accum, {
39
+ 'Stage-2': ':', '!HeadingToken': '',
40
+ });
41
+ super.insertAt(token);
42
+ }
43
+ else {
44
+ const token = new Token(parts[i], config, true, accum);
45
+ token.type = 'arg-default';
46
+ super.insertAt(token.setAttribute('stage', 2));
47
+ }
48
+ }
49
+ this.protectChildren(0);
50
+ }
51
+ /**
52
+ * @override
53
+ * @browser
54
+ */
55
+ toString(selector) {
56
+ return selector && this.matches(selector) ? '' : `{{{${super.toString(selector, '|')}}}}`;
57
+ }
58
+ /**
59
+ * @override
60
+ * @browser
61
+ */
62
+ text() {
63
+ return `{{{${(0, string_1.text)(this.childNodes.slice(0, 2), '|')}}}}`;
64
+ }
65
+ /** @private */
66
+ getPadding() {
67
+ return 3;
68
+ }
69
+ /** @private */
70
+ getGaps() {
71
+ return 1;
72
+ }
73
+ /**
74
+ * @override
75
+ * @browser
76
+ */
77
+ print() {
78
+ return super.print({ pre: '{{{', post: '}}}', sep: '|' });
79
+ }
80
+ /**
81
+ * @override
82
+ * @browser
83
+ */
84
+ lint(start = this.getAbsoluteIndex()) {
85
+ if (!this.getAttribute('include')) {
86
+ return [(0, lint_1.generateForSelf)(this, { start }, 'unexpected template argument')];
87
+ }
88
+ const { childNodes: [argName, argDefault, ...rest] } = this, errors = argName.lint(start + 3);
89
+ if (argDefault) {
90
+ errors.push(...argDefault.lint(start + 4 + String(argName).length));
91
+ }
92
+ if (rest.length > 0) {
93
+ const rect = { start, ...this.getRootNode().posFromIndex(start) };
94
+ errors.push(...rest.map(child => {
95
+ const error = (0, lint_1.generateForChild)(child, rect, 'invisible content inside triple brackets'), { startIndex, startCol, excerpt } = error;
96
+ return { ...error, startIndex: startIndex - 1, startCol: startCol - 1, excerpt: `|${excerpt}` };
97
+ }));
98
+ }
99
+ return errors;
100
+ }
101
+ /** @override */
102
+ cloneNode() {
103
+ const [name, ...cloned] = this.cloneChildNodes();
104
+ return Parser.run(() => {
105
+ const token = new ArgToken([''], this.getAttribute('config'));
106
+ token.firstChild.safeReplaceWith(name);
107
+ token.append(...cloned);
108
+ token.afterBuild();
109
+ return token;
110
+ });
111
+ }
112
+ /** @private */
113
+ afterBuild() {
114
+ this.setAttribute('name', this.firstChild.text().trim());
115
+ const /** @implements */ argListener = ({ prevTarget }) => {
116
+ if (prevTarget === this.firstChild) {
117
+ this.setAttribute('name', prevTarget.text().trim());
118
+ }
119
+ };
120
+ this.addEventListener(['remove', 'insert', 'replace', 'text'], argListener);
121
+ }
122
+ /** 移除无效部分 */
123
+ removeRedundant() {
124
+ Parser.run(() => {
125
+ for (let i = this.length - 1; i > 1; i--) {
126
+ super.removeAt(i);
127
+ }
128
+ });
129
+ }
130
+ /**
131
+ * @override
132
+ * @param i 移除位置
133
+ */
134
+ removeAt(i) {
135
+ if (i === 1) {
136
+ this.removeRedundant();
137
+ }
138
+ return super.removeAt(i);
139
+ }
140
+ /**
141
+ * @override
142
+ * @param token 待插入的子节点
143
+ * @param i 插入位置
144
+ * @throws `RangeError` 不可插入多余子节点
145
+ * @throws `TypeError` 不可插入文本节点
146
+ */
147
+ insertAt(token, i = this.length) {
148
+ const j = i < 0 ? i + this.length : i;
149
+ if (j > 1) {
150
+ throw new RangeError(`${this.constructor.name}不可插入多余的子节点!`);
151
+ }
152
+ else if (typeof token === 'string') {
153
+ throw new TypeError(`${this.constructor.name}不可插入文本节点!`);
154
+ }
155
+ super.insertAt(token, i);
156
+ if (j === 1) {
157
+ token.type = 'arg-default';
158
+ }
159
+ return token;
160
+ }
161
+ /**
162
+ * 设置参数名
163
+ * @param name 新参数名
164
+ * @throws `SyntaxError` 非法的参数名
165
+ */
166
+ setName(name) {
167
+ const root = Parser.parse(`{{{${name}}}}`, this.getAttribute('include'), 2, this.getAttribute('config')), { length, firstChild: arg } = root;
168
+ if (length !== 1 || arg.type !== 'arg' || arg.length !== 1) {
169
+ throw new SyntaxError(`非法的参数名称:${(0, string_1.noWrap)(name)}`);
170
+ }
171
+ const { firstChild } = arg;
172
+ arg.destroy();
173
+ this.firstChild.safeReplaceWith(firstChild);
174
+ }
175
+ /**
176
+ * 设置预设值
177
+ * @param value 预设值
178
+ * @throws `SyntaxError` 非法的参数预设值
179
+ */
180
+ setDefault(value) {
181
+ const root = Parser.parse(`{{{|${value}}}}`, this.getAttribute('include'), 2, this.getAttribute('config')), { length, firstChild: arg } = root;
182
+ if (length !== 1 || arg.type !== 'arg' || arg.length !== 2) {
183
+ throw new SyntaxError(`非法的参数预设值:${(0, string_1.noWrap)(value)}`);
184
+ }
185
+ const { childNodes: [, oldDefault] } = this, { lastChild } = arg;
186
+ arg.destroy();
187
+ if (oldDefault) {
188
+ oldDefault.safeReplaceWith(lastChild);
189
+ }
190
+ else {
191
+ this.insertAt(lastChild);
192
+ }
193
+ }
194
+ }
195
+ Parser.classes['ArgToken'] = __filename;
196
+ module.exports = ArgToken;
@@ -0,0 +1,12 @@
1
+ import * as Parser from '../index';
2
+ import Token = require('.');
3
+ declare type AtomTypes = 'arg-name' | 'attr-key' | 'attr-value' | 'ext-attr-dirty' | 'html-attr-dirty' | 'table-attr-dirty' | 'converter-flag' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'converter-rule-noconvert' | 'invoke-function' | 'invoke-module' | 'template-name' | 'link-target' | 'param-line';
4
+ /** 不会被继续解析的plain Token */
5
+ declare class AtomToken extends Token {
6
+ type: AtomTypes;
7
+ /** @browser */
8
+ constructor(wikitext: string | undefined, type: AtomTypes, config?: Parser.Config, accum?: Token[], acceptable?: Acceptable);
9
+ /** @override */
10
+ cloneNode(): this;
11
+ }
12
+ export = AtomToken;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ const Parser = require("../index");
3
+ const Token = require(".");
4
+ /** 不会被继续解析的plain Token */
5
+ class AtomToken extends Token {
6
+ /** @browser */
7
+ constructor(wikitext, type, config = Parser.getConfig(), accum = [], acceptable) {
8
+ super(wikitext, config, true, accum, acceptable);
9
+ this.type = type;
10
+ }
11
+ /** @override */
12
+ cloneNode() {
13
+ const cloned = this.cloneChildNodes(), config = this.getAttribute('config'), acceptable = this.getAttribute('acceptable');
14
+ return Parser.run(() => {
15
+ const token = new AtomToken(undefined, this.type, config, [], acceptable);
16
+ token.append(...cloned);
17
+ return token;
18
+ });
19
+ }
20
+ }
21
+ Parser.classes['AtomToken'] = __filename;
22
+ module.exports = AtomToken;
@@ -1,65 +1,106 @@
1
- export = AttributeToken;
1
+ import * as Parser from '../index';
2
+ import Token = require('.');
3
+ import AtomToken = require('./atom');
4
+ import type { TokenAttributeGetter } from '../lib/node';
5
+ declare type AttributeTypes = 'ext-attr' | 'html-attr' | 'table-attr';
6
+ declare const AttributeToken_base: ((abstract new (...args: any[]) => {
7
+ removeAt(): never;
8
+ insertAt(token: string, i?: number | undefined): import("../lib/text");
9
+ insertAt<T extends import("../lib/node").AstNodeTypes>(token: T, i?: number | undefined): T;
10
+ length: number;
11
+ toString(selector?: string | undefined, separator?: string | undefined): string;
12
+ text(separator?: string | undefined): string;
13
+ }) & {
14
+ readonly fixed: true;
15
+ }) & typeof Token;
2
16
  /**
3
17
  * 扩展和HTML标签属性
4
18
  * @classdesc `{childNodes: [AtomToken, Token|AtomToken]}`
5
19
  */
6
- declare class AttributeToken extends Token {
20
+ declare abstract class AttributeToken extends AttributeToken_base {
21
+ #private;
22
+ type: AttributeTypes;
23
+ name: string;
24
+ childNodes: [AtomToken, Token];
25
+ abstract get firstChild(): AtomToken;
26
+ abstract get firstElementChild(): AtomToken;
27
+ abstract get lastChild(): Token;
28
+ abstract get lastElementChild(): Token;
29
+ abstract get parentNode(): import('./attributes') | undefined;
30
+ abstract get parentElement(): import('./attributes') | undefined;
31
+ abstract get nextSibling(): AtomToken | this | undefined;
32
+ abstract get nextElementSibling(): AtomToken | this | undefined;
33
+ abstract get previousSibling(): AtomToken | this | undefined;
34
+ abstract get previousElementSibling(): AtomToken | this | undefined;
7
35
  /**
8
- * @param {'ext-attr'|'html-attr'|'table-attr'} type 标签类型
9
- * @param {string} tag 标签名
10
- * @param {string} key 属性名
11
- * @param {string} equal 等号
12
- * @param {string} value 属性值
13
- * @param {string[]} quotes 引号
14
- * @param {import('../../typings/token').accum} accum
36
+ * 引号是否匹配
37
+ * @browser
15
38
  */
16
- constructor(type: 'ext-attr' | 'html-attr' | 'table-attr', tag: string, key: string, equal?: string, value?: string, quotes?: string[], config?: import("../../typings/token").ParserConfig, accum?: import('../../typings/token').accum);
17
- /** 引号是否匹配 */
18
39
  get balanced(): boolean;
19
- set value(arg: string | true);
20
- /** getValue()的getter */
21
- get value(): string | true;
22
- /** 标签名 */
40
+ /**
41
+ * 标签名
42
+ * @browser
43
+ */
23
44
  get tag(): string;
24
- type: "ext-attr" | "html-attr" | "table-attr";
45
+ /**
46
+ * getValue()的getter
47
+ * @browser
48
+ */
49
+ get value(): string | true;
50
+ set value(value: string | true);
51
+ /**
52
+ * @browser
53
+ * @param type 标签类型
54
+ * @param tag 标签名
55
+ * @param key 属性名
56
+ * @param equal 等号
57
+ * @param value 属性值
58
+ * @param quotes 引号
59
+ */
60
+ constructor(type: AttributeTypes, tag: string, key: string, equal?: string, value?: string, quotes?: [string?, string?], config?: Parser.Config, accum?: Token[]);
25
61
  /**
26
62
  * @override
27
- * @param {string} selector
28
- * @returns {string}
63
+ * @browser
29
64
  */
30
- override toString(selector: string): string;
65
+ toString(selector?: string): string;
31
66
  /**
32
67
  * @override
33
- * @returns {string}
68
+ * @browser
69
+ */
70
+ text(): string;
71
+ /**
72
+ * @override
73
+ * @browser
74
+ */
75
+ print(): string;
76
+ /**
77
+ * @override
78
+ * @browser
79
+ */
80
+ lint(start?: number): Parser.LintError[];
81
+ /**
82
+ * 获取属性值
83
+ * @browser
34
84
  */
35
- override text(): string;
36
- /** @override */
37
- override print(): string;
38
- /** 获取属性值 */
39
85
  getValue(): string | true;
40
86
  /** @override */
41
- override cloneNode(): import("./attribute");
87
+ cloneNode(): this;
42
88
  /** 转义等号 */
43
89
  escape(): void;
44
90
  /** 闭合引号 */
45
91
  close(): void;
46
92
  /**
47
93
  * 设置属性值
48
- * @param {string|boolean} value 参数值
94
+ * @param value 参数值
49
95
  * @throws `SyntaxError` 非法的标签属性
50
96
  */
51
97
  setValue(value: string | boolean): void;
52
98
  /**
53
99
  * 修改属性名
54
- * @param {string} key 新属性名
100
+ * @param key 新属性名
55
101
  * @throws `Error` title属性不能更名
56
102
  * @throws `SyntaxError` 非法的模板参数名
57
103
  */
58
104
  rename(key: string): void;
59
- #private;
60
105
  }
61
- declare namespace AttributeToken {
62
- export { ParserConfig };
63
- }
64
- import Token = require(".");
65
- type ParserConfig = import('../../typings/token').ParserConfig;
106
+ export = AttributeToken;