wikiparser-node 1.5.2 → 1.5.3-b
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/bundle/bundle.min.js +37 -0
- package/config/enwiki.json +1 -814
- package/config/llwiki.json +1 -35
- package/config/moegirl.json +1 -44
- package/config/zhwiki.json +1 -466
- package/extensions/dist/base.js +64 -0
- package/extensions/dist/editor.js +159 -0
- package/extensions/dist/highlight.js +59 -0
- package/extensions/dist/lint.js +60 -0
- package/extensions/editor.css +63 -0
- package/extensions/ui.css +141 -0
- package/package.json +30 -17
- package/config/.schema.json +0 -172
- package/dist/addon/table.d.ts +0 -6
- package/dist/addon/table.js +0 -564
- package/dist/base.d.ts +0 -72
- package/dist/base.js +0 -38
- package/dist/index.d.ts +0 -30
- package/dist/index.js +0 -214
- package/dist/internal.d.ts +0 -44
- package/dist/lib/element.d.ts +0 -150
- package/dist/lib/element.js +0 -613
- package/dist/lib/node.d.ts +0 -146
- package/dist/lib/node.js +0 -428
- package/dist/lib/range.d.ts +0 -104
- package/dist/lib/range.js +0 -385
- package/dist/lib/ranges.d.ts +0 -26
- package/dist/lib/ranges.js +0 -118
- package/dist/lib/text.d.ts +0 -62
- package/dist/lib/text.js +0 -361
- package/dist/lib/title.d.ts +0 -38
- package/dist/lib/title.js +0 -166
- package/dist/mixin/attributesParent.d.ts +0 -50
- package/dist/mixin/attributesParent.js +0 -78
- package/dist/mixin/fixed.d.ts +0 -6
- package/dist/mixin/fixed.js +0 -30
- package/dist/mixin/flagsParent.d.ts +0 -72
- package/dist/mixin/flagsParent.js +0 -59
- package/dist/mixin/hidden.d.ts +0 -5
- package/dist/mixin/hidden.js +0 -24
- package/dist/mixin/magicLinkParent.d.ts +0 -40
- package/dist/mixin/magicLinkParent.js +0 -42
- package/dist/mixin/singleLine.d.ts +0 -6
- package/dist/mixin/singleLine.js +0 -26
- package/dist/mixin/sol.d.ts +0 -6
- package/dist/mixin/sol.js +0 -43
- package/dist/mixin/syntax.d.ts +0 -9
- package/dist/mixin/syntax.js +0 -50
- package/dist/parser/braces.js +0 -131
- package/dist/parser/commentAndExt.js +0 -90
- package/dist/parser/converter.js +0 -41
- package/dist/parser/externalLinks.js +0 -32
- package/dist/parser/hrAndDoubleUnderscore.js +0 -41
- package/dist/parser/html.js +0 -39
- package/dist/parser/links.js +0 -95
- package/dist/parser/list.js +0 -98
- package/dist/parser/magicLinks.js +0 -43
- package/dist/parser/quotes.js +0 -68
- package/dist/parser/selector.js +0 -162
- package/dist/parser/table.js +0 -124
- package/dist/src/arg.d.ts +0 -58
- package/dist/src/arg.js +0 -214
- package/dist/src/atom.d.ts +0 -12
- package/dist/src/atom.js +0 -27
- package/dist/src/attribute.d.ts +0 -71
- package/dist/src/attribute.js +0 -502
- package/dist/src/attributes.d.ts +0 -109
- package/dist/src/attributes.js +0 -356
- package/dist/src/converter.d.ts +0 -33
- package/dist/src/converter.js +0 -134
- package/dist/src/converterFlags.d.ts +0 -87
- package/dist/src/converterFlags.js +0 -242
- package/dist/src/converterRule.d.ts +0 -77
- package/dist/src/converterRule.js +0 -209
- package/dist/src/extLink.d.ts +0 -43
- package/dist/src/extLink.js +0 -186
- package/dist/src/gallery.d.ts +0 -54
- package/dist/src/gallery.js +0 -139
- package/dist/src/heading.d.ts +0 -47
- package/dist/src/heading.js +0 -190
- package/dist/src/hidden.d.ts +0 -7
- package/dist/src/hidden.js +0 -23
- package/dist/src/html.d.ts +0 -65
- package/dist/src/html.js +0 -358
- package/dist/src/imageParameter.d.ts +0 -65
- package/dist/src/imageParameter.js +0 -257
- package/dist/src/imagemap.d.ts +0 -56
- package/dist/src/imagemap.js +0 -150
- package/dist/src/imagemapLink.d.ts +0 -31
- package/dist/src/imagemapLink.js +0 -93
- package/dist/src/index.d.ts +0 -143
- package/dist/src/index.js +0 -813
- package/dist/src/link/base.d.ts +0 -52
- package/dist/src/link/base.js +0 -229
- package/dist/src/link/category.d.ts +0 -13
- package/dist/src/link/category.js +0 -28
- package/dist/src/link/file.d.ts +0 -98
- package/dist/src/link/file.js +0 -272
- package/dist/src/link/galleryImage.d.ts +0 -32
- package/dist/src/link/galleryImage.js +0 -157
- package/dist/src/link/index.d.ts +0 -56
- package/dist/src/link/index.js +0 -133
- package/dist/src/magicLink.d.ts +0 -59
- package/dist/src/magicLink.js +0 -223
- package/dist/src/nested.d.ts +0 -43
- package/dist/src/nested.js +0 -105
- package/dist/src/nowiki/base.d.ts +0 -31
- package/dist/src/nowiki/base.js +0 -93
- package/dist/src/nowiki/comment.d.ts +0 -25
- package/dist/src/nowiki/comment.js +0 -76
- package/dist/src/nowiki/dd.d.ts +0 -8
- package/dist/src/nowiki/dd.js +0 -24
- package/dist/src/nowiki/doubleUnderscore.d.ts +0 -18
- package/dist/src/nowiki/doubleUnderscore.js +0 -101
- package/dist/src/nowiki/hr.d.ts +0 -5
- package/dist/src/nowiki/hr.js +0 -63
- package/dist/src/nowiki/index.d.ts +0 -16
- package/dist/src/nowiki/index.js +0 -27
- package/dist/src/nowiki/list.d.ts +0 -16
- package/dist/src/nowiki/list.js +0 -97
- package/dist/src/nowiki/listBase.d.ts +0 -5
- package/dist/src/nowiki/listBase.js +0 -61
- package/dist/src/nowiki/noinclude.d.ts +0 -10
- package/dist/src/nowiki/noinclude.js +0 -23
- package/dist/src/nowiki/quote.d.ts +0 -14
- package/dist/src/nowiki/quote.js +0 -131
- package/dist/src/onlyinclude.d.ts +0 -16
- package/dist/src/onlyinclude.js +0 -57
- package/dist/src/paramTag/index.d.ts +0 -37
- package/dist/src/paramTag/index.js +0 -77
- package/dist/src/paramTag/inputbox.d.ts +0 -8
- package/dist/src/paramTag/inputbox.js +0 -22
- package/dist/src/parameter.d.ts +0 -70
- package/dist/src/parameter.js +0 -264
- package/dist/src/pre.d.ts +0 -28
- package/dist/src/pre.js +0 -55
- package/dist/src/syntax.d.ts +0 -20
- package/dist/src/syntax.js +0 -86
- package/dist/src/table/base.d.ts +0 -30
- package/dist/src/table/base.js +0 -132
- package/dist/src/table/index.d.ts +0 -233
- package/dist/src/table/index.js +0 -396
- package/dist/src/table/td.d.ts +0 -86
- package/dist/src/table/td.js +0 -350
- package/dist/src/table/tr.d.ts +0 -32
- package/dist/src/table/tr.js +0 -58
- package/dist/src/table/trBase.d.ts +0 -53
- package/dist/src/table/trBase.js +0 -152
- package/dist/src/tagPair/ext.d.ts +0 -32
- package/dist/src/tagPair/ext.js +0 -203
- package/dist/src/tagPair/include.d.ts +0 -35
- package/dist/src/tagPair/include.js +0 -74
- package/dist/src/tagPair/index.d.ts +0 -27
- package/dist/src/tagPair/index.js +0 -128
- package/dist/src/transclude.d.ts +0 -167
- package/dist/src/transclude.js +0 -717
- package/dist/util/constants.js +0 -28
- package/dist/util/debug.js +0 -88
- package/dist/util/diff.js +0 -83
- package/dist/util/lint.js +0 -31
- package/dist/util/string.js +0 -54
- package/errors/README +0 -1
- package/printed/README +0 -1
package/dist/src/table/trBase.js
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TrBaseToken = void 0;
|
|
4
|
-
const lint_1 = require("../../util/lint");
|
|
5
|
-
const debug_1 = require("../../util/debug");
|
|
6
|
-
const constants_1 = require("../../util/constants");
|
|
7
|
-
const __1 = require("..");
|
|
8
|
-
const base_1 = require("./base");
|
|
9
|
-
const td_1 = require("./td");
|
|
10
|
-
/** 表格行或表格 */
|
|
11
|
-
class TrBaseToken extends base_1.TableBaseToken {
|
|
12
|
-
/** @override */
|
|
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, isArg = (0, debug_1.isToken)('arg'), isTransclude = (0, debug_1.isToken)('magic-word');
|
|
19
|
-
if (!first
|
|
20
|
-
|| tdPattern.test(String(first))
|
|
21
|
-
|| isArg(first) && tdPattern.test(first.default || '')) {
|
|
22
|
-
return errors;
|
|
23
|
-
}
|
|
24
|
-
else if (isTransclude(first)) {
|
|
25
|
-
try {
|
|
26
|
-
if (first.getPossibleValues().every(token => tdPattern.test(token.text()))) {
|
|
27
|
-
return errors;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
catch { }
|
|
31
|
-
}
|
|
32
|
-
const error = (0, lint_1.generateForChild)(inter, { start }, 'fostered-content', 'content to be moved out from the table');
|
|
33
|
-
error.severity = first.type === 'template' ? 'warning' : 'error';
|
|
34
|
-
error.startIndex++;
|
|
35
|
-
error.startLine++;
|
|
36
|
-
error.startCol = 0;
|
|
37
|
-
errors.push(error);
|
|
38
|
-
return errors;
|
|
39
|
-
}
|
|
40
|
-
/* NOT FOR BROWSER */
|
|
41
|
-
/** 修复简单的表格语法错误 */
|
|
42
|
-
#correct() {
|
|
43
|
-
const { childNodes: [, , child] } = this;
|
|
44
|
-
if (child?.constructor === __1.Token) {
|
|
45
|
-
const { firstChild } = child;
|
|
46
|
-
if (firstChild?.type !== 'text') {
|
|
47
|
-
child.prepend('\n');
|
|
48
|
-
}
|
|
49
|
-
else if (!firstChild.data.startsWith('\n')) {
|
|
50
|
-
firstChild.insertData(0, '\n');
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/** @override */
|
|
55
|
-
text() {
|
|
56
|
-
this.#correct();
|
|
57
|
-
return super.text();
|
|
58
|
-
}
|
|
59
|
-
/** @private */
|
|
60
|
-
toString() {
|
|
61
|
-
this.#correct();
|
|
62
|
-
return super.toString();
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* @override
|
|
66
|
-
* @param i 移除位置
|
|
67
|
-
*/
|
|
68
|
-
removeAt(i) {
|
|
69
|
-
i += i < 0 ? this.length : 0;
|
|
70
|
-
const child = this.childNodes[i];
|
|
71
|
-
if (child instanceof td_1.TdToken && child.isIndependent()) {
|
|
72
|
-
const { nextSibling } = child;
|
|
73
|
-
if (nextSibling?.type === 'td') {
|
|
74
|
-
nextSibling.independence();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return super.removeAt(i);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* @override
|
|
81
|
-
* @param token 待插入的子节点
|
|
82
|
-
* @param i 插入位置
|
|
83
|
-
*/
|
|
84
|
-
insertAt(token, i = this.length) {
|
|
85
|
-
if (!debug_1.Shadow.running && token.type !== 'td') {
|
|
86
|
-
if (this.type === 'tr') {
|
|
87
|
-
this.typeError('insertAt', 'TdToken');
|
|
88
|
-
}
|
|
89
|
-
else if (token.type !== 'tr') {
|
|
90
|
-
this.typeError('insertAt', 'TrToken', 'TdToken');
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
i += i < 0 ? this.length : 0;
|
|
94
|
-
const child = this.childNodes[i];
|
|
95
|
-
if (token instanceof td_1.TdToken && token.isIndependent() && child instanceof td_1.TdToken) {
|
|
96
|
-
child.independence();
|
|
97
|
-
}
|
|
98
|
-
return super.insertAt(token, i);
|
|
99
|
-
}
|
|
100
|
-
/** 获取行数 */
|
|
101
|
-
getRowCount() {
|
|
102
|
-
return Number(this.childNodes.some(child => child instanceof td_1.TdToken && child.isIndependent() && !child.firstChild.text().endsWith('+')));
|
|
103
|
-
}
|
|
104
|
-
/** 获取列数 */
|
|
105
|
-
getColCount() {
|
|
106
|
-
let count = 0, last = 0;
|
|
107
|
-
for (const child of this.childNodes) {
|
|
108
|
-
if (child instanceof td_1.TdToken) {
|
|
109
|
-
last = child.isIndependent() ? Number(child.subtype !== 'caption') : last;
|
|
110
|
-
count += last;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return count;
|
|
114
|
-
}
|
|
115
|
-
getNthCol(n, insert = false) {
|
|
116
|
-
const nCols = this.getColCount();
|
|
117
|
-
n += n < 0 ? nCols : 0;
|
|
118
|
-
if (n < 0 || n > nCols || n === nCols && !insert) {
|
|
119
|
-
throw new RangeError(`不存在第 ${n} 个单元格!`);
|
|
120
|
-
}
|
|
121
|
-
let last = 0;
|
|
122
|
-
const isTr = (0, debug_1.isToken)('tr'), isSyntax = (0, debug_1.isToken)('table-syntax');
|
|
123
|
-
for (const child of this.childNodes.slice(2)) {
|
|
124
|
-
if (child instanceof td_1.TdToken) {
|
|
125
|
-
if (child.isIndependent()) {
|
|
126
|
-
last = Number(child.subtype !== 'caption');
|
|
127
|
-
}
|
|
128
|
-
n -= last;
|
|
129
|
-
if (n < 0) {
|
|
130
|
-
return child;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
else if (isTr(child) || isSyntax(child)) {
|
|
134
|
-
return child;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return undefined;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* 插入新的单元格
|
|
141
|
-
* @param inner 单元格内部wikitext
|
|
142
|
-
* @param {TableCoords} coord 单元格坐标
|
|
143
|
-
* @param subtype 单元格类型
|
|
144
|
-
* @param attr 单元格属性
|
|
145
|
-
*/
|
|
146
|
-
insertTableCell(inner, { column }, subtype = 'td', attr = {}) {
|
|
147
|
-
const token = (0, td_1.createTd)(inner, subtype, attr, this.getAttribute('include'), this.getAttribute('config'));
|
|
148
|
-
return this.insertBefore(token, this.getNthCol(column, true));
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
exports.TrBaseToken = TrBaseToken;
|
|
152
|
-
constants_1.classes['TrBaseToken'] = __filename;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import Parser from '../../index';
|
|
2
|
-
import { Token } from '../index';
|
|
3
|
-
import { TagPairToken } from './index';
|
|
4
|
-
import { AttributesToken } from '../attributes';
|
|
5
|
-
import type { LintError } from '../../base';
|
|
6
|
-
import type { AttributesParentBase } from '../../mixin/attributesParent';
|
|
7
|
-
export interface ExtToken extends AttributesParentBase {
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* 扩展标签
|
|
11
|
-
* @classdesc `{childNodes: [AttributesToken, Token]}`
|
|
12
|
-
*/
|
|
13
|
-
export declare abstract class ExtToken extends TagPairToken {
|
|
14
|
-
readonly type = "ext";
|
|
15
|
-
closed: true;
|
|
16
|
-
readonly childNodes: readonly [AttributesToken, Token];
|
|
17
|
-
abstract get firstChild(): AttributesToken;
|
|
18
|
-
abstract get lastChild(): Token;
|
|
19
|
-
abstract get children(): [AttributesToken, Token];
|
|
20
|
-
abstract get firstElementChild(): AttributesToken;
|
|
21
|
-
/**
|
|
22
|
-
* @param name 标签名
|
|
23
|
-
* @param attr 标签属性
|
|
24
|
-
* @param inner 内部wikitext
|
|
25
|
-
* @param closed 是否封闭
|
|
26
|
-
*/
|
|
27
|
-
constructor(name: string, attr?: string, inner?: string, closed?: string, config?: Parser.Config, accum?: Token[]);
|
|
28
|
-
/** @override */
|
|
29
|
-
lint(start?: number): LintError[];
|
|
30
|
-
/** @override */
|
|
31
|
-
cloneNode(): this;
|
|
32
|
-
}
|
package/dist/src/tagPair/ext.js
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
-
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
-
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
-
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
-
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
-
var _, done = false;
|
|
8
|
-
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
-
var context = {};
|
|
10
|
-
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
-
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
-
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
-
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
-
if (kind === "accessor") {
|
|
15
|
-
if (result === void 0) continue;
|
|
16
|
-
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
-
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
-
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
-
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
-
}
|
|
21
|
-
else if (_ = accept(result)) {
|
|
22
|
-
if (kind === "field") initializers.unshift(_);
|
|
23
|
-
else descriptor[key] = _;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
-
done = true;
|
|
28
|
-
};
|
|
29
|
-
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
-
var useValue = arguments.length > 2;
|
|
31
|
-
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
-
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
-
}
|
|
34
|
-
return useValue ? value : void 0;
|
|
35
|
-
};
|
|
36
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.ExtToken = void 0;
|
|
38
|
-
const lint_1 = require("../../util/lint");
|
|
39
|
-
const debug_1 = require("../../util/debug");
|
|
40
|
-
const constants_1 = require("../../util/constants");
|
|
41
|
-
const attributesParent_1 = require("../../mixin/attributesParent");
|
|
42
|
-
const index_1 = require("../../index");
|
|
43
|
-
const index_2 = require("../index");
|
|
44
|
-
const index_3 = require("./index");
|
|
45
|
-
const attributes_1 = require("../attributes");
|
|
46
|
-
/**
|
|
47
|
-
* 从数组中删除指定元素
|
|
48
|
-
* @param arr 数组
|
|
49
|
-
* @param ele 元素
|
|
50
|
-
*/
|
|
51
|
-
const del = (arr, ele) => {
|
|
52
|
-
const set = new Set(arr);
|
|
53
|
-
set.delete(ele);
|
|
54
|
-
return [...set];
|
|
55
|
-
};
|
|
56
|
-
/* NOT FOR BROWSER END */
|
|
57
|
-
/**
|
|
58
|
-
* 扩展标签
|
|
59
|
-
* @classdesc `{childNodes: [AttributesToken, Token]}`
|
|
60
|
-
*/
|
|
61
|
-
let ExtToken = (() => {
|
|
62
|
-
let _classDecorators = [(0, attributesParent_1.attributesParent)()];
|
|
63
|
-
let _classDescriptor;
|
|
64
|
-
let _classExtraInitializers = [];
|
|
65
|
-
let _classThis;
|
|
66
|
-
let _classSuper = index_3.TagPairToken;
|
|
67
|
-
var ExtToken = class extends _classSuper {
|
|
68
|
-
static { _classThis = this; }
|
|
69
|
-
static {
|
|
70
|
-
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
71
|
-
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
72
|
-
ExtToken = _classThis = _classDescriptor.value;
|
|
73
|
-
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
74
|
-
__runInitializers(_classThis, _classExtraInitializers);
|
|
75
|
-
}
|
|
76
|
-
type = 'ext';
|
|
77
|
-
/* NOT FOR BROWSER END */
|
|
78
|
-
/**
|
|
79
|
-
* @param name 标签名
|
|
80
|
-
* @param attr 标签属性
|
|
81
|
-
* @param inner 内部wikitext
|
|
82
|
-
* @param closed 是否封闭
|
|
83
|
-
*/
|
|
84
|
-
constructor(name, attr, inner, closed, config = index_1.default.getConfig(), accum = []) {
|
|
85
|
-
const lcName = name.toLowerCase(),
|
|
86
|
-
// @ts-expect-error abstract class
|
|
87
|
-
attrToken = new attributes_1.AttributesToken(!attr || attr.trimStart() !== attr ? attr : ` ${attr}`, 'ext-attrs', lcName, config, accum), newConfig = { ...config, ext: del(config.ext, lcName), excludes: [...config.excludes ?? []] };
|
|
88
|
-
let innerToken;
|
|
89
|
-
switch (lcName) {
|
|
90
|
-
case 'tab':
|
|
91
|
-
newConfig.ext = del(newConfig.ext, 'tabs');
|
|
92
|
-
// fall through
|
|
93
|
-
case 'indicator':
|
|
94
|
-
case 'poem':
|
|
95
|
-
case 'ref':
|
|
96
|
-
case 'option':
|
|
97
|
-
case 'combooption':
|
|
98
|
-
case 'tabs':
|
|
99
|
-
case 'poll':
|
|
100
|
-
case 'seo':
|
|
101
|
-
if (lcName === 'poem') {
|
|
102
|
-
newConfig.excludes.push('heading');
|
|
103
|
-
}
|
|
104
|
-
innerToken = new index_2.Token(inner, newConfig, accum);
|
|
105
|
-
break;
|
|
106
|
-
case 'pre': {
|
|
107
|
-
const { PreToken } = require('../pre');
|
|
108
|
-
// @ts-expect-error abstract class
|
|
109
|
-
innerToken = new PreToken(inner, newConfig, accum);
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
case 'dynamicpagelist': {
|
|
113
|
-
const { ParamTagToken } = require('../paramTag/index');
|
|
114
|
-
// @ts-expect-error abstract class
|
|
115
|
-
innerToken = new ParamTagToken(inner, newConfig, accum);
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
case 'inputbox': {
|
|
119
|
-
newConfig.excludes.push('heading');
|
|
120
|
-
const { InputboxToken } = require('../paramTag/inputbox');
|
|
121
|
-
// @ts-expect-error abstract class
|
|
122
|
-
innerToken = new InputboxToken(inner, newConfig, accum);
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
case 'references': {
|
|
126
|
-
const { NestedToken } = require('../nested');
|
|
127
|
-
// @ts-expect-error abstract class
|
|
128
|
-
innerToken = new NestedToken(inner, /<!--.*?(?:-->|$)|<(ref)(\s[^>]*)?>(.*?)<\/(ref\s*)>/gisu, ['ref'], newConfig, accum);
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
case 'choose': {
|
|
132
|
-
const { NestedToken } = require('../nested');
|
|
133
|
-
// @ts-expect-error abstract class
|
|
134
|
-
innerToken = new NestedToken(inner, /<(option|choicetemplate)(\s[^>]*)?>(.*?)<\/(\1)>/gsu, ['option', 'choicetemplate'], newConfig, accum);
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
case 'combobox': {
|
|
138
|
-
const { NestedToken } = require('../nested');
|
|
139
|
-
// @ts-expect-error abstract class
|
|
140
|
-
innerToken = new NestedToken(inner, /<(combooption)(\s[^>]*)?>(.*?)<\/(combooption\s*)>/gisu, ['combooption'], newConfig, accum);
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
case 'gallery': {
|
|
144
|
-
const { GalleryToken } = require('../gallery');
|
|
145
|
-
// @ts-expect-error abstract class
|
|
146
|
-
innerToken = new GalleryToken(inner, newConfig, accum);
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
case 'imagemap': {
|
|
150
|
-
const { ImagemapToken } = require('../imagemap');
|
|
151
|
-
// @ts-expect-error abstract class
|
|
152
|
-
innerToken = new ImagemapToken(inner, newConfig, accum);
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
// 更多定制扩展的代码示例:
|
|
156
|
-
// ```
|
|
157
|
-
// case 'extensionName': {
|
|
158
|
-
// const {ExtensionToken}: typeof import('../extension') = require('../extension');
|
|
159
|
-
// innerToken = new ExtensionToken(inner, newConfig, accum);
|
|
160
|
-
// break;
|
|
161
|
-
// }
|
|
162
|
-
// ```
|
|
163
|
-
default: {
|
|
164
|
-
const { NowikiToken } = require('../nowiki/index');
|
|
165
|
-
// @ts-expect-error abstract class
|
|
166
|
-
innerToken = new NowikiToken(inner, newConfig);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
innerToken.setAttribute('name', lcName);
|
|
170
|
-
innerToken.type = 'ext-inner';
|
|
171
|
-
super(name, attrToken, innerToken, closed, config, accum);
|
|
172
|
-
this.seal('closed', true);
|
|
173
|
-
}
|
|
174
|
-
/** @override */
|
|
175
|
-
lint(start = this.getAbsoluteIndex()) {
|
|
176
|
-
const errors = super.lint(start);
|
|
177
|
-
let rect;
|
|
178
|
-
if (this.name !== 'nowiki' && this.closest('html-attrs, table-attrs')) {
|
|
179
|
-
rect = { start, ...this.getRootNode().posFromIndex(start) };
|
|
180
|
-
errors.push((0, lint_1.generateForSelf)(this, rect, 'parsing-order', 'extension tag in HTML tag attributes'));
|
|
181
|
-
}
|
|
182
|
-
if (this.name === 'ref' && this.closest('heading-title')) {
|
|
183
|
-
rect ??= { start, ...this.getRootNode().posFromIndex(start) };
|
|
184
|
-
errors.push((0, lint_1.generateForSelf)(this, rect, 'var-anchor', 'variable anchor in a section header'));
|
|
185
|
-
}
|
|
186
|
-
return errors;
|
|
187
|
-
}
|
|
188
|
-
/* NOT FOR BROWSER */
|
|
189
|
-
/** @override */
|
|
190
|
-
cloneNode() {
|
|
191
|
-
const inner = this.lastChild.cloneNode(), tags = this.getAttribute('tags'), config = this.getAttribute('config'), attr = String(this.firstChild);
|
|
192
|
-
return debug_1.Shadow.run(() => {
|
|
193
|
-
// @ts-expect-error abstract class
|
|
194
|
-
const token = new ExtToken(tags[0], attr, '', this.selfClosing ? undefined : tags[1], config);
|
|
195
|
-
token.lastChild.safeReplaceWith(inner);
|
|
196
|
-
return token;
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
return ExtToken = _classThis;
|
|
201
|
-
})();
|
|
202
|
-
exports.ExtToken = ExtToken;
|
|
203
|
-
constants_1.classes['ExtToken'] = __filename;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import Parser from '../../index';
|
|
2
|
-
import { TagPairToken } from './index';
|
|
3
|
-
import type { LintError } from '../../base';
|
|
4
|
-
import type { AstText, Token } from '../../internal';
|
|
5
|
-
export declare abstract class IncludeToken extends TagPairToken {
|
|
6
|
-
readonly type = "include";
|
|
7
|
-
readonly childNodes: readonly [AstText, AstText];
|
|
8
|
-
abstract get firstChild(): AstText;
|
|
9
|
-
abstract get lastChild(): AstText;
|
|
10
|
-
abstract get children(): [];
|
|
11
|
-
abstract get firstElementChild(): undefined;
|
|
12
|
-
abstract get lastElementChild(): undefined;
|
|
13
|
-
/** @override */
|
|
14
|
-
get innerText(): string | undefined;
|
|
15
|
-
set innerText(text: string | undefined);
|
|
16
|
-
/**
|
|
17
|
-
* @param name 标签名
|
|
18
|
-
* @param attr 标签属性
|
|
19
|
-
* @param inner 内部wikitext
|
|
20
|
-
* @param closed 是否封闭
|
|
21
|
-
*/
|
|
22
|
-
constructor(name: string, attr?: string, inner?: string, closed?: string, config?: Parser.Config, accum?: Token[]);
|
|
23
|
-
/** @override */
|
|
24
|
-
lint(start?: number): LintError[];
|
|
25
|
-
/** @override */
|
|
26
|
-
cloneNode(): this;
|
|
27
|
-
/**
|
|
28
|
-
* @override
|
|
29
|
-
* @param str 新文本
|
|
30
|
-
*/
|
|
31
|
-
setText(str: string): string;
|
|
32
|
-
/** 清除标签属性 */
|
|
33
|
-
removeAttr(): void;
|
|
34
|
-
}
|
|
35
|
-
export {};
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IncludeToken = void 0;
|
|
4
|
-
const lint_1 = require("../../util/lint");
|
|
5
|
-
const debug_1 = require("../../util/debug");
|
|
6
|
-
const constants_1 = require("../../util/constants");
|
|
7
|
-
const hidden_1 = require("../../mixin/hidden");
|
|
8
|
-
const index_1 = require("../../index");
|
|
9
|
-
const index_2 = require("./index");
|
|
10
|
-
/**
|
|
11
|
-
* `<includeonly>`或`<noinclude>`或`<onlyinclude>`
|
|
12
|
-
* @classdesc `{childNodes: [AstText, AstText]}`
|
|
13
|
-
*/
|
|
14
|
-
class IncludeToken extends (0, hidden_1.hiddenToken)(index_2.TagPairToken) {
|
|
15
|
-
type = 'include';
|
|
16
|
-
/** @override */
|
|
17
|
-
get innerText() {
|
|
18
|
-
return this.selfClosing ? undefined : this.lastChild.data;
|
|
19
|
-
}
|
|
20
|
-
set innerText(text) {
|
|
21
|
-
if (text === undefined) {
|
|
22
|
-
this.selfClosing = true;
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
this.selfClosing = false;
|
|
26
|
-
this.setText(text);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
/* NOT FOR BROWSER END */
|
|
30
|
-
/**
|
|
31
|
-
* @param name 标签名
|
|
32
|
-
* @param attr 标签属性
|
|
33
|
-
* @param inner 内部wikitext
|
|
34
|
-
* @param closed 是否封闭
|
|
35
|
-
*/
|
|
36
|
-
constructor(name, attr = '', inner, closed, config = index_1.default.getConfig(), accum = []) {
|
|
37
|
-
super(name, attr, inner ?? '', inner === undefined ? closed : closed ?? '', config, accum);
|
|
38
|
-
}
|
|
39
|
-
/** @override */
|
|
40
|
-
lint(start = this.getAbsoluteIndex()) {
|
|
41
|
-
if (this.closed) {
|
|
42
|
-
return [];
|
|
43
|
-
}
|
|
44
|
-
const e = (0, lint_1.generateForSelf)(this, { start }, 'unclosed-comment', index_1.default.msg('unclosed $1', `<${this.name}>`));
|
|
45
|
-
e.suggestions = [
|
|
46
|
-
{
|
|
47
|
-
desc: 'close',
|
|
48
|
-
range: [e.endIndex, e.endIndex],
|
|
49
|
-
text: `</${this.name}>`,
|
|
50
|
-
},
|
|
51
|
-
];
|
|
52
|
-
return [e];
|
|
53
|
-
}
|
|
54
|
-
/* NOT FOR BROWSER */
|
|
55
|
-
/** @override */
|
|
56
|
-
cloneNode() {
|
|
57
|
-
const tags = this.getAttribute('tags'), config = this.getAttribute('config'), { innerText } = this, closing = this.selfClosing || !this.closed ? undefined : tags[1];
|
|
58
|
-
// @ts-expect-error abstract class
|
|
59
|
-
return debug_1.Shadow.run(() => new IncludeToken(tags[0], this.firstChild.data, innerText, closing, config));
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* @override
|
|
63
|
-
* @param str 新文本
|
|
64
|
-
*/
|
|
65
|
-
setText(str) {
|
|
66
|
-
return super.setText(str, 1);
|
|
67
|
-
}
|
|
68
|
-
/** 清除标签属性 */
|
|
69
|
-
removeAttr() {
|
|
70
|
-
super.setText('');
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
exports.IncludeToken = IncludeToken;
|
|
74
|
-
constants_1.classes['IncludeToken'] = __filename;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import Parser from '../../index';
|
|
2
|
-
import { Token } from '../index';
|
|
3
|
-
import type { AstNodes } from '../../lib/node';
|
|
4
|
-
/** 成对标签 */
|
|
5
|
-
export declare abstract class TagPairToken extends Token {
|
|
6
|
-
#private;
|
|
7
|
-
type: 'ext' | 'include';
|
|
8
|
-
readonly name: string;
|
|
9
|
-
closed: boolean;
|
|
10
|
-
selfClosing: boolean;
|
|
11
|
-
readonly childNodes: readonly [AstNodes, AstNodes];
|
|
12
|
-
abstract get firstChild(): AstNodes;
|
|
13
|
-
abstract get lastChild(): AstNodes;
|
|
14
|
-
/** 内部wikitext */
|
|
15
|
-
get innerText(): string | undefined;
|
|
16
|
-
/**
|
|
17
|
-
* @param name 标签名
|
|
18
|
-
* @param attr 标签属性
|
|
19
|
-
* @param inner 内部wikitext
|
|
20
|
-
* @param closed 是否封闭;约定`undefined`表示自封闭,`''`表示未闭合
|
|
21
|
-
*/
|
|
22
|
-
constructor(name: string, attr: string | Token, inner: string | Token, closed?: string, config?: Parser.Config, accum?: Token[]);
|
|
23
|
-
/** @override */
|
|
24
|
-
text(): string;
|
|
25
|
-
/** @override */
|
|
26
|
-
print(): string;
|
|
27
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
-
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
-
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
-
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
-
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
-
var _, done = false;
|
|
8
|
-
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
-
var context = {};
|
|
10
|
-
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
-
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
-
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
-
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
-
if (kind === "accessor") {
|
|
15
|
-
if (result === void 0) continue;
|
|
16
|
-
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
-
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
-
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
-
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
-
}
|
|
21
|
-
else if (_ = accept(result)) {
|
|
22
|
-
if (kind === "field") initializers.unshift(_);
|
|
23
|
-
else descriptor[key] = _;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
-
done = true;
|
|
28
|
-
};
|
|
29
|
-
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
-
var useValue = arguments.length > 2;
|
|
31
|
-
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
-
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
-
}
|
|
34
|
-
return useValue ? value : void 0;
|
|
35
|
-
};
|
|
36
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.TagPairToken = void 0;
|
|
38
|
-
const constants_1 = require("../../util/constants");
|
|
39
|
-
const fixed_1 = require("../../mixin/fixed");
|
|
40
|
-
const index_1 = require("../../index");
|
|
41
|
-
const index_2 = require("../index");
|
|
42
|
-
/** 成对标签 */
|
|
43
|
-
let TagPairToken = (() => {
|
|
44
|
-
let _classDecorators = [fixed_1.fixedToken];
|
|
45
|
-
let _classDescriptor;
|
|
46
|
-
let _classExtraInitializers = [];
|
|
47
|
-
let _classThis;
|
|
48
|
-
let _classSuper = index_2.Token;
|
|
49
|
-
var TagPairToken = class extends _classSuper {
|
|
50
|
-
static { _classThis = this; }
|
|
51
|
-
static {
|
|
52
|
-
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
53
|
-
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
54
|
-
TagPairToken = _classThis = _classDescriptor.value;
|
|
55
|
-
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
56
|
-
__runInitializers(_classThis, _classExtraInitializers);
|
|
57
|
-
}
|
|
58
|
-
#tags;
|
|
59
|
-
closed;
|
|
60
|
-
selfClosing;
|
|
61
|
-
/* NOT FOR BROWSER END */
|
|
62
|
-
/** 内部wikitext */
|
|
63
|
-
get innerText() {
|
|
64
|
-
return this.selfClosing ? undefined : this.lastChild.text();
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* @param name 标签名
|
|
68
|
-
* @param attr 标签属性
|
|
69
|
-
* @param inner 内部wikitext
|
|
70
|
-
* @param closed 是否封闭;约定`undefined`表示自封闭,`''`表示未闭合
|
|
71
|
-
*/
|
|
72
|
-
constructor(name, attr, inner, closed, config = index_1.default.getConfig(), accum = []) {
|
|
73
|
-
super(undefined, config);
|
|
74
|
-
this.setAttribute('name', name.toLowerCase());
|
|
75
|
-
this.#tags = [name, closed || name];
|
|
76
|
-
this.closed = closed !== '';
|
|
77
|
-
this.selfClosing = closed === undefined;
|
|
78
|
-
this.append(attr, inner);
|
|
79
|
-
const index = typeof attr === 'string' ? -1 : accum.indexOf(attr);
|
|
80
|
-
accum.splice(index === -1 ? Infinity : index, 0, this);
|
|
81
|
-
}
|
|
82
|
-
/** @private */
|
|
83
|
-
toString() {
|
|
84
|
-
const { selfClosing, firstChild, lastChild,
|
|
85
|
-
/* NOT FOR BROWSER */
|
|
86
|
-
nextSibling, name, closed, } = this, [opening, closing] = this.#tags;
|
|
87
|
-
/* NOT FOR BROWSER */
|
|
88
|
-
if (!closed && nextSibling) {
|
|
89
|
-
index_1.default.error(`自动闭合 <${name}>`, lastChild);
|
|
90
|
-
this.closed = true;
|
|
91
|
-
}
|
|
92
|
-
/* NOT FOR BROWSER END */
|
|
93
|
-
return selfClosing
|
|
94
|
-
? `<${opening}${String(firstChild)}/>`
|
|
95
|
-
: `<${opening}${String(firstChild)}>${String(lastChild)}${this.closed ? `</${closing}>` : ''}`;
|
|
96
|
-
}
|
|
97
|
-
/** @override */
|
|
98
|
-
text() {
|
|
99
|
-
const [opening, closing] = this.#tags;
|
|
100
|
-
return this.selfClosing
|
|
101
|
-
? `<${opening}${this.firstChild.text()}/>`
|
|
102
|
-
: `<${opening}${super.text('>')}${this.closed ? `</${closing}>` : ''}`;
|
|
103
|
-
}
|
|
104
|
-
/** @private */
|
|
105
|
-
getAttribute(key) {
|
|
106
|
-
/* NOT FOR BROWSER */
|
|
107
|
-
if (key === 'tags') {
|
|
108
|
-
return [...this.#tags];
|
|
109
|
-
}
|
|
110
|
-
/* NOT FOR BROWSER END */
|
|
111
|
-
return key === 'padding' ? this.#tags[0].length + 1 : super.getAttribute(key);
|
|
112
|
-
}
|
|
113
|
-
/** @private */
|
|
114
|
-
getGaps() {
|
|
115
|
-
return 1;
|
|
116
|
-
}
|
|
117
|
-
/** @override */
|
|
118
|
-
print() {
|
|
119
|
-
const [opening, closing] = this.#tags;
|
|
120
|
-
return super.print(this.selfClosing
|
|
121
|
-
? { pre: `<${opening}`, post: '/>' }
|
|
122
|
-
: { pre: `<${opening}`, sep: '>', post: this.closed ? `</${closing}>` : '' });
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
return TagPairToken = _classThis;
|
|
126
|
-
})();
|
|
127
|
-
exports.TagPairToken = TagPairToken;
|
|
128
|
-
constants_1.classes['TagPairToken'] = __filename;
|