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.
- package/config/.schema.json +26 -0
- package/dist/index.d.ts +61 -113
- package/dist/index.js +314 -0
- package/dist/lib/element.d.ts +122 -108
- package/dist/lib/element.js +656 -0
- package/dist/lib/node.d.ts +115 -221
- package/dist/lib/node.js +473 -0
- package/dist/lib/ranges.d.ts +27 -26
- package/dist/lib/ranges.js +130 -0
- package/dist/lib/text.d.ts +36 -28
- package/dist/lib/text.js +215 -0
- package/dist/lib/title.d.ts +26 -12
- package/dist/lib/title.js +108 -0
- package/dist/mixin/attributesParent.js +90 -0
- package/dist/mixin/fixed.js +29 -0
- package/dist/mixin/hidden.js +19 -0
- package/dist/mixin/singleLine.js +23 -0
- package/dist/mixin/sol.js +41 -0
- package/dist/parser/brackets.js +118 -0
- package/dist/parser/commentAndExt.js +48 -0
- package/dist/parser/converter.js +31 -0
- package/dist/parser/externalLinks.js +22 -0
- package/dist/parser/hrAndDoubleUnderscore.js +35 -0
- package/dist/parser/html.js +29 -0
- package/dist/parser/links.js +86 -0
- package/dist/parser/list.js +51 -0
- package/dist/parser/magicLinks.js +32 -0
- package/dist/parser/quotes.js +57 -0
- package/dist/parser/selector.js +158 -0
- package/dist/parser/table.js +108 -0
- package/dist/src/arg.d.ts +47 -23
- package/dist/src/arg.js +196 -0
- package/dist/src/atom.d.ts +12 -0
- package/dist/src/atom.js +22 -0
- package/dist/src/attribute.d.ts +74 -33
- package/dist/src/attribute.js +433 -0
- package/dist/src/attributes.d.ts +61 -55
- package/dist/src/attributes.js +371 -0
- package/dist/src/converter.d.ts +45 -71
- package/dist/src/converter.js +135 -0
- package/dist/src/converterFlags.d.ts +64 -39
- package/dist/src/converterFlags.js +235 -0
- package/dist/src/converterRule.d.ts +49 -27
- package/dist/src/converterRule.js +255 -0
- package/dist/src/extLink.d.ts +41 -38
- package/dist/src/extLink.js +154 -0
- package/dist/src/gallery.d.ts +59 -18
- package/dist/src/gallery.js +132 -0
- package/dist/src/heading.d.ts +60 -22
- package/dist/src/heading.js +135 -0
- package/dist/src/hidden.d.ts +20 -0
- package/dist/src/hidden.js +24 -0
- package/dist/src/html.d.ts +83 -29
- package/dist/src/html.js +242 -0
- package/dist/src/imageParameter.d.ts +59 -40
- package/dist/src/imageParameter.js +251 -0
- package/dist/src/imagemap.d.ts +65 -21
- package/dist/src/imagemap.js +169 -0
- package/dist/src/imagemapLink.d.ts +46 -14
- package/dist/src/imagemapLink.js +38 -0
- package/dist/src/index.d.ts +71 -105
- package/dist/src/index.js +826 -0
- package/dist/src/link/base.d.ts +71 -0
- package/dist/src/link/base.js +225 -0
- package/dist/src/link/category.d.ts +10 -11
- package/dist/src/link/category.js +26 -0
- package/dist/src/link/file.d.ts +61 -39
- package/dist/src/link/file.js +242 -0
- package/dist/src/link/galleryImage.d.ts +34 -12
- package/dist/src/link/galleryImage.js +98 -0
- package/dist/src/link/index.d.ts +25 -63
- package/dist/src/link/index.js +136 -0
- package/dist/src/magicLink.d.ts +22 -15
- package/dist/src/magicLink.js +126 -0
- package/dist/src/nested.d.ts +47 -0
- package/dist/src/nested.js +84 -0
- package/dist/src/nowiki/base.d.ts +39 -0
- package/dist/src/nowiki/base.js +29 -0
- package/dist/src/nowiki/comment.d.ts +31 -20
- package/dist/src/nowiki/comment.js +61 -0
- package/dist/src/nowiki/dd.d.ts +17 -11
- package/dist/src/nowiki/dd.js +50 -0
- package/dist/src/nowiki/doubleUnderscore.d.ts +28 -13
- package/dist/src/nowiki/doubleUnderscore.js +45 -0
- package/dist/src/nowiki/hr.d.ts +28 -10
- package/dist/src/nowiki/hr.js +33 -0
- package/dist/src/nowiki/index.d.ts +17 -23
- package/dist/src/nowiki/index.js +21 -0
- package/dist/src/nowiki/list.d.ts +15 -7
- package/dist/src/nowiki/list.js +11 -0
- package/dist/src/nowiki/noinclude.d.ts +20 -7
- package/dist/src/nowiki/noinclude.js +22 -0
- package/dist/src/nowiki/quote.d.ts +25 -10
- package/dist/src/nowiki/quote.js +55 -0
- package/dist/src/onlyinclude.d.ts +28 -12
- package/dist/src/onlyinclude.js +64 -0
- package/dist/src/paramTag/index.d.ts +40 -17
- package/dist/src/paramTag/index.js +76 -0
- package/dist/src/paramTag/inputbox.d.ts +8 -7
- package/dist/src/paramTag/inputbox.js +19 -0
- package/dist/src/parameter.d.ts +62 -41
- package/dist/src/parameter.js +201 -0
- package/dist/src/pre.d.ts +32 -0
- package/dist/src/pre.js +39 -0
- package/dist/src/syntax.d.ts +17 -14
- package/dist/src/syntax.js +65 -0
- package/dist/src/table/base.d.ts +55 -0
- package/dist/src/table/base.js +77 -0
- package/dist/src/table/index.d.ts +123 -156
- package/dist/src/table/index.js +811 -0
- package/dist/src/table/td.d.ts +90 -67
- package/dist/src/table/td.js +276 -0
- package/dist/src/table/tr.d.ts +30 -85
- package/dist/src/table/tr.js +48 -0
- package/dist/src/table/trBase.d.ts +72 -0
- package/dist/src/table/trBase.js +153 -0
- package/dist/src/tagPair/ext.d.ts +47 -11
- package/dist/src/tagPair/ext.js +127 -0
- package/dist/src/tagPair/include.d.ts +32 -13
- package/dist/src/tagPair/include.js +40 -0
- package/dist/src/tagPair/index.d.ts +44 -29
- package/dist/src/tagPair/index.js +111 -0
- package/dist/src/transclude.d.ts +88 -85
- package/dist/src/transclude.js +739 -0
- package/dist/util/base.js +26 -0
- package/dist/util/debug.js +52 -0
- package/dist/util/diff.js +69 -0
- package/dist/util/lint.js +38 -0
- package/dist/util/string.js +103 -0
- package/errors/README +1 -0
- package/i18n/zh-hans.json +1 -0
- package/i18n/zh-hant.json +1 -0
- package/package.json +21 -24
- package/printed/README +1 -0
- package/dist/mixin/attributeParent.d.ts +0 -9
- package/dist/mixin/fixedToken.d.ts +0 -8
- package/dist/mixin/hidden.d.ts +0 -8
- package/dist/mixin/singleLine.d.ts +0 -8
- package/dist/mixin/sol.d.ts +0 -8
- package/dist/parser/brackets.d.ts +0 -12
- package/dist/parser/commentAndExt.d.ts +0 -8
- package/dist/parser/converter.d.ts +0 -7
- package/dist/parser/externalLinks.d.ts +0 -7
- package/dist/parser/hrAndDoubleUnderscore.d.ts +0 -11
- package/dist/parser/html.d.ts +0 -7
- package/dist/parser/links.d.ts +0 -7
- package/dist/parser/list.d.ts +0 -7
- package/dist/parser/magicLinks.d.ts +0 -7
- package/dist/parser/quotes.d.ts +0 -7
- package/dist/parser/selector.d.ts +0 -12
- package/dist/parser/table.d.ts +0 -11
- package/dist/src/atom/hidden.d.ts +0 -5
- package/dist/src/atom/index.d.ts +0 -15
- package/dist/src/charinsert.d.ts +0 -32
- package/dist/src/hasNowiki/index.d.ts +0 -14
- package/dist/src/hasNowiki/pre.d.ts +0 -13
- package/dist/src/nested/choose.d.ts +0 -13
- package/dist/src/nested/combobox.d.ts +0 -13
- package/dist/src/nested/index.d.ts +0 -18
- package/dist/src/nested/references.d.ts +0 -13
- package/dist/tool/index.d.ts +0 -420
- package/dist/util/base.d.ts +0 -10
- package/dist/util/debug.d.ts +0 -20
- package/dist/util/diff.d.ts +0 -8
- package/dist/util/lint.d.ts +0 -28
- package/dist/util/string.d.ts +0 -55
- package/index.js +0 -333
- package/lib/element.js +0 -618
- package/lib/node.js +0 -730
- package/lib/ranges.js +0 -130
- package/lib/text.js +0 -265
- package/lib/title.js +0 -83
- package/mixin/attributeParent.js +0 -117
- package/mixin/fixedToken.js +0 -40
- package/mixin/hidden.js +0 -21
- package/mixin/singleLine.js +0 -31
- package/mixin/sol.js +0 -54
- package/parser/brackets.js +0 -128
- package/parser/commentAndExt.js +0 -62
- package/parser/converter.js +0 -46
- package/parser/externalLinks.js +0 -33
- package/parser/hrAndDoubleUnderscore.js +0 -49
- package/parser/html.js +0 -42
- package/parser/links.js +0 -94
- package/parser/list.js +0 -59
- package/parser/magicLinks.js +0 -41
- package/parser/quotes.js +0 -64
- package/parser/selector.js +0 -180
- package/parser/table.js +0 -114
- package/src/arg.js +0 -207
- package/src/atom/hidden.js +0 -13
- package/src/atom/index.js +0 -43
- package/src/attribute.js +0 -472
- package/src/attributes.js +0 -453
- package/src/charinsert.js +0 -97
- package/src/converter.js +0 -176
- package/src/converterFlags.js +0 -284
- package/src/converterRule.js +0 -256
- package/src/extLink.js +0 -180
- package/src/gallery.js +0 -149
- package/src/hasNowiki/index.js +0 -44
- package/src/hasNowiki/pre.js +0 -40
- package/src/heading.js +0 -134
- package/src/html.js +0 -254
- package/src/imageParameter.js +0 -303
- package/src/imagemap.js +0 -199
- package/src/imagemapLink.js +0 -41
- package/src/index.js +0 -938
- package/src/link/category.js +0 -44
- package/src/link/file.js +0 -287
- package/src/link/galleryImage.js +0 -120
- package/src/link/index.js +0 -388
- package/src/magicLink.js +0 -151
- package/src/nested/choose.js +0 -24
- package/src/nested/combobox.js +0 -23
- package/src/nested/index.js +0 -96
- package/src/nested/references.js +0 -23
- package/src/nowiki/comment.js +0 -71
- package/src/nowiki/dd.js +0 -59
- package/src/nowiki/doubleUnderscore.js +0 -56
- package/src/nowiki/hr.js +0 -41
- package/src/nowiki/index.js +0 -56
- package/src/nowiki/list.js +0 -16
- package/src/nowiki/noinclude.js +0 -28
- package/src/nowiki/quote.js +0 -69
- package/src/onlyinclude.js +0 -64
- package/src/paramTag/index.js +0 -89
- package/src/paramTag/inputbox.js +0 -35
- package/src/parameter.js +0 -239
- package/src/syntax.js +0 -91
- package/src/table/index.js +0 -985
- package/src/table/td.js +0 -343
- package/src/table/tr.js +0 -319
- package/src/tagPair/ext.js +0 -146
- package/src/tagPair/include.js +0 -50
- package/src/tagPair/index.js +0 -131
- package/src/transclude.js +0 -843
- package/tool/index.js +0 -1209
- package/typings/api.d.ts +0 -9
- package/typings/array.d.ts +0 -29
- package/typings/event.d.ts +0 -22
- package/typings/index.d.ts +0 -118
- package/typings/node.d.ts +0 -35
- package/typings/parser.d.ts +0 -12
- package/typings/table.d.ts +0 -10
- package/typings/token.d.ts +0 -31
- package/typings/tool.d.ts +0 -6
- package/util/base.js +0 -17
- package/util/debug.js +0 -73
- package/util/diff.js +0 -76
- package/util/lint.js +0 -57
- 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
|
-
|
|
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,
|
|
27
|
+
* @classdesc `{childNodes: [AttributesToken, Token]}`
|
|
5
28
|
*/
|
|
6
|
-
declare class ExtToken extends
|
|
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
|
-
* @
|
|
9
|
-
* @param
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
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?:
|
|
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
|
-
|
|
52
|
+
cloneNode(): this;
|
|
17
53
|
}
|
|
18
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
* @
|
|
9
|
-
* @param
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
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?:
|
|
33
|
+
constructor(name: string, attr?: string, inner?: string | undefined, closed?: string | undefined, config?: Parser.Config, accum?: Token[]);
|
|
15
34
|
/** @override */
|
|
16
|
-
|
|
35
|
+
cloneNode(): this;
|
|
17
36
|
/**
|
|
18
37
|
* @override
|
|
19
|
-
* @param
|
|
38
|
+
* @param str 新文本
|
|
20
39
|
*/
|
|
21
|
-
|
|
40
|
+
setText(str: string): string;
|
|
22
41
|
/** 清除标签属性 */
|
|
23
42
|
removeAttr(): void;
|
|
24
43
|
}
|
|
25
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
*
|
|
9
|
-
* @
|
|
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
|
|
19
|
-
/**
|
|
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
|
-
* @
|
|
42
|
+
* @browser
|
|
26
43
|
*/
|
|
27
|
-
|
|
44
|
+
toString(selector?: string): string;
|
|
28
45
|
/**
|
|
29
46
|
* @override
|
|
30
|
-
* @
|
|
47
|
+
* @browser
|
|
31
48
|
*/
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
export { TokenAttribute };
|
|
49
|
+
text(): string;
|
|
50
|
+
/**
|
|
51
|
+
* @override
|
|
52
|
+
* @browser
|
|
53
|
+
*/
|
|
54
|
+
print(): string;
|
|
39
55
|
}
|
|
40
|
-
|
|
41
|
-
type TokenAttribute<T> = import('../../../typings/node').TokenAttribute<T>;
|
|
56
|
+
export = TagPairToken;
|