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
@@ -1,37 +1,81 @@
1
- export = ImagemapToken;
1
+ import * as Parser from '../index';
2
+ import AstText = require('../lib/text');
3
+ import Token = require('.');
4
+ import NoincludeToken = require('./nowiki/noinclude');
5
+ import GalleryImageToken = require('./link/galleryImage');
6
+ import ImagemapLinkToken = require('./imagemapLink');
7
+ import AttributesToken = require('./attributes');
8
+ import ExtToken = require('./tagPair/ext');
9
+ import type { AstNodeTypes } from '../lib/node';
2
10
  /**
3
11
  * `<imagemap>`
4
12
  * @classdesc `{childNodes: ...NoincludeToken, GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)}`
5
13
  */
6
- declare class ImagemapToken extends Token {
14
+ declare abstract class ImagemapToken extends Token {
15
+ /** @browser */
16
+ readonly type = "ext-inner";
17
+ childNodes: (GalleryImageToken | NoincludeToken | ImagemapLinkToken | AstText)[];
18
+ abstract get children(): (GalleryImageToken | NoincludeToken | ImagemapLinkToken)[];
19
+ abstract get firstChild(): NoincludeToken | GalleryImageToken;
20
+ abstract get firstElementChild(): NoincludeToken | GalleryImageToken;
21
+ abstract get lastChild(): GalleryImageToken | NoincludeToken | ImagemapLinkToken | AstText;
22
+ abstract get lastElementChild(): GalleryImageToken | NoincludeToken | ImagemapLinkToken;
23
+ abstract get nextSibling(): undefined;
24
+ abstract get nextElementSibling(): undefined;
25
+ abstract get previousSibling(): AttributesToken;
26
+ abstract get previousElementSibling(): AttributesToken;
27
+ abstract get parentNode(): ExtToken | undefined;
28
+ abstract get parentElement(): ExtToken | undefined;
29
+ /**
30
+ * 图片
31
+ * @browser
32
+ */
33
+ get image(): GalleryImageToken | undefined;
34
+ /** 链接 */
35
+ get links(): ImagemapLinkToken[];
7
36
  /**
8
- * @param {string} inner 标签内部wikitext
9
- * @param {import('../../typings/token').accum} accum
37
+ * @browser
38
+ * @param inner 标签内部wikitext
10
39
  * @throws `SyntaxError` 没有合法图片
11
40
  */
12
- constructor(inner: string, config?: import("../../typings/token").ParserConfig, accum?: import('../../typings/token').accum);
41
+ constructor(inner?: string, config?: Parser.Config, accum?: Token[]);
13
42
  /**
14
- * 图片
15
- * @returns {GalleryImageToken}
43
+ * @override
44
+ * @browser
16
45
  */
17
- get image(): GalleryImageToken;
46
+ toString(selector?: string): string;
18
47
  /**
19
- * 链接
20
- * @returns {ImagemapLinkToken[]}
48
+ * @override
49
+ * @browser
21
50
  */
22
- get links(): ImagemapLinkToken[];
51
+ text(): string;
23
52
  /**
24
53
  * @override
25
- * @param {string} selector
54
+ * @browser
26
55
  */
27
- override toString(selector: string): string;
28
- /** @override */
29
- override text(): string;
30
- /** @override */
31
- override print(): string;
56
+ print(): string;
57
+ /**
58
+ * @override
59
+ * @browser
60
+ */
61
+ lint(start?: number): Parser.LintError[];
62
+ /**
63
+ * @override
64
+ * @param token 待插入的节点
65
+ * @param i 插入位置
66
+ * @throws `Error` 当前缺少合法图片
67
+ * @throws `RangeError` 已有一张合法图片
68
+ */
69
+ insertAt(token: string, i?: number): AstText;
70
+ /** @ignore */
71
+ insertAt<T extends AstNodeTypes>(token: T, i?: number): T;
72
+ /**
73
+ * @override
74
+ * @param i 移除位置
75
+ * @throws `Error` 禁止移除图片
76
+ */
77
+ removeAt(i: number): AstNodeTypes;
32
78
  /** @override */
33
- override cloneNode(): ImagemapToken;
79
+ cloneNode(): this;
34
80
  }
35
- import Token = require(".");
36
- import GalleryImageToken = require("./link/galleryImage");
37
- import ImagemapLinkToken = require("./imagemapLink");
81
+ export = ImagemapToken;
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ const lint_1 = require("../util/lint");
3
+ const singleLine = require("../mixin/singleLine");
4
+ const Parser = require("../index");
5
+ const Token = require(".");
6
+ const NoincludeToken = require("./nowiki/noinclude");
7
+ const GalleryImageToken = require("./link/galleryImage");
8
+ const ImagemapLinkToken = require("./imagemapLink");
9
+ /**
10
+ * `<imagemap>`
11
+ * @classdesc `{childNodes: ...NoincludeToken, GalleryImageToken, ...(NoincludeToken|ImagemapLinkToken|AstText)}`
12
+ */
13
+ class ImagemapToken extends Token {
14
+ /** @browser */
15
+ type = 'ext-inner';
16
+ /**
17
+ * 图片
18
+ * @browser
19
+ */
20
+ get image() {
21
+ return this.childNodes.find(({ type }) => type === 'imagemap-image');
22
+ }
23
+ /** 链接 */
24
+ get links() {
25
+ return this.childNodes.filter(({ type }) => type === 'imagemap-link');
26
+ }
27
+ /**
28
+ * @browser
29
+ * @param inner 标签内部wikitext
30
+ * @throws `SyntaxError` 没有合法图片
31
+ */
32
+ constructor(inner, config = Parser.getConfig(), accum = []) {
33
+ super(undefined, config, true, accum, {
34
+ GalleryImageToken: ':', ImagemapLinkToken: ':', SingleLineNoincludeToken: ':', AstText: ':',
35
+ });
36
+ if (!inner) {
37
+ return;
38
+ }
39
+ const lines = inner.split('\n'), protocols = new Set(config.protocol.split('|')), SingleLineNoincludeToken = singleLine(NoincludeToken),
40
+ /**
41
+ * 无效文本
42
+ * @param line 一行文本
43
+ */
44
+ fallback = (line) => {
45
+ super.insertAt(new SingleLineNoincludeToken(line, config, accum));
46
+ };
47
+ let first = true, error = false;
48
+ for (const line of lines) {
49
+ const trimmed = line.trim();
50
+ if (error || !trimmed || trimmed.startsWith('#')) {
51
+ //
52
+ }
53
+ else if (first) {
54
+ const [file, ...options] = line.split('|'), title = this.normalizeTitle(file, 0, true);
55
+ if (title.valid && !title.interwiki && title.ns === 6) {
56
+ const token = new GalleryImageToken('imagemap', file, options.length > 0 ? options.join('|') : undefined, config, accum);
57
+ super.insertAt(token);
58
+ first = false;
59
+ continue;
60
+ }
61
+ else {
62
+ Parser.error('<imagemap>标签内必须先包含一张合法图片!', line);
63
+ error = true;
64
+ }
65
+ }
66
+ else if (line.trim().split(/[\t ]/u)[0] === 'desc') {
67
+ super.insertAt(line);
68
+ continue;
69
+ }
70
+ else if (line.includes('[')) {
71
+ const i = line.indexOf('['), substr = line.slice(i), mtIn = /^\[{2}([^|]+)(?:\|([^\]]+))?\]{2}[\w\s]*$/u
72
+ .exec(substr);
73
+ if (mtIn) {
74
+ const title = this.normalizeTitle(mtIn[1], 0, true, false, true);
75
+ if (title.valid) {
76
+ super.insertAt(new ImagemapLinkToken(line.slice(0, i), mtIn.slice(1), substr.slice(substr.indexOf(']]') + 2), config, accum));
77
+ continue;
78
+ }
79
+ }
80
+ else if (protocols.has(substr.slice(1, substr.indexOf(':') + 1))
81
+ || protocols.has(substr.slice(1, substr.indexOf('//') + 2))) {
82
+ const mtEx = /^\[([^\]\s]+)(?:(\s+)(\S[^\]]*)?)?\][\w\s]*$/u
83
+ .exec(substr);
84
+ if (mtEx) {
85
+ super.insertAt(new ImagemapLinkToken(line.slice(0, i), mtEx.slice(1), substr.slice(substr.indexOf(']') + 1), config, accum));
86
+ continue;
87
+ }
88
+ }
89
+ }
90
+ fallback(line);
91
+ }
92
+ }
93
+ /**
94
+ * @override
95
+ * @browser
96
+ */
97
+ toString(selector) {
98
+ return super.toString(selector, '\n');
99
+ }
100
+ /**
101
+ * @override
102
+ * @browser
103
+ */
104
+ text() {
105
+ return super.text('\n').replace(/\n{2,}/gu, '\n');
106
+ }
107
+ /** @private */
108
+ getGaps() {
109
+ return 1;
110
+ }
111
+ /**
112
+ * @override
113
+ * @browser
114
+ */
115
+ print() {
116
+ return super.print({ sep: '\n' });
117
+ }
118
+ /**
119
+ * @override
120
+ * @browser
121
+ */
122
+ lint(start = this.getAbsoluteIndex()) {
123
+ const errors = super.lint(start), rect = { start, ...this.getRootNode().posFromIndex(start) };
124
+ if (this.image) {
125
+ errors.push(...this.childNodes.filter(child => {
126
+ const str = String(child).trim();
127
+ return child.type === 'noinclude' && str && !str.startsWith('#');
128
+ }).map(child => (0, lint_1.generateForChild)(child, rect, 'invalid link in <imagemap>')));
129
+ }
130
+ else {
131
+ errors.push((0, lint_1.generateForSelf)(this, rect, '<imagemap> without an image'));
132
+ }
133
+ return errors;
134
+ }
135
+ /** @ignore */
136
+ insertAt(token, i = 0) {
137
+ const { image } = this;
138
+ if (!image && (typeof token === 'string' || token.type === 'imagemap-link' || token.type === 'text')) {
139
+ throw new Error('当前缺少一张合法图片!');
140
+ }
141
+ else if (image && typeof token !== 'string' && token.type === 'imagemap-image') {
142
+ throw new RangeError('已有一张合法图片!');
143
+ }
144
+ return super.insertAt(token, i);
145
+ }
146
+ /**
147
+ * @override
148
+ * @param i 移除位置
149
+ * @throws `Error` 禁止移除图片
150
+ */
151
+ removeAt(i) {
152
+ const child = this.childNodes[i];
153
+ if (child.type === 'imagemap-image') {
154
+ throw new Error('禁止移除<imagemap>内的图片!');
155
+ }
156
+ return super.removeAt(i);
157
+ }
158
+ /** @override */
159
+ cloneNode() {
160
+ const cloned = this.cloneChildNodes();
161
+ return Parser.run(() => {
162
+ const token = new ImagemapToken(undefined, this.getAttribute('config'));
163
+ token.append(...cloned);
164
+ return token;
165
+ });
166
+ }
167
+ }
168
+ Parser.classes['ImagemapToken'] = __filename;
169
+ module.exports = ImagemapToken;
@@ -1,21 +1,53 @@
1
- export = ImagemapLinkToken;
1
+ import * as Parser from '../index';
2
+ import Title = require('../lib/title');
3
+ import AstText = require('../lib/text');
4
+ import Token = require('.');
5
+ import NoincludeToken = require('./nowiki/noinclude');
6
+ import LinkToken = require('./link');
7
+ import ExtLinkToken = require('./extLink');
8
+ declare const ImagemapLinkToken_base: ((abstract new (...args: any[]) => {
9
+ removeAt(): never;
10
+ insertAt(token: string, i?: number | undefined): AstText;
11
+ insertAt<T extends import("../lib/node").AstNodeTypes>(token: T, i?: number | undefined): T;
12
+ length: number;
13
+ toString(selector?: string | undefined, separator?: string | undefined): string;
14
+ /**
15
+ * `<imagemap>`内的链接
16
+ * @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
17
+ */
18
+ text(separator?: string | undefined): string;
19
+ }) & {
20
+ readonly fixed: true;
21
+ }) & (abstract new (...args: any[]) => {
22
+ toString(selector?: string | undefined): string;
23
+ text(): string;
24
+ length: number;
25
+ insertAt(token: unknown, i?: number | undefined): unknown;
26
+ }) & typeof Token;
2
27
  /**
3
28
  * `<imagemap>`内的链接
4
29
  * @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
5
30
  */
6
- declare class ImagemapLinkToken extends Token {
7
- /**
8
- * @param {string} pre 链接前的文本
9
- * @param {[string, string, string|Title]} linkStuff 内外链接
10
- * @param {string} post 链接后的文本
11
- * @param {import('../../typings/token').accum} accum
12
- */
13
- constructor(pre: string, linkStuff: [string, string, string | Title], post: string, config: any, accum: import('../../typings/token').accum);
31
+ declare abstract class ImagemapLinkToken extends ImagemapLinkToken_base {
32
+ /** @browser */
33
+ readonly type = "imagemap-link";
34
+ childNodes: [AstText, LinkToken | ExtLinkToken, NoincludeToken];
35
+ abstract get children(): [LinkToken | ExtLinkToken, NoincludeToken];
36
+ abstract get firstChild(): AstText;
37
+ abstract get firstElementChild(): LinkToken | ExtLinkToken;
38
+ abstract get lastChild(): NoincludeToken;
39
+ abstract get lastElementChild(): NoincludeToken;
40
+ abstract get parentNode(): import('./imagemap') | undefined;
41
+ abstract get parentElement(): import('./imagemap') | undefined;
42
+ /** 内外链接 */
43
+ get link(): string | Title;
44
+ set link(link: string | Title);
14
45
  /**
15
- * 内外链接
16
- * @this {{childNodes: (LinkToken|ExtLinkToken)[]}}
46
+ * @browser
47
+ * @param pre 链接前的文本
48
+ * @param linkStuff 内外链接
49
+ * @param post 链接后的文本
17
50
  */
18
- get link(): string | Title;
51
+ constructor(pre: string, linkStuff: [string, string | undefined, string | Title | undefined] | [string, string | undefined], post: string, config?: Parser.Config, accum?: Token[]);
19
52
  }
20
- import Token = require(".");
21
- import Title = require("../lib/title");
53
+ export = ImagemapLinkToken;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ const fixed = require("../mixin/fixed");
3
+ const singleLine = require("../mixin/singleLine");
4
+ const Parser = require("../index");
5
+ const Token = require(".");
6
+ const NoincludeToken = require("./nowiki/noinclude");
7
+ const LinkToken = require("./link");
8
+ const ExtLinkToken = require("./extLink");
9
+ /**
10
+ * `<imagemap>`内的链接
11
+ * @classdesc `{childNodes: [AstText, LinkToken|ExtLinkToken, NoincludeToken]}`
12
+ */
13
+ class ImagemapLinkToken extends fixed(singleLine(Token)) {
14
+ /** @browser */
15
+ type = 'imagemap-link';
16
+ /** 内外链接 */
17
+ get link() {
18
+ return this.childNodes[1].link;
19
+ }
20
+ set link(link) {
21
+ this.childNodes[1].link = link;
22
+ }
23
+ /**
24
+ * @browser
25
+ * @param pre 链接前的文本
26
+ * @param linkStuff 内外链接
27
+ * @param post 链接后的文本
28
+ */
29
+ constructor(pre, linkStuff, post, config = Parser.getConfig(), accum = []) {
30
+ super(undefined, config, true, accum);
31
+ this.append(pre, linkStuff.length === 2
32
+ ? new LinkToken(...linkStuff, config, accum)
33
+ : new ExtLinkToken(...linkStuff, config, accum),
34
+ new NoincludeToken(post, config, accum));
35
+ }
36
+ }
37
+ Parser.classes['ImagemapLinkToken'] = __filename;
38
+ module.exports = ImagemapLinkToken;
@@ -1,165 +1,146 @@
1
- export = Token;
1
+ import type { AstNodeTypes, TokenAttributeGetter, TokenAttributeSetter, CaretPosition } from '../lib/node';
2
+ import * as Ranges from '../lib/ranges';
3
+ import * as Parser from '../index';
4
+ import AstElement = require('../lib/element');
5
+ import AstText = require('../lib/text');
6
+ declare type TokenTypes = 'root' | 'plain' | 'onlyinclude' | 'noinclude' | 'include' | 'comment' | 'ext' | 'ext-attrs' | 'ext-attr-dirty' | 'ext-attr' | 'attr-key' | 'attr-value' | 'ext-inner' | 'arg' | 'arg-name' | 'arg-default' | 'hidden' | 'magic-word' | 'magic-word-name' | 'invoke-function' | 'invoke-module' | 'template' | 'template-name' | 'parameter' | 'parameter-key' | 'parameter-value' | 'heading' | 'heading-title' | 'heading-trail' | 'html' | 'html-attrs' | 'html-attr-dirty' | 'html-attr' | 'table' | 'tr' | 'td' | 'table-syntax' | 'table-attrs' | 'table-attr-dirty' | 'table-attr' | 'table-inter' | 'td-inner' | 'hr' | 'double-underscore' | 'link' | 'link-target' | 'link-text' | 'category' | 'file' | 'gallery-image' | 'imagemap-image' | 'image-parameter' | 'quote' | 'ext-link' | 'ext-link-text' | 'ext-link-url' | 'free-ext-link' | 'list' | 'dd' | 'converter' | 'converter-flags' | 'converter-flag' | 'converter-rule' | 'converter-rule-noconvert' | 'converter-rule-variant' | 'converter-rule-to' | 'converter-rule-from' | 'param-line' | 'charinsert-line' | 'imagemap-link';
7
+ declare type TagToken = import('./tagPair/include') | import('./tagPair/ext') | import('./html');
2
8
  /**
3
9
  * 所有节点的基类
4
10
  * @classdesc `{childNodes: ...(AstText|Token)}`
5
11
  */
6
12
  declare class Token extends AstElement {
7
- /**
8
- * @param {string} wikitext wikitext
9
- * @param {import('../../typings/token').accum} accum
10
- * @param {acceptable} acceptable 可接受的子节点设置
11
- */
12
- constructor(wikitext: string, config?: import("../../typings/token").ParserConfig, halfParsed?: boolean, accum?: import('../../typings/token').accum, acceptable?: acceptable);
13
+ #private;
14
+ /** @browser */
15
+ type: TokenTypes;
13
16
  /** 所有图片,包括图库 */
14
17
  get images(): Token[];
15
18
  /** 所有内链、外链和自由外链 */
16
19
  get links(): Token[];
17
20
  /** 所有模板和模块 */
18
- get embeds(): Token[];
21
+ get embeds(): import('./transclude')[];
22
+ /** @browser */
23
+ constructor(wikitext?: string, config?: Parser.Config, halfParsed?: boolean, accum?: Token[], acceptable?: Acceptable);
19
24
  /**
20
- * @override
21
- * @template {string} T
22
- * @param {T} key 属性键
23
- * @param {TokenAttribute<T>} value 属性值
25
+ * 解析、重构、生成部分Token的`name`属性
26
+ * @browser
27
+ * @param n 最大解析层级
28
+ * @param include 是否嵌入
24
29
  */
25
- override setAttribute<T extends string>(key: T, value: import("../../typings/node").TokenAttribute<T>): Token | this;
26
- /** 是否是普通节点 */
27
- isPlain(): boolean;
30
+ parse(n?: number, include?: boolean): this;
28
31
  /**
29
32
  * @override
30
- * @template {string|Token} T
31
- * @param {T} token 待插入的子节点
32
- * @param {number} i 插入位置
33
- * @complexity `n`
34
- * @returns {T extends Token ? Token : AstText}
33
+ * @browser
34
+ * @param child 待插入的子节点
35
+ * @param i 插入位置
35
36
  * @throws `RangeError` 不可插入的子节点
36
37
  */
37
- override insertAt<T_1 extends string | Token>(token: T_1, i?: number): T_1 extends Token ? Token : AstText;
38
+ insertAt(child: string, i?: number): AstText;
39
+ /** @ignore */
40
+ insertAt<T extends AstNodeTypes>(child: T, i?: number): T;
38
41
  /**
39
42
  * 规范化页面标题
40
- * @param {string} title 标题(含或不含命名空间前缀)
41
- * @param {number} defaultNs 命名空间
42
- * @param {boolean} decode 是否需要解码
43
- * @param {boolean} selfLink 是否允许selfLink
43
+ * @browser
44
+ * @param title 标题(含或不含命名空间前缀)
45
+ * @param defaultNs 命名空间
46
+ * @param decode 是否需要解码
47
+ * @param selfLink 是否允许selfLink
44
48
  */
45
- normalizeTitle(title: string, defaultNs?: number, halfParsed?: boolean, decode?: boolean, selfLink?: boolean): import("../lib/title");
49
+ normalizeTitle(title: string, defaultNs?: number, halfParsed?: boolean, decode?: boolean, selfLink?: boolean): import('../lib/title');
46
50
  /**
47
51
  * @override
48
- * @param {number} i 移除位置
49
- * @returns {Token}
50
- * @complexity `n`
52
+ * @param i 移除位置
51
53
  * @throws `Error` 不可移除的子节点
52
54
  */
53
- override removeAt(i: number): Token;
55
+ removeAt(i: number): AstNodeTypes;
54
56
  /**
55
57
  * 替换为同类节点
56
- * @param {Token} token 待替换的节点
57
- * @complexity `n`
58
+ * @param token 待替换的节点
58
59
  * @throws `Error` 不存在父节点
59
60
  * @throws `Error` 待替换的节点具有不同属性
60
61
  */
61
- safeReplaceWith(token: Token): void;
62
+ safeReplaceWith(token: this): void;
62
63
  /**
63
64
  * 创建HTML注释
64
- * @param {string} data 注释内容
65
+ * @param data 注释内容
65
66
  */
66
- createComment(data?: string): import("./nowiki/comment");
67
+ createComment(data?: string): import('./nowiki/comment');
67
68
  /**
68
69
  * 创建标签
69
- * @param {string} tagName 标签名
70
- * @param {{selfClosing: boolean, closing: boolean}} options 选项
70
+ * @param tagName 标签名
71
+ * @param options 选项
72
+ * @param options.selfClosing 是否自封闭
73
+ * @param options.closing 是否是闭合标签
71
74
  * @throws `RangeError` 非法的标签名
72
75
  */
73
76
  createElement(tagName: string, { selfClosing, closing }?: {
74
- selfClosing: boolean;
75
- closing: boolean;
76
- }): any;
77
+ selfClosing?: boolean;
78
+ closing?: boolean;
79
+ }): TagToken;
77
80
  /**
78
81
  * 创建纯文本节点
79
- * @param {string} data 文本内容
82
+ * @param data 文本内容
80
83
  */
81
84
  createTextNode(data?: string): AstText;
82
85
  /**
83
86
  * 找到给定位置所在的节点
84
- * @param {number} index 位置
87
+ * @param index 位置
85
88
  */
86
- caretPositionFromIndex(index: number): {
87
- offsetNode: Token;
88
- offset: number;
89
- };
89
+ caretPositionFromIndex(index?: number): CaretPosition | undefined;
90
90
  /**
91
91
  * 找到给定位置所在的节点
92
- * @param {number} x 列数
93
- * @param {number} y 行数
92
+ * @param x 列数
93
+ * @param y 行数
94
94
  */
95
- caretPositionFromPoint(x: number, y: number): {
96
- offsetNode: Token;
97
- offset: number;
98
- };
95
+ caretPositionFromPoint(x: number, y: number): CaretPosition | undefined;
99
96
  /**
100
97
  * 找到给定位置所在的最外层节点
101
- * @param {number} index 位置
98
+ * @param index 位置
102
99
  * @throws `Error` 不是根节点
103
100
  */
104
- elementFromIndex(index: number): this;
101
+ elementFromIndex(index?: number): AstNodeTypes | undefined;
105
102
  /**
106
103
  * 找到给定位置所在的最外层节点
107
- * @param {number} x 列数
108
- * @param {number} y 行数
104
+ * @param x 列数
105
+ * @param y 行数
109
106
  */
110
- elementFromPoint(x: number, y: number): this;
107
+ elementFromPoint(x: number, y: number): AstNodeTypes | undefined;
111
108
  /**
112
109
  * 找到给定位置所在的所有节点
113
- * @param {number} index 位置
110
+ * @param index 位置
114
111
  */
115
- elementsFromIndex(index: number): Token[];
112
+ elementsFromIndex(index?: number): AstNodeTypes[];
116
113
  /**
117
114
  * 找到给定位置所在的所有节点
118
- * @param {number} x 列数
119
- * @param {number} y 行数
115
+ * @param x 列数
116
+ * @param y 行数
120
117
  */
121
- elementsFromPoint(x: number, y: number): Token[];
118
+ elementsFromPoint(x: number, y: number): AstNodeTypes[];
122
119
  /**
123
120
  * 判断标题是否是跨维基链接
124
- * @param {string} title 标题
125
- */
126
- isInterwiki(title: string): RegExpMatchArray;
127
- /**
128
- * 深拷贝所有子节点
129
- * @complexity `n`
130
- * @returns {(AstText|Token)[]}
121
+ * @param title 标题
131
122
  */
132
- cloneChildNodes(): (AstText | Token)[];
123
+ isInterwiki(title: string): [string, string] | null;
133
124
  /**
134
125
  * 深拷贝节点
135
- * @complexity `n`
136
126
  * @throws `Error` 未定义复制方法
137
127
  */
138
- cloneNode(): Token;
139
- /**
140
- * 获取全部章节
141
- * @complexity `n`
142
- */
143
- sections(): (Token | AstText)[][];
128
+ cloneNode(): this;
129
+ /** 获取全部章节 */
130
+ sections(): (AstText | Token)[][] | undefined;
144
131
  /**
145
132
  * 获取指定章节
146
- * @param {number} n 章节序号
147
- * @complexity `n`
133
+ * @param n 章节序号
148
134
  */
149
- section(n: number): (Token | AstText)[];
135
+ section(n: number): (AstText | Token)[] | undefined;
150
136
  /**
151
137
  * 获取指定的外层HTML标签
152
- * @param {string|undefined} tag HTML标签名
153
- * @returns {[Token, Token]}
154
- * @complexity `n`
138
+ * @param tag HTML标签名
155
139
  * @throws `RangeError` 非法的标签或空标签
156
140
  */
157
- findEnclosingHtml(tag: string | undefined): [Token, Token];
158
- /**
159
- * 获取全部分类
160
- * @complexity `n`
161
- */
162
- getCategories(): any[][];
141
+ findEnclosingHtml(tag?: string): [import('./html'), import('./html')] | undefined;
142
+ /** 获取全部分类 */
143
+ getCategories(): [string, string | undefined][];
163
144
  /**
164
145
  * 重新解析单引号
165
146
  * @throws `Error` 不接受QuoteToken作为子节点
@@ -167,20 +148,5 @@ declare class Token extends AstElement {
167
148
  redoQuotes(): void;
168
149
  /** 解析部分魔术字 */
169
150
  solveConst(): void;
170
- /** 生成部分Token的`name`属性 */
171
- afterBuild(): void;
172
- /**
173
- * 解析、重构、生成部分Token的`name`属性
174
- * @param {number} n 最大解析层级
175
- * @param {boolean} include 是否嵌入
176
- */
177
- parse(n?: number, include?: boolean): Token;
178
- #private;
179
151
  }
180
- declare namespace Token {
181
- export { acceptable, TokenAttribute };
182
- }
183
- import AstElement = require("../lib/element");
184
- import AstText = require("../lib/text");
185
- type acceptable = import('../../typings/token').acceptable;
186
- type TokenAttribute<T> = import('../../typings/node').TokenAttribute<T>;
152
+ export = Token;