wikiparser-node 0.11.0 → 1.0.0-beta.0

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 (251) hide show
  1. package/dist/index.d.ts +59 -113
  2. package/dist/index.js +307 -0
  3. package/dist/lib/element.d.ts +122 -108
  4. package/dist/lib/element.js +656 -0
  5. package/dist/lib/node.d.ts +115 -221
  6. package/dist/lib/node.js +473 -0
  7. package/dist/lib/ranges.d.ts +27 -26
  8. package/dist/lib/ranges.js +130 -0
  9. package/dist/lib/text.d.ts +36 -28
  10. package/dist/lib/text.js +215 -0
  11. package/dist/lib/title.d.ts +25 -12
  12. package/dist/lib/title.js +100 -0
  13. package/dist/mixin/attributesParent.js +90 -0
  14. package/dist/mixin/fixed.js +29 -0
  15. package/dist/mixin/hidden.js +19 -0
  16. package/dist/mixin/singleLine.js +23 -0
  17. package/dist/mixin/sol.js +41 -0
  18. package/dist/parser/brackets.js +117 -0
  19. package/dist/parser/commentAndExt.js +48 -0
  20. package/dist/parser/converter.js +31 -0
  21. package/dist/parser/externalLinks.js +22 -0
  22. package/dist/parser/hrAndDoubleUnderscore.js +33 -0
  23. package/dist/parser/html.js +29 -0
  24. package/dist/parser/links.js +86 -0
  25. package/dist/parser/list.js +51 -0
  26. package/dist/parser/magicLinks.js +32 -0
  27. package/dist/parser/quotes.js +57 -0
  28. package/dist/parser/selector.js +158 -0
  29. package/dist/parser/table.js +108 -0
  30. package/dist/src/arg.d.ts +47 -23
  31. package/dist/src/arg.js +196 -0
  32. package/dist/src/atom.d.ts +12 -0
  33. package/dist/src/atom.js +22 -0
  34. package/dist/src/attribute.d.ts +74 -33
  35. package/dist/src/attribute.js +433 -0
  36. package/dist/src/attributes.d.ts +61 -55
  37. package/dist/src/attributes.js +371 -0
  38. package/dist/src/converter.d.ts +45 -71
  39. package/dist/src/converter.js +135 -0
  40. package/dist/src/converterFlags.d.ts +64 -39
  41. package/dist/src/converterFlags.js +235 -0
  42. package/dist/src/converterRule.d.ts +49 -27
  43. package/dist/src/converterRule.js +255 -0
  44. package/dist/src/extLink.d.ts +41 -38
  45. package/dist/src/extLink.js +154 -0
  46. package/dist/src/gallery.d.ts +59 -18
  47. package/dist/src/gallery.js +132 -0
  48. package/dist/src/heading.d.ts +60 -22
  49. package/dist/src/heading.js +135 -0
  50. package/dist/src/hidden.d.ts +20 -0
  51. package/dist/src/hidden.js +24 -0
  52. package/dist/src/html.d.ts +83 -29
  53. package/dist/src/html.js +242 -0
  54. package/dist/src/imageParameter.d.ts +59 -40
  55. package/dist/src/imageParameter.js +251 -0
  56. package/dist/src/imagemap.d.ts +65 -21
  57. package/dist/src/imagemap.js +164 -0
  58. package/dist/src/imagemapLink.d.ts +46 -14
  59. package/dist/src/imagemapLink.js +38 -0
  60. package/dist/src/index.d.ts +71 -105
  61. package/dist/src/index.js +826 -0
  62. package/dist/src/link/base.d.ts +71 -0
  63. package/dist/src/link/base.js +225 -0
  64. package/dist/src/link/category.d.ts +10 -11
  65. package/dist/src/link/category.js +26 -0
  66. package/dist/src/link/file.d.ts +61 -39
  67. package/dist/src/link/file.js +242 -0
  68. package/dist/src/link/galleryImage.d.ts +34 -12
  69. package/dist/src/link/galleryImage.js +98 -0
  70. package/dist/src/link/index.d.ts +25 -63
  71. package/dist/src/link/index.js +136 -0
  72. package/dist/src/magicLink.d.ts +22 -15
  73. package/dist/src/magicLink.js +126 -0
  74. package/dist/src/nested.d.ts +47 -0
  75. package/dist/src/nested.js +84 -0
  76. package/dist/src/nowiki/base.d.ts +39 -0
  77. package/dist/src/nowiki/base.js +29 -0
  78. package/dist/src/nowiki/comment.d.ts +31 -20
  79. package/dist/src/nowiki/comment.js +61 -0
  80. package/dist/src/nowiki/dd.d.ts +17 -11
  81. package/dist/src/nowiki/dd.js +50 -0
  82. package/dist/src/nowiki/doubleUnderscore.d.ts +28 -13
  83. package/dist/src/nowiki/doubleUnderscore.js +45 -0
  84. package/dist/src/nowiki/hr.d.ts +28 -10
  85. package/dist/src/nowiki/hr.js +33 -0
  86. package/dist/src/nowiki/index.d.ts +17 -23
  87. package/dist/src/nowiki/index.js +21 -0
  88. package/dist/src/nowiki/list.d.ts +15 -7
  89. package/dist/src/nowiki/list.js +11 -0
  90. package/dist/src/nowiki/noinclude.d.ts +20 -7
  91. package/dist/src/nowiki/noinclude.js +22 -0
  92. package/dist/src/nowiki/quote.d.ts +25 -10
  93. package/dist/src/nowiki/quote.js +55 -0
  94. package/dist/src/onlyinclude.d.ts +28 -12
  95. package/dist/src/onlyinclude.js +64 -0
  96. package/dist/src/paramTag/index.d.ts +40 -17
  97. package/dist/src/paramTag/index.js +76 -0
  98. package/dist/src/paramTag/inputbox.d.ts +8 -7
  99. package/dist/src/paramTag/inputbox.js +19 -0
  100. package/dist/src/parameter.d.ts +62 -41
  101. package/dist/src/parameter.js +201 -0
  102. package/dist/src/pre.d.ts +32 -0
  103. package/dist/src/pre.js +39 -0
  104. package/dist/src/syntax.d.ts +17 -14
  105. package/dist/src/syntax.js +65 -0
  106. package/dist/src/table/base.d.ts +55 -0
  107. package/dist/src/table/base.js +77 -0
  108. package/dist/src/table/index.d.ts +123 -156
  109. package/dist/src/table/index.js +811 -0
  110. package/dist/src/table/td.d.ts +90 -67
  111. package/dist/src/table/td.js +276 -0
  112. package/dist/src/table/tr.d.ts +30 -85
  113. package/dist/src/table/tr.js +48 -0
  114. package/dist/src/table/trBase.d.ts +72 -0
  115. package/dist/src/table/trBase.js +153 -0
  116. package/dist/src/tagPair/ext.d.ts +47 -11
  117. package/dist/src/tagPair/ext.js +127 -0
  118. package/dist/src/tagPair/include.d.ts +32 -13
  119. package/dist/src/tagPair/include.js +40 -0
  120. package/dist/src/tagPair/index.d.ts +44 -29
  121. package/dist/src/tagPair/index.js +111 -0
  122. package/dist/src/transclude.d.ts +88 -85
  123. package/dist/src/transclude.js +739 -0
  124. package/dist/util/base.js +26 -0
  125. package/dist/util/debug.js +52 -0
  126. package/dist/util/diff.js +69 -0
  127. package/dist/util/lint.js +38 -0
  128. package/dist/util/string.js +103 -0
  129. package/errors/README +1 -0
  130. package/i18n/zh-hans.json +1 -0
  131. package/i18n/zh-hant.json +1 -0
  132. package/package.json +11 -14
  133. package/printed/README +1 -0
  134. package/dist/mixin/attributeParent.d.ts +0 -9
  135. package/dist/mixin/fixedToken.d.ts +0 -8
  136. package/dist/mixin/hidden.d.ts +0 -8
  137. package/dist/mixin/singleLine.d.ts +0 -8
  138. package/dist/mixin/sol.d.ts +0 -8
  139. package/dist/parser/brackets.d.ts +0 -12
  140. package/dist/parser/commentAndExt.d.ts +0 -8
  141. package/dist/parser/converter.d.ts +0 -7
  142. package/dist/parser/externalLinks.d.ts +0 -7
  143. package/dist/parser/hrAndDoubleUnderscore.d.ts +0 -11
  144. package/dist/parser/html.d.ts +0 -7
  145. package/dist/parser/links.d.ts +0 -7
  146. package/dist/parser/list.d.ts +0 -7
  147. package/dist/parser/magicLinks.d.ts +0 -7
  148. package/dist/parser/quotes.d.ts +0 -7
  149. package/dist/parser/selector.d.ts +0 -12
  150. package/dist/parser/table.d.ts +0 -11
  151. package/dist/src/atom/hidden.d.ts +0 -5
  152. package/dist/src/atom/index.d.ts +0 -15
  153. package/dist/src/charinsert.d.ts +0 -32
  154. package/dist/src/hasNowiki/index.d.ts +0 -14
  155. package/dist/src/hasNowiki/pre.d.ts +0 -13
  156. package/dist/src/nested/choose.d.ts +0 -13
  157. package/dist/src/nested/combobox.d.ts +0 -13
  158. package/dist/src/nested/index.d.ts +0 -18
  159. package/dist/src/nested/references.d.ts +0 -13
  160. package/dist/tool/index.d.ts +0 -420
  161. package/dist/util/base.d.ts +0 -10
  162. package/dist/util/debug.d.ts +0 -20
  163. package/dist/util/diff.d.ts +0 -8
  164. package/dist/util/lint.d.ts +0 -28
  165. package/dist/util/string.d.ts +0 -55
  166. package/index.js +0 -333
  167. package/lib/element.js +0 -618
  168. package/lib/node.js +0 -730
  169. package/lib/ranges.js +0 -130
  170. package/lib/text.js +0 -265
  171. package/lib/title.js +0 -83
  172. package/mixin/attributeParent.js +0 -117
  173. package/mixin/fixedToken.js +0 -40
  174. package/mixin/hidden.js +0 -21
  175. package/mixin/singleLine.js +0 -31
  176. package/mixin/sol.js +0 -54
  177. package/parser/brackets.js +0 -128
  178. package/parser/commentAndExt.js +0 -62
  179. package/parser/converter.js +0 -46
  180. package/parser/externalLinks.js +0 -33
  181. package/parser/hrAndDoubleUnderscore.js +0 -49
  182. package/parser/html.js +0 -42
  183. package/parser/links.js +0 -94
  184. package/parser/list.js +0 -59
  185. package/parser/magicLinks.js +0 -41
  186. package/parser/quotes.js +0 -64
  187. package/parser/selector.js +0 -180
  188. package/parser/table.js +0 -114
  189. package/src/arg.js +0 -207
  190. package/src/atom/hidden.js +0 -13
  191. package/src/atom/index.js +0 -43
  192. package/src/attribute.js +0 -472
  193. package/src/attributes.js +0 -453
  194. package/src/charinsert.js +0 -97
  195. package/src/converter.js +0 -176
  196. package/src/converterFlags.js +0 -284
  197. package/src/converterRule.js +0 -256
  198. package/src/extLink.js +0 -180
  199. package/src/gallery.js +0 -149
  200. package/src/hasNowiki/index.js +0 -44
  201. package/src/hasNowiki/pre.js +0 -40
  202. package/src/heading.js +0 -134
  203. package/src/html.js +0 -254
  204. package/src/imageParameter.js +0 -303
  205. package/src/imagemap.js +0 -199
  206. package/src/imagemapLink.js +0 -41
  207. package/src/index.js +0 -938
  208. package/src/link/category.js +0 -44
  209. package/src/link/file.js +0 -287
  210. package/src/link/galleryImage.js +0 -120
  211. package/src/link/index.js +0 -388
  212. package/src/magicLink.js +0 -151
  213. package/src/nested/choose.js +0 -24
  214. package/src/nested/combobox.js +0 -23
  215. package/src/nested/index.js +0 -96
  216. package/src/nested/references.js +0 -23
  217. package/src/nowiki/comment.js +0 -71
  218. package/src/nowiki/dd.js +0 -59
  219. package/src/nowiki/doubleUnderscore.js +0 -56
  220. package/src/nowiki/hr.js +0 -41
  221. package/src/nowiki/index.js +0 -56
  222. package/src/nowiki/list.js +0 -16
  223. package/src/nowiki/noinclude.js +0 -28
  224. package/src/nowiki/quote.js +0 -69
  225. package/src/onlyinclude.js +0 -64
  226. package/src/paramTag/index.js +0 -89
  227. package/src/paramTag/inputbox.js +0 -35
  228. package/src/parameter.js +0 -239
  229. package/src/syntax.js +0 -91
  230. package/src/table/index.js +0 -985
  231. package/src/table/td.js +0 -343
  232. package/src/table/tr.js +0 -319
  233. package/src/tagPair/ext.js +0 -146
  234. package/src/tagPair/include.js +0 -50
  235. package/src/tagPair/index.js +0 -131
  236. package/src/transclude.js +0 -843
  237. package/tool/index.js +0 -1209
  238. package/typings/api.d.ts +0 -9
  239. package/typings/array.d.ts +0 -29
  240. package/typings/event.d.ts +0 -22
  241. package/typings/index.d.ts +0 -118
  242. package/typings/node.d.ts +0 -35
  243. package/typings/parser.d.ts +0 -12
  244. package/typings/table.d.ts +0 -10
  245. package/typings/token.d.ts +0 -31
  246. package/typings/tool.d.ts +0 -6
  247. package/util/base.js +0 -17
  248. package/util/debug.js +0 -73
  249. package/util/diff.js +0 -76
  250. package/util/lint.js +0 -57
  251. package/util/string.js +0 -126
@@ -0,0 +1,71 @@
1
+ import Title = require('../../lib/title');
2
+ import * as Parser from '../../index';
3
+ import Token = require('..');
4
+ import AtomToken = require('../atom');
5
+ import type { TokenAttributeSetter } from '../../lib/node';
6
+ /**
7
+ * 内链
8
+ * @classdesc `{childNodes: [AtomToken, ...Token]}`
9
+ */
10
+ declare abstract class LinkBaseToken extends Token {
11
+ #private;
12
+ type: 'link' | 'category' | 'file' | 'gallery-image' | 'imagemap-image';
13
+ name: string;
14
+ childNodes: [AtomToken, ...Token[]];
15
+ abstract get children(): [AtomToken, ...Token[]];
16
+ abstract get firstChild(): AtomToken;
17
+ abstract get firstElementChild(): AtomToken;
18
+ abstract get lastChild(): Token;
19
+ abstract get lastElementChild(): Token;
20
+ /** 完整链接 */
21
+ get link(): string | Title;
22
+ set link(link: string | Title);
23
+ /** fragment */
24
+ get fragment(): string | undefined;
25
+ /** 链接显示文字 */
26
+ get innerText(): string | undefined;
27
+ /**
28
+ * @browser
29
+ * @param link 链接标题
30
+ * @param linkText 链接显示文字
31
+ * @param delimiter `|`
32
+ */
33
+ constructor(link: string, linkText?: string, config?: Parser.Config, accum?: Token[], delimiter?: string);
34
+ /**
35
+ * @override
36
+ * @browser
37
+ */
38
+ toString(selector?: string): string;
39
+ /**
40
+ * @override
41
+ * @browser
42
+ */
43
+ text(): string;
44
+ /**
45
+ * @override
46
+ * @browser
47
+ */
48
+ print(): string;
49
+ /**
50
+ * @override
51
+ * @browser
52
+ */
53
+ lint(start?: number): Parser.LintError[];
54
+ /** @override */
55
+ cloneNode(this: this & {
56
+ constructor: new (...args: unknown[]) => unknown;
57
+ }): this;
58
+ /**
59
+ * 设置链接目标
60
+ * @param link 链接目标
61
+ * @throws `SyntaxError` 非法的链接目标
62
+ */
63
+ setTarget(link: string | Title): void;
64
+ /**
65
+ * 设置链接显示文字
66
+ * @param linkStr 链接显示文字
67
+ * @throws `SyntaxError` 非法的链接显示文字
68
+ */
69
+ setLinkText(linkStr?: string): void;
70
+ }
71
+ export = LinkBaseToken;
@@ -0,0 +1,225 @@
1
+ "use strict";
2
+ const lint_1 = require("../../util/lint");
3
+ const string_1 = require("../../util/string");
4
+ const debug_1 = require("../../util/debug");
5
+ const Parser = require("../../index");
6
+ const Token = require("..");
7
+ const AtomToken = require("../atom");
8
+ /**
9
+ * 内链
10
+ * @classdesc `{childNodes: [AtomToken, ...Token]}`
11
+ */
12
+ class LinkBaseToken extends Token {
13
+ #bracket = true;
14
+ #delimiter;
15
+ #fragment;
16
+ #encoded = false;
17
+ /** 完整链接 */
18
+ get link() {
19
+ return this.#getTitle();
20
+ }
21
+ set link(link) {
22
+ this.setTarget(link);
23
+ }
24
+ /** fragment */
25
+ get fragment() {
26
+ return this.#getTitle().fragment;
27
+ }
28
+ /** 链接显示文字 */
29
+ get innerText() {
30
+ if (this.type === 'link') {
31
+ return this.length > 1
32
+ ? this.lastChild.text()
33
+ : this.firstChild.text().replace(/^\s*:/u, '');
34
+ }
35
+ return undefined;
36
+ }
37
+ /**
38
+ * @browser
39
+ * @param link 链接标题
40
+ * @param linkText 链接显示文字
41
+ * @param delimiter `|`
42
+ */
43
+ constructor(link, linkText, config = Parser.getConfig(), accum = [], delimiter = '|') {
44
+ super(undefined, config, true, accum, {
45
+ AtomToken: 0, Token: 1,
46
+ });
47
+ this.insertAt(new AtomToken(link, 'link-target', config, accum, {
48
+ 'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '',
49
+ }));
50
+ if (linkText !== undefined) {
51
+ const inner = new Token(linkText, config, true, accum, {
52
+ 'Stage-5': ':', ConverterToken: ':',
53
+ });
54
+ inner.type = 'link-text';
55
+ this.insertAt(inner.setAttribute('stage', Parser.MAX_STAGE - 1));
56
+ }
57
+ this.#delimiter = delimiter;
58
+ this.protectChildren(0);
59
+ }
60
+ /** @private */
61
+ afterBuild() {
62
+ const titleObj = this.normalizeTitle(this.firstChild.text(), 0, false, true, true);
63
+ this.setAttribute('name', titleObj.title);
64
+ this.#fragment = titleObj.fragment;
65
+ this.#encoded = titleObj.encoded;
66
+ if (this.#delimiter.includes('\0')) {
67
+ this.#delimiter = this.buildFromStr(this.#delimiter, 'string');
68
+ }
69
+ const /** @implements */ linkListener = (e, data) => {
70
+ const { prevTarget } = e;
71
+ if (prevTarget?.type === 'link-target') {
72
+ const name = prevTarget.text(), { title, interwiki, ns, valid, fragment, encoded } = this.normalizeTitle(name, 0, false, true, true);
73
+ if (!valid) {
74
+ (0, debug_1.undo)(e, data);
75
+ throw new Error(`非法的内链目标:${name}`);
76
+ }
77
+ else if (this.type === 'category' && (interwiki || ns !== 14)
78
+ || this.type === 'file' && (interwiki || ns !== 6)) {
79
+ (0, debug_1.undo)(e, data);
80
+ throw new Error(`${this.type === 'file' ? '文件' : '分类'}链接不可更改命名空间:${name}`);
81
+ }
82
+ else if (this.type === 'link' && !interwiki && (ns === 6 || ns === 14)
83
+ && !name.trim().startsWith(':')) {
84
+ const { firstChild } = prevTarget;
85
+ if (firstChild?.type === 'text') {
86
+ firstChild.insertData(0, ':');
87
+ }
88
+ else {
89
+ prevTarget.prepend(':');
90
+ }
91
+ }
92
+ this.setAttribute('name', title);
93
+ this.#fragment = fragment;
94
+ this.#encoded = encoded;
95
+ }
96
+ };
97
+ this.addEventListener(['remove', 'insert', 'replace', 'text'], linkListener);
98
+ }
99
+ /** @private */
100
+ setAttribute(key, value) {
101
+ if (key === 'bracket') {
102
+ this.#bracket = Boolean(value);
103
+ return this;
104
+ }
105
+ return super.setAttribute(key, value);
106
+ }
107
+ /**
108
+ * @override
109
+ * @browser
110
+ */
111
+ toString(selector) {
112
+ const str = super.toString(selector, this.#delimiter);
113
+ return this.#bracket && !(selector && this.matches(selector)) ? `[[${str}]]` : str;
114
+ }
115
+ /**
116
+ * @override
117
+ * @browser
118
+ */
119
+ text() {
120
+ const str = super.text('|');
121
+ return this.#bracket ? `[[${str}]]` : str;
122
+ }
123
+ /** @private */
124
+ getPadding() {
125
+ return 2;
126
+ }
127
+ /** @private */
128
+ getGaps() {
129
+ return this.#delimiter.length;
130
+ }
131
+ /**
132
+ * @override
133
+ * @browser
134
+ */
135
+ print() {
136
+ return super.print(this.#bracket ? { pre: '[[', post: ']]', sep: this.#delimiter } : { sep: this.#delimiter });
137
+ }
138
+ /**
139
+ * @override
140
+ * @browser
141
+ */
142
+ lint(start = this.getAbsoluteIndex()) {
143
+ const errors = super.lint(start), { childNodes: [target, linkText], type: linkType } = this;
144
+ let rect;
145
+ if (linkType === 'link' && target.childNodes.some(({ type }) => type === 'template')) {
146
+ rect = { start, ...this.getRootNode().posFromIndex(start) };
147
+ errors.push((0, lint_1.generateForChild)(target, rect, 'template in an internal link target', 'warning'));
148
+ }
149
+ if (this.#encoded) {
150
+ rect ??= { start, ...this.getRootNode().posFromIndex(start) };
151
+ errors.push((0, lint_1.generateForChild)(target, rect, 'unnecessary URL encoding in an internal link'));
152
+ }
153
+ if (linkType === 'link' && linkText?.childNodes?.some(child => child.type === 'text' && child.data.includes('|'))) {
154
+ rect ??= { start, ...this.getRootNode().posFromIndex(start) };
155
+ errors.push((0, lint_1.generateForChild)(linkText, rect, 'additional "|" in the link text', 'warning'));
156
+ }
157
+ else if (linkType !== 'link' && this.#fragment !== undefined) {
158
+ rect ??= { start, ...this.getRootNode().posFromIndex(start) };
159
+ errors.push((0, lint_1.generateForChild)(target, rect, 'useless fragment'));
160
+ }
161
+ return errors;
162
+ }
163
+ /** 生成Title对象 */
164
+ #getTitle() {
165
+ return this.normalizeTitle(this.firstChild.text(), 0, false, true, true);
166
+ }
167
+ /** @override */
168
+ cloneNode() {
169
+ const [link, ...linkText] = this.cloneChildNodes();
170
+ return Parser.run(() => {
171
+ const token = new this.constructor('', undefined, this.getAttribute('config'));
172
+ token.firstChild.safeReplaceWith(link);
173
+ token.append(...linkText);
174
+ token.afterBuild();
175
+ return token;
176
+ });
177
+ }
178
+ /**
179
+ * 设置链接目标
180
+ * @param link 链接目标
181
+ * @throws `SyntaxError` 非法的链接目标
182
+ */
183
+ setTarget(link) {
184
+ let strLink = String(link);
185
+ if (this.type === 'link' && !/^\s*[:#]/u.test(strLink)) {
186
+ strLink = `:${strLink}`;
187
+ }
188
+ const root = Parser.parse(`[[${strLink}]]`, this.getAttribute('include'), 6, this.getAttribute('config')), { length, firstChild: wikiLink } = root;
189
+ if (length !== 1 || wikiLink?.type !== this.type || wikiLink.length !== 1) {
190
+ const msgs = { link: '内链', file: '文件链接', category: '分类' };
191
+ throw new SyntaxError(`非法的${msgs[this.type]}目标:${strLink}`);
192
+ }
193
+ const { firstChild } = wikiLink;
194
+ wikiLink.destroy();
195
+ this.firstChild.safeReplaceWith(firstChild);
196
+ }
197
+ /**
198
+ * 设置链接显示文字
199
+ * @param linkStr 链接显示文字
200
+ * @throws `SyntaxError` 非法的链接显示文字
201
+ */
202
+ setLinkText(linkStr = '') {
203
+ let lastChild;
204
+ const config = this.getAttribute('config');
205
+ if (linkStr) {
206
+ const root = Parser.parse(`[[${this.type === 'category' ? 'Category:' : ''}L|${linkStr}]]`, this.getAttribute('include'), 6, config), { length, firstChild: wikiLink } = root;
207
+ if (length !== 1 || wikiLink?.type !== this.type || wikiLink.length !== 2) {
208
+ throw new SyntaxError(`非法的${this.type === 'link' ? '内链文字' : '分类关键字'}:${(0, string_1.noWrap)(linkStr)}`);
209
+ }
210
+ ({ lastChild } = wikiLink);
211
+ }
212
+ else {
213
+ lastChild = Parser.run(() => new Token('', config));
214
+ lastChild.setAttribute('stage', 7).type = 'link-text';
215
+ }
216
+ if (this.length === 1) {
217
+ this.insertAt(lastChild);
218
+ }
219
+ else {
220
+ this.lastChild.safeReplaceWith(lastChild);
221
+ }
222
+ }
223
+ }
224
+ Parser.classes['LinkBaseToken'] = __filename;
225
+ module.exports = LinkBaseToken;
@@ -1,16 +1,15 @@
1
- export = CategoryToken;
2
- /**
3
- * 分类
4
- * @classdesc `{childNodes: [AtomToken, ?Token]}`
5
- */
6
- declare class CategoryToken extends LinkToken {
7
- set sortkey(arg: string);
1
+ import LinkToken = require('.');
2
+ /** 分类 */
3
+ declare abstract class CategoryToken extends LinkToken {
4
+ /** @browser */
5
+ readonly type = "category";
8
6
  /** 分类排序关键字 */
9
- get sortkey(): string;
7
+ get sortkey(): string | undefined;
8
+ set sortkey(text: string | undefined);
10
9
  /**
11
10
  * 设置排序关键字
12
- * @param {string} text 排序关键字
11
+ * @param text 排序关键字
13
12
  */
14
- setSortkey(text: string): void;
13
+ setSortkey(text?: string): void;
15
14
  }
16
- import LinkToken = require(".");
15
+ export = CategoryToken;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ const string_1 = require("../../util/string");
3
+ const Parser = require("../../index");
4
+ const LinkToken = require(".");
5
+ /** 分类 */
6
+ class CategoryToken extends LinkToken {
7
+ /** @browser */
8
+ type = 'category';
9
+ /** 分类排序关键字 */
10
+ get sortkey() {
11
+ const { childNodes: [, child] } = this;
12
+ return child && (0, string_1.decodeHtml)(child.text());
13
+ }
14
+ set sortkey(text) {
15
+ this.setSortkey(text);
16
+ }
17
+ /**
18
+ * 设置排序关键字
19
+ * @param text 排序关键字
20
+ */
21
+ setSortkey(text) {
22
+ this.setLinkText(text);
23
+ }
24
+ }
25
+ Parser.classes['CategoryToken'] = __filename;
26
+ module.exports = CategoryToken;
@@ -1,85 +1,107 @@
1
- export = FileToken;
1
+ import Title = require('../../lib/title');
2
+ import * as Parser from '../../index';
3
+ import LinkBaseToken = require('./base');
4
+ import ImageParameterToken = require('../imageParameter');
5
+ import AtomToken = require('../atom');
6
+ import Token = require('..');
2
7
  /**
3
8
  * 图片
4
9
  * @classdesc `{childNodes: [AtomToken, ...ImageParameterToken]}`
5
10
  */
6
- declare class FileToken extends LinkToken {
7
- set link(arg: string | import("../../lib/title"));
11
+ declare abstract class FileToken extends LinkBaseToken {
12
+ #private;
13
+ /** @browser */
14
+ readonly type: 'file' | 'gallery-image' | 'imagemap-image';
15
+ childNodes: [AtomToken, ...ImageParameterToken[]];
16
+ abstract get children(): [AtomToken, ...ImageParameterToken[]];
17
+ abstract get lastChild(): ImageParameterToken;
18
+ abstract get lastElementChild(): ImageParameterToken;
8
19
  /** 图片链接 */
9
- get link(): string | import("../../lib/title");
20
+ get link(): string | Title;
21
+ set link(value: string | Title);
10
22
  /** 图片大小 */
11
23
  get size(): {
12
24
  width: string;
13
25
  height: string;
14
- };
15
- set width(arg: string);
26
+ } | undefined;
16
27
  /** 图片宽度 */
17
- get width(): string;
18
- set height(arg: string);
28
+ get width(): string | undefined;
29
+ set width(width: string | undefined);
19
30
  /** 图片高度 */
20
- get height(): string;
31
+ get height(): string | undefined;
32
+ set height(height: string | undefined);
33
+ /**
34
+ * @browser
35
+ * @param link 文件名
36
+ * @param text 图片参数
37
+ * @param delimiter `|`
38
+ */
39
+ constructor(link: string, text?: string, config?: Parser.Config, accum?: Token[], delimiter?: string);
40
+ /**
41
+ * @override
42
+ * @browser
43
+ */
44
+ lint(start?: number): Parser.LintError[];
21
45
  /**
22
46
  * 获取所有图片参数节点
23
- * @returns {ImageParameterToken[]}
47
+ * @browser
24
48
  */
25
49
  getAllArgs(): ImageParameterToken[];
26
50
  /**
27
51
  * 获取指定图片参数
28
- * @param {string} key 参数名
29
- * @complexity `n`
52
+ * @browser
53
+ * @param key 参数名
30
54
  */
31
55
  getArgs(key: string): ImageParameterToken[];
32
- /** 获取图片框架属性参数节点 */
56
+ /**
57
+ * 获取图片框架属性参数节点
58
+ * @browser
59
+ */
33
60
  getFrameArgs(): ImageParameterToken[];
34
- /** 获取图片水平对齐参数节点 */
61
+ /**
62
+ * 获取图片水平对齐参数节点
63
+ * @browser
64
+ */
35
65
  getHorizAlignArgs(): ImageParameterToken[];
36
- /** 获取图片垂直对齐参数节点 */
66
+ /**
67
+ * 获取图片垂直对齐参数节点
68
+ * @browser
69
+ */
37
70
  getVertAlignArgs(): ImageParameterToken[];
38
71
  /**
39
72
  * 获取生效的指定图片参数
40
- * @param {string} key 参数名
41
- * @complexity `n`
73
+ * @param key 参数名
42
74
  */
43
- getArg(key: string): ImageParameterToken;
75
+ getArg(key: string): ImageParameterToken | undefined;
44
76
  /**
45
77
  * 是否具有指定图片参数
46
- * @param {string} key 参数名
47
- * @complexity `n`
78
+ * @param key 参数名
48
79
  */
49
80
  hasArg(key: string): boolean;
50
81
  /**
51
82
  * 移除指定图片参数
52
- * @param {string} key 参数名
53
- * @complexity `n`
83
+ * @param key 参数名
54
84
  */
55
85
  removeArg(key: string): void;
56
- /**
57
- * 获取图片参数名
58
- * @complexity `n`
59
- */
60
- getKeys(): string[];
86
+ /** 获取图片参数名 */
87
+ getKeys(): Set<string>;
61
88
  /**
62
89
  * 获取指定的图片参数值
63
- * @param {string} key 参数名
64
- * @complexity `n`
90
+ * @param key 参数名
65
91
  */
66
92
  getValues(key: string): (string | true)[];
67
93
  /**
68
94
  * 获取生效的指定图片参数值
69
- * @param {string} key 参数名
70
- * @complexity `n`
95
+ * @param key 参数名
71
96
  */
72
- getValue(key: string): string | true;
97
+ getValue(key: string): string | true | undefined;
73
98
  /**
74
99
  * 设置图片参数
75
- * @param {string} key 参数名
76
- * @param {string|boolean} value 参数值
77
- * @complexity `n`
100
+ * @param key 参数名
101
+ * @param value 参数值
78
102
  * @throws `RangeError` 未定义的图片参数
79
103
  * @throws `SyntaxError` 非法的参数
80
104
  */
81
- setValue(key: string, value: string | boolean): void;
82
- #private;
105
+ setValue(key: string, value?: string | boolean | undefined): void;
83
106
  }
84
- import LinkToken = require(".");
85
- import ImageParameterToken = require("../imageParameter");
107
+ export = FileToken;