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,72 @@
1
+ import * as Parser from '../../index';
2
+ import Token = require('..');
3
+ import TableBaseToken = require('./base');
4
+ import TdToken = require('./td');
5
+ import SyntaxToken = require('../syntax');
6
+ import type { AstNodeTypes } from '../../lib/node';
7
+ declare interface TableCoords {
8
+ row: number;
9
+ column: number;
10
+ x?: undefined;
11
+ y?: undefined;
12
+ start?: boolean;
13
+ }
14
+ declare interface TableRenderedCoords {
15
+ row?: undefined;
16
+ column?: undefined;
17
+ x: number;
18
+ y: number;
19
+ }
20
+ /** 表格行或表格 */
21
+ declare abstract class TrBaseToken extends TableBaseToken {
22
+ #private;
23
+ type: 'table' | 'tr';
24
+ /**
25
+ * @override
26
+ * @browser
27
+ */
28
+ lint(start?: number): Parser.LintError[];
29
+ /**
30
+ * @override
31
+ * @browser
32
+ */
33
+ text(): string;
34
+ /** @override */
35
+ toString(selector?: string): string;
36
+ /**
37
+ * @override
38
+ * @param i 移除位置
39
+ */
40
+ removeAt(i: number): AstNodeTypes;
41
+ /**
42
+ * @override
43
+ * @param token 待插入的子节点
44
+ * @param i 插入位置
45
+ */
46
+ insertAt<T extends Token>(token: T, i?: number): T;
47
+ /** 获取行数 */
48
+ getRowCount(): number;
49
+ /** 获取列数 */
50
+ getColCount(): number;
51
+ /**
52
+ * 获取第n列
53
+ * @param n 列号
54
+ * @param insert 是否用于判断插入新列的位置
55
+ * @throws `RangeError` 不存在对应单元格
56
+ */
57
+ getNthCol(n: number, insert?: false): TdToken | undefined;
58
+ /** @ignore */
59
+ getNthCol(n: number, insert: true): TdToken | import('./tr') | SyntaxToken | undefined;
60
+ /**
61
+ * 插入新的单元格
62
+ * @param inner 单元格内部wikitext
63
+ * @param {TableCoords} coord 单元格坐标
64
+ * @param subtype 单元格类型
65
+ * @param attr 单元格属性
66
+ */
67
+ insertTableCell(inner: string | Token, { column }: TableCoords, subtype?: 'td' | 'th' | 'caption', attr?: TdToken.TdAttrs): TdToken;
68
+ }
69
+ declare namespace TrBaseToken {
70
+ export type { TableCoords, TableRenderedCoords, };
71
+ }
72
+ export = TrBaseToken;
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ const lint_1 = require("../../util/lint");
3
+ const Parser = require("../../index");
4
+ const Token = require("..");
5
+ const TableBaseToken = require("./base");
6
+ const TdToken = require("./td");
7
+ /** 表格行或表格 */
8
+ class TrBaseToken extends TableBaseToken {
9
+ /**
10
+ * @override
11
+ * @browser
12
+ */
13
+ lint(start = this.getAbsoluteIndex()) {
14
+ const errors = super.lint(start), inter = this.childNodes.find(({ type }) => type === 'table-inter');
15
+ if (!inter) {
16
+ return errors;
17
+ }
18
+ const first = inter.childNodes.find(child => child.text().trim()), tdPattern = /^\s*(?:!|\{\{\s*![!-]?\s*\}\})/u;
19
+ if (!first || tdPattern.test(String(first))
20
+ || first.type === 'arg' && tdPattern.test(first.default || '')) {
21
+ return errors;
22
+ }
23
+ else if (first.type === 'magic-word') {
24
+ try {
25
+ const possibleValues = first.getPossibleValues();
26
+ if (possibleValues.every(token => tdPattern.test(token.text()))) {
27
+ return errors;
28
+ }
29
+ }
30
+ catch { }
31
+ }
32
+ const error = (0, lint_1.generateForChild)(inter, { start }, 'content to be moved out from the table');
33
+ errors.push({
34
+ ...error,
35
+ startIndex: error.startIndex + 1,
36
+ startLine: error.startLine + 1,
37
+ startCol: 0,
38
+ excerpt: error.excerpt.slice(1),
39
+ });
40
+ return errors;
41
+ }
42
+ /**
43
+ * @override
44
+ * @browser
45
+ */
46
+ text() {
47
+ this.#correct();
48
+ const str = super.text();
49
+ return this.type === 'tr' && !str.trim().includes('\n') ? '' : str;
50
+ }
51
+ /** 修复简单的表格语法错误 */
52
+ #correct() {
53
+ const { childNodes: [, , child] } = this;
54
+ if (child?.constructor === Token) {
55
+ const { firstChild } = child;
56
+ if (firstChild?.type !== 'text') {
57
+ child.prepend('\n');
58
+ }
59
+ else if (!firstChild.data.startsWith('\n')) {
60
+ firstChild.insertData(0, '\n');
61
+ }
62
+ }
63
+ }
64
+ /** @override */
65
+ toString(selector) {
66
+ this.#correct();
67
+ return super.toString(selector);
68
+ }
69
+ /**
70
+ * @override
71
+ * @param i 移除位置
72
+ */
73
+ removeAt(i) {
74
+ const child = this.childNodes.at(i);
75
+ if (child instanceof TdToken && child.isIndependent()) {
76
+ const { nextSibling } = child;
77
+ if (nextSibling?.type === 'td') {
78
+ nextSibling.independence();
79
+ }
80
+ }
81
+ return super.removeAt(i);
82
+ }
83
+ /**
84
+ * @override
85
+ * @param token 待插入的子节点
86
+ * @param i 插入位置
87
+ */
88
+ insertAt(token, i = this.length) {
89
+ if (!Parser.running && !(token instanceof TrBaseToken)) {
90
+ this.typeError('insertAt', 'TrToken');
91
+ }
92
+ const child = this.childNodes.at(i);
93
+ if (token instanceof TdToken && token.isIndependent() && child instanceof TdToken) {
94
+ child.independence();
95
+ }
96
+ return super.insertAt(token, i);
97
+ }
98
+ /** 获取行数 */
99
+ getRowCount() {
100
+ return Number(this.childNodes.some(child => child instanceof TdToken && child.isIndependent() && !child.firstChild.text().endsWith('+')));
101
+ }
102
+ /** 获取列数 */
103
+ getColCount() {
104
+ let count = 0, last = 0;
105
+ for (const child of this.childNodes) {
106
+ if (child instanceof TdToken) {
107
+ last = child.isIndependent() ? Number(child.subtype !== 'caption') : last;
108
+ count += last;
109
+ }
110
+ }
111
+ return count;
112
+ }
113
+ /** @ignore */
114
+ getNthCol(n, insert = false) {
115
+ if (!Number.isInteger(n)) {
116
+ this.typeError('getNthCol', 'Number');
117
+ }
118
+ const nCols = this.getColCount();
119
+ let m = n < 0 ? n + nCols : n;
120
+ if (m < 0 || m > nCols || m === nCols && !insert) {
121
+ throw new RangeError(`不存在第 ${m} 个单元格!`);
122
+ }
123
+ let last = 0;
124
+ for (const child of this.childNodes.slice(2)) {
125
+ if (child instanceof TdToken) {
126
+ if (child.isIndependent()) {
127
+ last = Number(child.subtype !== 'caption');
128
+ }
129
+ m -= last;
130
+ if (m < 0) {
131
+ return child;
132
+ }
133
+ }
134
+ else if (child.type === 'tr' || child.type === 'table-syntax') {
135
+ return child;
136
+ }
137
+ }
138
+ return undefined;
139
+ }
140
+ /**
141
+ * 插入新的单元格
142
+ * @param inner 单元格内部wikitext
143
+ * @param {TableCoords} coord 单元格坐标
144
+ * @param subtype 单元格类型
145
+ * @param attr 单元格属性
146
+ */
147
+ insertTableCell(inner, { column }, subtype = 'td', attr = {}) {
148
+ const token = TdToken.create(inner, subtype, attr, this.getAttribute('include'), this.getAttribute('config'));
149
+ return this.insertBefore(token, this.getNthCol(column, true));
150
+ }
151
+ }
152
+ Parser.classes['TrBaseToken'] = __filename;
153
+ module.exports = TrBaseToken;
@@ -1,18 +1,54 @@
1
- export = ExtToken;
1
+ import * as Parser from '../../index';
2
+ import Token = require('..');
3
+ import TagPairToken = require('.');
4
+ import AttributesToken = require('../attributes');
5
+ declare const ExtToken_base: (abstract new (...args: any[]) => {
6
+ childNodes: import("../../lib/node").AstNodeTypes[];
7
+ readonly "__#12@#attributesChild": AttributesToken;
8
+ readonly attributes: Record<string, string | true>;
9
+ className: string;
10
+ readonly classList: Set<string>;
11
+ id: string;
12
+ hasAttr(key: string): boolean;
13
+ getAttr(key: string): string | true | undefined;
14
+ getAttrNames(): Set<string>;
15
+ hasAttrs(): boolean;
16
+ getAttrs(): Record<string, string | true>;
17
+ setAttr(key: string, value: string | boolean): void;
18
+ removeAttr(key: string): void;
19
+ toggleAttr(key: string, force?: boolean | undefined): void;
20
+ length: number;
21
+ toString(selector?: string | undefined, separator?: string | undefined): string;
22
+ text(separator?: string | undefined): string;
23
+ insertAt(token: unknown, i?: number | undefined): unknown;
24
+ }) & typeof TagPairToken;
2
25
  /**
3
26
  * 扩展标签
4
- * @classdesc `{childNodes: [AttributesToken, NowikiToken|Token]}`
27
+ * @classdesc `{childNodes: [AttributesToken, Token]}`
5
28
  */
6
- declare class ExtToken extends TagPairToken {
29
+ declare abstract class ExtToken extends ExtToken_base {
30
+ readonly type = "ext";
31
+ childNodes: [AttributesToken, Token];
32
+ abstract get children(): [AttributesToken, Token];
33
+ abstract get firstChild(): AttributesToken;
34
+ abstract get firstElementChild(): AttributesToken;
35
+ abstract get lastChild(): Token;
36
+ /** @override */
37
+ get closed(): boolean;
7
38
  /**
8
- * @param {string} name 标签名
9
- * @param {string} attr 标签属性
10
- * @param {string} inner 内部wikitext
11
- * @param {string|undefined} closed 是否封闭
12
- * @param {import('../../../typings/token').accum} accum
39
+ * @browser
40
+ * @param name 标签名
41
+ * @param attr 标签属性
42
+ * @param inner 内部wikitext
43
+ * @param closed 是否封闭
13
44
  */
14
- constructor(name: string, attr?: string, inner?: string, closed?: string | undefined, config?: import("../../../typings/token").ParserConfig, accum?: import('../../../typings/token').accum);
45
+ constructor(name: string, attr?: string, inner?: string, closed?: string | undefined, config?: Parser.Config, accum?: Token[]);
46
+ /**
47
+ * @override
48
+ * @browser
49
+ */
50
+ lint(start?: number): Parser.LintError[];
15
51
  /** @override */
16
- override cloneNode(): ExtToken;
52
+ cloneNode(): this;
17
53
  }
18
- import TagPairToken = require(".");
54
+ export = ExtToken;
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ const lint_1 = require("../../util/lint");
3
+ const base_1 = require("../../util/base");
4
+ const attributesParent = require("../../mixin/attributesParent");
5
+ const Parser = require("../../index");
6
+ const Token = require("..");
7
+ const TagPairToken = require(".");
8
+ const AttributesToken = require("../attributes");
9
+ /**
10
+ * 扩展标签
11
+ * @classdesc `{childNodes: [AttributesToken, Token]}`
12
+ */
13
+ class ExtToken extends attributesParent(TagPairToken) {
14
+ type = 'ext';
15
+ /** @override */
16
+ get closed() {
17
+ return true;
18
+ }
19
+ /**
20
+ * @browser
21
+ * @param name 标签名
22
+ * @param attr 标签属性
23
+ * @param inner 内部wikitext
24
+ * @param closed 是否封闭
25
+ */
26
+ constructor(name, attr = '', inner = '', closed = undefined, config = Parser.getConfig(), accum = []) {
27
+ const lcName = name.toLowerCase(),
28
+ attrToken = new AttributesToken(!attr || attr.trimStart() !== attr ? attr : ` ${attr}`, 'ext-attrs', lcName, config, accum), newConfig = { ...config, ext: (0, base_1.del)(config.ext, lcName), excludes: [...config.excludes ?? []] };
29
+ let innerToken;
30
+ switch (lcName) {
31
+ case 'tab':
32
+ newConfig.ext = (0, base_1.del)(newConfig.ext, 'tabs');
33
+ // fall through
34
+ case 'indicator':
35
+ case 'poem':
36
+ case 'ref':
37
+ case 'option':
38
+ case 'combooption':
39
+ case 'tabs':
40
+ case 'poll':
41
+ case 'seo':
42
+ if (lcName === 'poem') {
43
+ newConfig.excludes.push('heading');
44
+ }
45
+ innerToken = new Token(inner, newConfig, true, accum);
46
+ break;
47
+ case 'pre': {
48
+ const PreToken = require('../pre');
49
+ innerToken = new PreToken(inner, newConfig, accum);
50
+ break;
51
+ }
52
+ case 'dynamicpagelist': {
53
+ const ParamTagToken = require('../paramTag');
54
+ innerToken = new ParamTagToken(inner, newConfig, accum);
55
+ break;
56
+ }
57
+ case 'inputbox': {
58
+ newConfig.excludes.push('heading');
59
+ const InputboxToken = require('../paramTag/inputbox');
60
+ innerToken = new InputboxToken(inner, newConfig, accum);
61
+ break;
62
+ }
63
+ case 'references': {
64
+ const NestedToken = require('../nested');
65
+ innerToken = new NestedToken(inner, /<!--.*?(?:-->|$)|<(ref)(\s[^>]*)?>(.*?)<\/(ref\s*)>/gisu, ['ref'], newConfig, accum);
66
+ break;
67
+ }
68
+ case 'choose': {
69
+ const NestedToken = require('../nested');
70
+ innerToken = new NestedToken(inner, /<(option|choicetemplate)(\s[^>]*)?>(.*?)<\/(\1)>/gsu, ['option', 'choicetemplate'], newConfig, accum);
71
+ break;
72
+ }
73
+ case 'combobox': {
74
+ const NestedToken = require('../nested');
75
+ innerToken = new NestedToken(inner, /<(combooption)(\s[^>]*)?>(.*?)<\/(combooption\s*)>/gisu, ['combooption'], newConfig, accum);
76
+ break;
77
+ }
78
+ case 'gallery': {
79
+ const GalleryToken = require('../gallery');
80
+ innerToken = new GalleryToken(inner, newConfig, accum);
81
+ break;
82
+ }
83
+ case 'imagemap': {
84
+ const ImagemapToken = require('../imagemap');
85
+ innerToken = new ImagemapToken(inner, newConfig, accum);
86
+ break;
87
+ }
88
+ // 更多定制扩展的代码示例:
89
+ // ```
90
+ // case 'extensionName': {
91
+ // const ExtensionToken: typeof import('../extension') = require('../extension');
92
+ // innerToken = new ExtensionToken(inner, newConfig, accum);
93
+ // break;
94
+ // }
95
+ // ```
96
+ default: {
97
+ const NowikiToken = require('../nowiki');
98
+ innerToken = new NowikiToken(inner, newConfig);
99
+ }
100
+ }
101
+ innerToken.setAttribute('name', lcName).type = 'ext-inner';
102
+ super(name, attrToken, innerToken, closed, config, accum);
103
+ }
104
+ /**
105
+ * @override
106
+ * @browser
107
+ */
108
+ lint(start = this.getAbsoluteIndex()) {
109
+ const errors = super.lint(start);
110
+ if (this.name !== 'nowiki' && this.closest('html-attrs, table-attrs')) {
111
+ const root = this.getRootNode(), excerpt = String(root).slice(Math.max(0, start - 25), start + 25), rect = { start, ...root.posFromIndex(start) };
112
+ errors.push({ ...(0, lint_1.generateForSelf)(this, rect, 'extension tag in HTML tag attributes'), excerpt });
113
+ }
114
+ return errors;
115
+ }
116
+ /** @override */
117
+ cloneNode() {
118
+ const inner = this.lastChild.cloneNode(), tags = this.getAttribute('tags'), config = this.getAttribute('config'), attr = String(this.firstChild);
119
+ return Parser.run(() => {
120
+ const token = new ExtToken(tags[0], attr, '', this.selfClosing ? undefined : tags[1], config);
121
+ token.lastChild.safeReplaceWith(inner);
122
+ return token;
123
+ });
124
+ }
125
+ }
126
+ Parser.classes['ExtToken'] = __filename;
127
+ module.exports = ExtToken;
@@ -1,25 +1,44 @@
1
- export = IncludeToken;
1
+ import * as Parser from '../../index';
2
+ import TagPairToken = require('.');
3
+ import Token = require('..');
4
+ import AstText = require('../../lib/text');
5
+ declare const IncludeToken_base: ((abstract new (...args: any[]) => {
6
+ text(): string;
7
+ length: number;
8
+ toString(selector?: string | undefined, separator?: string | undefined): string;
9
+ insertAt(token: unknown, i?: number | undefined): unknown;
10
+ }) & {
11
+ readonly hidden: true;
12
+ }) & typeof TagPairToken;
2
13
  /**
3
- * `<includeonly>`或`<noinclude>`
14
+ * `<includeonly>`或`<noinclude>`或`<onlyinclude>`
4
15
  * @classdesc `{childNodes: [AstText, AstText]}`
5
16
  */
6
- declare class IncludeToken extends TagPairToken {
17
+ declare abstract class IncludeToken extends IncludeToken_base {
18
+ /** @browser */
19
+ readonly type = "include";
20
+ childNodes: [AstText, AstText];
21
+ abstract get children(): [];
22
+ abstract get firstChild(): AstText;
23
+ abstract get firstElementChild(): undefined;
24
+ abstract get lastChild(): AstText;
25
+ abstract get lastElementChild(): undefined;
7
26
  /**
8
- * @param {string} name 标签名
9
- * @param {string} attr 标签属性
10
- * @param {string|undefined} inner 内部wikitext
11
- * @param {string|undefined} closed 是否封闭
12
- * @param {import('../../../typings/token').accum} accum
27
+ * @browser
28
+ * @param name 标签名
29
+ * @param attr 标签属性
30
+ * @param inner 内部wikitext
31
+ * @param closed 是否封闭
13
32
  */
14
- constructor(name: string, attr?: string, inner?: string | undefined, closed?: string | undefined, config?: import("../../../typings/token").ParserConfig, accum?: import('../../../typings/token').accum);
33
+ constructor(name: string, attr?: string, inner?: string | undefined, closed?: string | undefined, config?: Parser.Config, accum?: Token[]);
15
34
  /** @override */
16
- override cloneNode(): IncludeToken;
35
+ cloneNode(): this;
17
36
  /**
18
37
  * @override
19
- * @param {string} str 新文本
38
+ * @param str 新文本
20
39
  */
21
- override setText(str: string): string;
40
+ setText(str: string): string;
22
41
  /** 清除标签属性 */
23
42
  removeAttr(): void;
24
43
  }
25
- import TagPairToken = require(".");
44
+ export = IncludeToken;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ const hidden = require("../../mixin/hidden");
3
+ const Parser = require("../../index");
4
+ const TagPairToken = require(".");
5
+ /**
6
+ * `<includeonly>`或`<noinclude>`或`<onlyinclude>`
7
+ * @classdesc `{childNodes: [AstText, AstText]}`
8
+ */
9
+ class IncludeToken extends hidden(TagPairToken) {
10
+ /** @browser */
11
+ type = 'include';
12
+ /**
13
+ * @browser
14
+ * @param name 标签名
15
+ * @param attr 标签属性
16
+ * @param inner 内部wikitext
17
+ * @param closed 是否封闭
18
+ */
19
+ constructor(name, attr = '', inner = undefined, closed = undefined, config = Parser.getConfig(), accum = []) {
20
+ super(name, attr, inner ?? '', inner === undefined ? closed : closed ?? '', config, accum);
21
+ }
22
+ /** @override */
23
+ cloneNode() {
24
+ const tags = this.getAttribute('tags'), config = this.getAttribute('config'), inner = this.selfClosing ? undefined : this.lastChild.data, closing = this.selfClosing || !this.closed ? undefined : tags[1];
25
+ return Parser.run(() => new IncludeToken(tags[0], this.firstChild.data, inner, closing, config));
26
+ }
27
+ /**
28
+ * @override
29
+ * @param str 新文本
30
+ */
31
+ setText(str) {
32
+ return super.setText(str, 1);
33
+ }
34
+ /** 清除标签属性 */
35
+ removeAttr() {
36
+ super.setText('');
37
+ }
38
+ }
39
+ Parser.classes['IncludeToken'] = __filename;
40
+ module.exports = IncludeToken;
@@ -1,41 +1,56 @@
1
- export = TagPairToken;
2
- /**
3
- * 成对标签
4
- * @classdesc `{childNodes: [AstText|AttributesToken, AstText|Token]}`
5
- */
6
- declare class TagPairToken extends Token {
1
+ import * as Parser from '../../index';
2
+ import Token = require('..');
3
+ import type { AstNodeTypes, TokenAttributeGetter } from '../../lib/node';
4
+ declare const TagPairToken_base: ((abstract new (...args: any[]) => {
5
+ removeAt(): never;
6
+ insertAt(token: string, i?: number | undefined): import("../../lib/text");
7
+ insertAt<T extends AstNodeTypes>(token: T, i?: number | undefined): T;
8
+ length: number;
9
+ toString(selector?: string | undefined, separator?: string | undefined): string;
10
+ text(separator?: string | undefined): string;
11
+ }) & {
12
+ readonly fixed: true; /** @browser */
13
+ }) & typeof Token;
14
+ /** 成对标签 */
15
+ declare abstract class TagPairToken extends TagPairToken_base {
16
+ #private;
17
+ type: 'ext' | 'include';
18
+ name: string;
19
+ abstract get firstChild(): AstNodeTypes;
20
+ abstract get lastChild(): AstNodeTypes;
7
21
  /**
8
- * @param {string} name 标签名
9
- * @param {string|Token} attr 标签属性
10
- * @param {string|Token} inner 内部wikitext
11
- * @param {string|undefined} closed 是否封闭;约定`undefined`表示自闭合,`''`表示未闭合
12
- * @param {import('../../../typings/token').accum} accum
22
+ * 是否闭合
23
+ * @browser
13
24
  */
14
- constructor(name: string, attr: string | Token, inner: string | Token, closed: string | undefined, config?: import("../../../typings/token").ParserConfig, accum?: import('../../../typings/token').accum);
15
- set closed(arg: boolean);
16
- /** getter */
17
25
  get closed(): boolean;
18
- set selfClosing(arg: boolean);
19
- /** getter */
26
+ set closed(value: boolean);
27
+ /** 是否自封闭 */
20
28
  get selfClosing(): boolean;
29
+ set selfClosing(value: boolean);
21
30
  /** 内部wikitext */
22
- get innerText(): string;
31
+ get innerText(): string | undefined;
32
+ /**
33
+ * @browser
34
+ * @param name 标签名
35
+ * @param attr 标签属性
36
+ * @param inner 内部wikitext
37
+ * @param closed 是否封闭;约定`undefined`表示自封闭,`''`表示未闭合
38
+ */
39
+ constructor(name: string, attr: string | Token, inner: string | Token, closed: string | undefined, config?: Parser.Config, accum?: Token[]);
23
40
  /**
24
41
  * @override
25
- * @param {string} selector
42
+ * @browser
26
43
  */
27
- override toString(selector: string): string;
44
+ toString(selector?: string): string;
28
45
  /**
29
46
  * @override
30
- * @returns {string}
47
+ * @browser
31
48
  */
32
- override text(): string;
33
- /** @override */
34
- override print(): string;
35
- #private;
36
- }
37
- declare namespace TagPairToken {
38
- export { TokenAttribute };
49
+ text(): string;
50
+ /**
51
+ * @override
52
+ * @browser
53
+ */
54
+ print(): string;
39
55
  }
40
- import Token = require("..");
41
- type TokenAttribute<T> = import('../../../typings/node').TokenAttribute<T>;
56
+ export = TagPairToken;