wikiparser-node 1.4.3-b → 1.4.4
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/README.en.md +1 -1
- package/README.md +1 -1
- package/config/.schema.json +172 -0
- package/config/enwiki.json +814 -1
- package/config/llwiki.json +35 -1
- package/config/moegirl.json +44 -1
- package/config/zhwiki.json +466 -1
- package/dist/addon/table.d.ts +6 -0
- package/dist/addon/table.js +564 -0
- package/dist/base.d.ts +58 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +211 -0
- package/dist/internal.d.ts +44 -0
- package/dist/lib/element.d.ts +155 -0
- package/dist/lib/element.js +655 -0
- package/dist/lib/node.d.ts +146 -0
- package/dist/lib/node.js +428 -0
- package/dist/lib/range.d.ts +104 -0
- package/dist/lib/range.js +385 -0
- package/dist/lib/ranges.d.ts +26 -0
- package/dist/lib/ranges.js +118 -0
- package/dist/lib/text.d.ts +62 -0
- package/dist/lib/text.js +306 -0
- package/dist/lib/title.d.ts +38 -0
- package/dist/lib/title.js +164 -0
- package/dist/mixin/attributesParent.d.ts +50 -0
- package/dist/mixin/attributesParent.js +78 -0
- package/dist/mixin/fixed.d.ts +6 -0
- package/dist/mixin/fixed.js +30 -0
- package/dist/mixin/flagsParent.d.ts +72 -0
- package/dist/mixin/flagsParent.js +59 -0
- package/dist/mixin/hidden.d.ts +5 -0
- package/dist/mixin/hidden.js +24 -0
- package/dist/mixin/magicLinkParent.d.ts +40 -0
- package/dist/mixin/magicLinkParent.js +42 -0
- package/dist/mixin/singleLine.d.ts +6 -0
- package/dist/mixin/singleLine.js +26 -0
- package/dist/mixin/sol.d.ts +6 -0
- package/dist/mixin/sol.js +43 -0
- package/dist/mixin/syntax.d.ts +9 -0
- package/dist/mixin/syntax.js +50 -0
- package/dist/parser/braces.js +131 -0
- package/dist/parser/commentAndExt.js +90 -0
- package/dist/parser/converter.js +41 -0
- package/dist/parser/externalLinks.js +32 -0
- package/dist/parser/hrAndDoubleUnderscore.js +41 -0
- package/dist/parser/html.js +39 -0
- package/dist/parser/links.js +95 -0
- package/dist/parser/list.js +68 -0
- package/dist/parser/magicLinks.js +43 -0
- package/dist/parser/quotes.js +68 -0
- package/dist/parser/selector.js +162 -0
- package/dist/parser/table.js +124 -0
- package/dist/src/arg.d.ts +58 -0
- package/dist/src/arg.js +196 -0
- package/dist/src/atom.d.ts +12 -0
- package/dist/src/atom.js +27 -0
- package/dist/src/attribute.d.ts +69 -0
- package/dist/src/attribute.js +475 -0
- package/dist/src/attributes.d.ts +109 -0
- package/dist/src/attributes.js +346 -0
- package/dist/src/converter.d.ts +33 -0
- package/dist/src/converter.js +134 -0
- package/dist/src/converterFlags.d.ts +87 -0
- package/dist/src/converterFlags.js +226 -0
- package/dist/src/converterRule.d.ts +77 -0
- package/dist/src/converterRule.js +209 -0
- package/dist/src/extLink.d.ts +43 -0
- package/dist/src/extLink.js +186 -0
- package/dist/src/gallery.d.ts +54 -0
- package/dist/src/gallery.js +126 -0
- package/dist/src/heading.d.ts +47 -0
- package/dist/src/heading.js +190 -0
- package/dist/src/hidden.d.ts +7 -0
- package/dist/src/hidden.js +23 -0
- package/dist/src/html.d.ts +65 -0
- package/dist/src/html.js +337 -0
- package/dist/src/imageParameter.d.ts +65 -0
- package/dist/src/imageParameter.js +246 -0
- package/dist/src/imagemap.d.ts +56 -0
- package/dist/src/imagemap.js +150 -0
- package/dist/src/imagemapLink.d.ts +31 -0
- package/dist/src/imagemapLink.js +93 -0
- package/dist/src/index.d.ts +143 -0
- package/dist/src/index.js +803 -0
- package/dist/src/link/base.d.ts +52 -0
- package/dist/src/link/base.js +209 -0
- package/dist/src/link/category.d.ts +13 -0
- package/dist/src/link/category.js +28 -0
- package/dist/src/link/file.d.ts +96 -0
- package/dist/src/link/file.js +265 -0
- package/dist/src/link/galleryImage.d.ts +32 -0
- package/dist/src/link/galleryImage.js +157 -0
- package/dist/src/link/index.d.ts +56 -0
- package/dist/src/link/index.js +133 -0
- package/dist/src/magicLink.d.ts +59 -0
- package/dist/src/magicLink.js +199 -0
- package/dist/src/nested.d.ts +43 -0
- package/dist/src/nested.js +92 -0
- package/dist/src/nowiki/base.d.ts +31 -0
- package/dist/src/nowiki/base.js +93 -0
- package/dist/src/nowiki/comment.d.ts +25 -0
- package/dist/src/nowiki/comment.js +68 -0
- package/dist/src/nowiki/dd.d.ts +8 -0
- package/dist/src/nowiki/dd.js +24 -0
- package/dist/src/nowiki/doubleUnderscore.d.ts +18 -0
- package/dist/src/nowiki/doubleUnderscore.js +101 -0
- package/dist/src/nowiki/hr.d.ts +5 -0
- package/dist/src/nowiki/hr.js +63 -0
- package/dist/src/nowiki/index.d.ts +16 -0
- package/dist/src/nowiki/index.js +21 -0
- package/dist/src/nowiki/list.d.ts +16 -0
- package/dist/src/nowiki/list.js +97 -0
- package/dist/src/nowiki/listBase.d.ts +5 -0
- package/dist/src/nowiki/listBase.js +61 -0
- package/dist/src/nowiki/noinclude.d.ts +10 -0
- package/dist/src/nowiki/noinclude.js +23 -0
- package/dist/src/nowiki/quote.d.ts +14 -0
- package/dist/src/nowiki/quote.js +116 -0
- package/dist/src/onlyinclude.d.ts +16 -0
- package/dist/src/onlyinclude.js +57 -0
- package/dist/src/paramTag/index.d.ts +37 -0
- package/dist/src/paramTag/index.js +69 -0
- package/dist/src/paramTag/inputbox.d.ts +8 -0
- package/dist/src/paramTag/inputbox.js +22 -0
- package/dist/src/parameter.d.ts +70 -0
- package/dist/src/parameter.js +262 -0
- package/dist/src/pre.d.ts +28 -0
- package/dist/src/pre.js +55 -0
- package/dist/src/syntax.d.ts +20 -0
- package/dist/src/syntax.js +86 -0
- package/dist/src/table/base.d.ts +30 -0
- package/dist/src/table/base.js +132 -0
- package/dist/src/table/index.d.ts +233 -0
- package/dist/src/table/index.js +396 -0
- package/dist/src/table/td.d.ts +92 -0
- package/dist/src/table/td.js +337 -0
- package/dist/src/table/tr.d.ts +32 -0
- package/dist/src/table/tr.js +58 -0
- package/dist/src/table/trBase.d.ts +53 -0
- package/dist/src/table/trBase.js +154 -0
- package/dist/src/tagPair/ext.d.ts +32 -0
- package/dist/src/tagPair/ext.js +203 -0
- package/dist/src/tagPair/include.d.ts +35 -0
- package/dist/src/tagPair/include.js +63 -0
- package/dist/src/tagPair/index.d.ts +27 -0
- package/dist/src/tagPair/index.js +128 -0
- package/dist/src/transclude.d.ts +167 -0
- package/dist/src/transclude.js +710 -0
- package/dist/util/constants.js +113 -0
- package/dist/util/debug.js +88 -0
- package/dist/util/diff.js +82 -0
- package/dist/util/lint.js +30 -0
- package/dist/util/string.js +53 -0
- package/errors/README +1 -0
- package/i18n/zh-hans.json +1 -0
- package/i18n/zh-hant.json +1 -0
- package/package.json +15 -30
- package/printed/README +1 -0
- package/bundle/bundle.min.js +0 -36
- package/extensions/dist/base.js +0 -64
- package/extensions/dist/editor.js +0 -159
- package/extensions/dist/highlight.js +0 -59
- package/extensions/dist/lint.js +0 -48
- package/extensions/editor.css +0 -63
- package/extensions/ui.css +0 -141
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import Parser from '../../index';
|
|
2
|
+
import { Token } from '../index';
|
|
3
|
+
import { TableBaseToken } from './base';
|
|
4
|
+
import type { LintError, AST } from '../../base';
|
|
5
|
+
import type { SyntaxToken, AttributesToken, TrToken, TableToken } from '../../internal';
|
|
6
|
+
export type TdSubtypes = 'td' | 'th' | 'caption';
|
|
7
|
+
export interface TdSpanAttrs {
|
|
8
|
+
rowspan?: number;
|
|
9
|
+
colspan?: number;
|
|
10
|
+
}
|
|
11
|
+
declare type TdAttrGetter<T extends string> = T extends keyof TdSpanAttrs ? number : string | true | undefined;
|
|
12
|
+
declare type TdAttrSetter<T extends string> = T extends keyof TdSpanAttrs ? number : string | boolean;
|
|
13
|
+
export type TdAttrs = Record<string, string | true> & TdSpanAttrs;
|
|
14
|
+
/**
|
|
15
|
+
* `<td>`、`<th>`和`<caption>`
|
|
16
|
+
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, Token]}`
|
|
17
|
+
*/
|
|
18
|
+
export declare abstract class TdToken extends TableBaseToken {
|
|
19
|
+
#private;
|
|
20
|
+
readonly type = "td";
|
|
21
|
+
readonly childNodes: readonly [SyntaxToken, AttributesToken, Token];
|
|
22
|
+
abstract get parentNode(): TrToken | TableToken | undefined;
|
|
23
|
+
abstract get nextSibling(): this | TrToken | SyntaxToken | undefined;
|
|
24
|
+
abstract get previousSibling(): Token | undefined;
|
|
25
|
+
abstract get children(): [SyntaxToken, AttributesToken, Token];
|
|
26
|
+
abstract get parentElement(): TrToken | TableToken | undefined;
|
|
27
|
+
abstract get nextElementSibling(): this | TrToken | SyntaxToken | undefined;
|
|
28
|
+
/** 单元格类型 */
|
|
29
|
+
get subtype(): TdSubtypes;
|
|
30
|
+
set subtype(subtype: TdSubtypes);
|
|
31
|
+
/** rowspan */
|
|
32
|
+
get rowspan(): number;
|
|
33
|
+
set rowspan(rowspan: number);
|
|
34
|
+
/** colspan */
|
|
35
|
+
get colspan(): number;
|
|
36
|
+
set colspan(colspan: number);
|
|
37
|
+
/** 内部wikitext */
|
|
38
|
+
get innerText(): string;
|
|
39
|
+
set innerText(text: string);
|
|
40
|
+
/**
|
|
41
|
+
* @param syntax 单元格语法
|
|
42
|
+
* @param inner 内部wikitext
|
|
43
|
+
*/
|
|
44
|
+
constructor(syntax: string, inner?: string, config?: Parser.Config, accum?: Token[]);
|
|
45
|
+
/** @override */
|
|
46
|
+
text(): string;
|
|
47
|
+
/** @override */
|
|
48
|
+
lint(start?: number): LintError[];
|
|
49
|
+
/** @override */
|
|
50
|
+
print(): string;
|
|
51
|
+
/** @override */
|
|
52
|
+
json(): AST;
|
|
53
|
+
/** 是否位于行首 */
|
|
54
|
+
isIndependent(): boolean;
|
|
55
|
+
/** @override */
|
|
56
|
+
cloneNode(): this;
|
|
57
|
+
/**
|
|
58
|
+
* @override
|
|
59
|
+
* @param syntax 表格语法
|
|
60
|
+
* @param esc 是否需要转义
|
|
61
|
+
*/
|
|
62
|
+
setSyntax(syntax: string, esc?: boolean): void;
|
|
63
|
+
/** 改为独占一行 */
|
|
64
|
+
independence(): void;
|
|
65
|
+
/**
|
|
66
|
+
* @override
|
|
67
|
+
* @param key 属性键
|
|
68
|
+
*/
|
|
69
|
+
getAttr<T extends string>(key: T): TdAttrGetter<T>;
|
|
70
|
+
/** @override */
|
|
71
|
+
getAttrs(): TdAttrs;
|
|
72
|
+
/**
|
|
73
|
+
* @override
|
|
74
|
+
* @param key 属性键
|
|
75
|
+
* @param value 属性值
|
|
76
|
+
* @param prop 属性对象
|
|
77
|
+
*/
|
|
78
|
+
setAttr<T extends string>(key: T, value: TdAttrSetter<T>): void;
|
|
79
|
+
setAttr(prop: Record<string, string | number | boolean>): void;
|
|
80
|
+
/** @override */
|
|
81
|
+
escape(): void;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 创建新的单元格
|
|
85
|
+
* @param inner 内部wikitext
|
|
86
|
+
* @param subtype 单元格类型
|
|
87
|
+
* @param attr 单元格属性
|
|
88
|
+
* @param include 是否嵌入
|
|
89
|
+
* @param config
|
|
90
|
+
*/
|
|
91
|
+
export declare const createTd: (inner: string | Token, subtype?: TdSubtypes, attr?: TdAttrs, include?: boolean, config?: Parser.Config) => TdToken;
|
|
92
|
+
export {};
|
|
@@ -0,0 +1,337 @@
|
|
|
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.createTd = exports.TdToken = void 0;
|
|
38
|
+
const lint_1 = require("../../util/lint");
|
|
39
|
+
const constants_1 = require("../../util/constants");
|
|
40
|
+
const debug_1 = require("../../util/debug");
|
|
41
|
+
const fixed_1 = require("../../mixin/fixed");
|
|
42
|
+
const index_1 = require("../../index");
|
|
43
|
+
const index_2 = require("../index");
|
|
44
|
+
const base_1 = require("./base");
|
|
45
|
+
/**
|
|
46
|
+
* `<td>`、`<th>`和`<caption>`
|
|
47
|
+
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, Token]}`
|
|
48
|
+
*/
|
|
49
|
+
let TdToken = (() => {
|
|
50
|
+
var _a;
|
|
51
|
+
let _classDecorators = [fixed_1.fixedToken];
|
|
52
|
+
let _classDescriptor;
|
|
53
|
+
let _classExtraInitializers = [];
|
|
54
|
+
let _classThis;
|
|
55
|
+
let _classSuper = base_1.TableBaseToken;
|
|
56
|
+
var TdToken = class extends _classSuper {
|
|
57
|
+
static { _classThis = this; }
|
|
58
|
+
static {
|
|
59
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
60
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
61
|
+
TdToken = _classThis = _classDescriptor.value;
|
|
62
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
63
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
64
|
+
}
|
|
65
|
+
type = 'td';
|
|
66
|
+
#innerSyntax = '';
|
|
67
|
+
/* NOT FOR BROWSER END */
|
|
68
|
+
/** 单元格类型 */
|
|
69
|
+
get subtype() {
|
|
70
|
+
return this.#getSyntax().subtype;
|
|
71
|
+
}
|
|
72
|
+
/* NOT FOR BROWSER */
|
|
73
|
+
set subtype(subtype) {
|
|
74
|
+
this.setSyntax(subtype);
|
|
75
|
+
}
|
|
76
|
+
/** rowspan */
|
|
77
|
+
get rowspan() {
|
|
78
|
+
return this.getAttr('rowspan');
|
|
79
|
+
}
|
|
80
|
+
set rowspan(rowspan) {
|
|
81
|
+
this.setAttr('rowspan', rowspan);
|
|
82
|
+
}
|
|
83
|
+
/** colspan */
|
|
84
|
+
get colspan() {
|
|
85
|
+
return this.getAttr('colspan');
|
|
86
|
+
}
|
|
87
|
+
set colspan(colspan) {
|
|
88
|
+
this.setAttr('colspan', colspan);
|
|
89
|
+
}
|
|
90
|
+
/** 内部wikitext */
|
|
91
|
+
get innerText() {
|
|
92
|
+
return this.lastChild.text();
|
|
93
|
+
}
|
|
94
|
+
set innerText(text) {
|
|
95
|
+
this.lastChild.replaceChildren(...index_1.default.parse(text, true, undefined, this.getAttribute('config')).childNodes);
|
|
96
|
+
}
|
|
97
|
+
/* NOT FOR BROWSER END */
|
|
98
|
+
/**
|
|
99
|
+
* @param syntax 单元格语法
|
|
100
|
+
* @param inner 内部wikitext
|
|
101
|
+
*/
|
|
102
|
+
constructor(syntax, inner, config = index_1.default.getConfig(), accum = []) {
|
|
103
|
+
let innerSyntax = /\||\0\d+!\x7F/u.exec(inner ?? ''), attr = innerSyntax ? inner.slice(0, innerSyntax.index) : '';
|
|
104
|
+
if (/\[\[|-\{/u.test(attr)) {
|
|
105
|
+
innerSyntax = null;
|
|
106
|
+
attr = '';
|
|
107
|
+
}
|
|
108
|
+
super(/^(?:\n[^\S\n]*(?:[|!]|\|\+|\{\{\s*!\s*\}\}\+?)|(?:\||\{\{\s*!\s*\}\}){2}|!!|\{\{\s*!!\s*\}\})$/u, syntax, attr, config, accum, { SyntaxToken: 0, AttributesToken: 1, Token: 2 });
|
|
109
|
+
if (innerSyntax) {
|
|
110
|
+
[this.#innerSyntax] = innerSyntax;
|
|
111
|
+
}
|
|
112
|
+
const innerToken = new index_2.Token(inner?.slice((innerSyntax?.index ?? NaN) + this.#innerSyntax.length), config, accum);
|
|
113
|
+
innerToken.type = 'td-inner';
|
|
114
|
+
innerToken.setAttribute('stage', 4);
|
|
115
|
+
this.insertAt(innerToken);
|
|
116
|
+
}
|
|
117
|
+
/** 表格语法信息 */
|
|
118
|
+
#getSyntax() {
|
|
119
|
+
const syntax = this.firstChild.text(),
|
|
120
|
+
/* NOT FOR BROWSER */
|
|
121
|
+
esc = syntax.includes('{{'),
|
|
122
|
+
/* NOT FOR BROWSER END */
|
|
123
|
+
char = syntax.slice(-1);
|
|
124
|
+
let subtype = 'td';
|
|
125
|
+
if (char === '!') {
|
|
126
|
+
subtype = 'th';
|
|
127
|
+
}
|
|
128
|
+
else if (char === '+') {
|
|
129
|
+
subtype = 'caption';
|
|
130
|
+
}
|
|
131
|
+
if (this.isIndependent()) {
|
|
132
|
+
return {
|
|
133
|
+
subtype,
|
|
134
|
+
/* NOT FOR BROWSER */
|
|
135
|
+
escape: esc,
|
|
136
|
+
correction: false,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/* NOT FOR BROWSER */
|
|
140
|
+
const { previousSibling } = this;
|
|
141
|
+
if (!(previousSibling instanceof TdToken)) {
|
|
142
|
+
return { subtype, escape: esc, correction: true };
|
|
143
|
+
}
|
|
144
|
+
const result = previousSibling.#getSyntax(), str = String(previousSibling.lastChild);
|
|
145
|
+
result.escape ||= esc;
|
|
146
|
+
result.correction = str.includes('\n') && debug_1.Shadow.run(() => {
|
|
147
|
+
const config = this.getAttribute('config'), include = this.getAttribute('include');
|
|
148
|
+
return String(new index_2.Token(str, config).parseOnce(0, include).parseOnce()).includes('\n');
|
|
149
|
+
});
|
|
150
|
+
if (subtype === 'th' && result.subtype !== 'th') {
|
|
151
|
+
result.subtype = 'th';
|
|
152
|
+
result.correction = true;
|
|
153
|
+
}
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
/** @private */
|
|
157
|
+
afterBuild() {
|
|
158
|
+
if (this.#innerSyntax.includes('\0')) {
|
|
159
|
+
this.#innerSyntax = this.buildFromStr(this.#innerSyntax, constants_1.BuildMethod.String);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/** @private */
|
|
163
|
+
toString() {
|
|
164
|
+
/* NOT FOR BROWSER */
|
|
165
|
+
this.#correct();
|
|
166
|
+
/* NOT FOR BROWSER END */
|
|
167
|
+
const { childNodes: [syntax, attr, inner] } = this;
|
|
168
|
+
return `${String(syntax)}${String(attr)}${this.#innerSyntax}${String(inner)}`;
|
|
169
|
+
}
|
|
170
|
+
/** @override */
|
|
171
|
+
text() {
|
|
172
|
+
/* NOT FOR BROWSER */
|
|
173
|
+
this.#correct();
|
|
174
|
+
/* NOT FOR BROWSER END */
|
|
175
|
+
const { childNodes: [syntax, attr, inner] } = this;
|
|
176
|
+
return `${syntax.text()}${attr.text()}${this.#innerSyntax}${inner.text()}`;
|
|
177
|
+
}
|
|
178
|
+
/** @private */
|
|
179
|
+
getGaps(i) {
|
|
180
|
+
if (i === 1) {
|
|
181
|
+
/* NOT FOR BROWSER */
|
|
182
|
+
this.#correct();
|
|
183
|
+
/* NOT FOR BROWSER END */
|
|
184
|
+
return this.#innerSyntax.length;
|
|
185
|
+
}
|
|
186
|
+
return 0;
|
|
187
|
+
}
|
|
188
|
+
/** @override */
|
|
189
|
+
lint(start = this.getAbsoluteIndex()) {
|
|
190
|
+
const errors = super.lint(start);
|
|
191
|
+
start += this.getRelativeIndex(this.length - 1);
|
|
192
|
+
for (const child of this.lastChild.childNodes) {
|
|
193
|
+
if (child.type === 'text') {
|
|
194
|
+
const { data } = child;
|
|
195
|
+
if (data.includes('|')) {
|
|
196
|
+
errors.push((0, lint_1.generateForChild)(child, { start }, 'additional "|" in a table cell', data.includes('||') ? 'error' : 'warning'));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return errors;
|
|
201
|
+
}
|
|
202
|
+
/** @override */
|
|
203
|
+
print() {
|
|
204
|
+
const { childNodes: [syntax, attr, inner] } = this;
|
|
205
|
+
return `<span class="wpb-td">${syntax.print()}${attr.print()}${this.#innerSyntax}${inner.print()}</span>`;
|
|
206
|
+
}
|
|
207
|
+
/** @override */
|
|
208
|
+
json() {
|
|
209
|
+
const json = super.json();
|
|
210
|
+
json['subtype'] = this.subtype;
|
|
211
|
+
return json;
|
|
212
|
+
}
|
|
213
|
+
/* NOT FOR BROWSER */
|
|
214
|
+
/** 是否位于行首 */
|
|
215
|
+
isIndependent() {
|
|
216
|
+
return this.firstChild.text().startsWith('\n');
|
|
217
|
+
}
|
|
218
|
+
/** @override */
|
|
219
|
+
cloneNode() {
|
|
220
|
+
const token = super.cloneNode();
|
|
221
|
+
token.setAttribute('innerSyntax', this.#innerSyntax);
|
|
222
|
+
return token;
|
|
223
|
+
}
|
|
224
|
+
/** @private */
|
|
225
|
+
getAttribute(key) {
|
|
226
|
+
return key === 'innerSyntax' ? this.#innerSyntax : super.getAttribute(key);
|
|
227
|
+
}
|
|
228
|
+
/** @private */
|
|
229
|
+
setAttribute(key, value) {
|
|
230
|
+
if (key === 'innerSyntax') {
|
|
231
|
+
this.#innerSyntax = value ?? '';
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
super.setAttribute(key, value);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* @override
|
|
239
|
+
* @param syntax 表格语法
|
|
240
|
+
* @param esc 是否需要转义
|
|
241
|
+
*/
|
|
242
|
+
setSyntax(syntax, esc = false) {
|
|
243
|
+
const aliases = { td: '\n|', th: '\n!', caption: '\n|+' };
|
|
244
|
+
super.setSyntax(aliases[syntax] ?? syntax, esc);
|
|
245
|
+
}
|
|
246
|
+
/** 修复\<td\>语法 */
|
|
247
|
+
#correct() {
|
|
248
|
+
if (String(this.childNodes[1])) {
|
|
249
|
+
this.#innerSyntax ||= '|';
|
|
250
|
+
}
|
|
251
|
+
const { subtype, escape, correction } = this.#getSyntax();
|
|
252
|
+
if (correction) {
|
|
253
|
+
this.setSyntax(subtype, escape);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/** 改为独占一行 */
|
|
257
|
+
independence() {
|
|
258
|
+
if (!this.isIndependent()) {
|
|
259
|
+
const { subtype, escape } = this.#getSyntax();
|
|
260
|
+
this.setSyntax(subtype, escape);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* @override
|
|
265
|
+
* @param key 属性键
|
|
266
|
+
*/
|
|
267
|
+
getAttr(key) {
|
|
268
|
+
const value = super.getAttr(key);
|
|
269
|
+
key = key.toLowerCase().trim();
|
|
270
|
+
return (key === 'rowspan' || key === 'colspan' ? Number(value) || 1 : value);
|
|
271
|
+
}
|
|
272
|
+
/** @override */
|
|
273
|
+
getAttrs() {
|
|
274
|
+
const attr = super.getAttrs();
|
|
275
|
+
if ('rowspan' in attr) {
|
|
276
|
+
attr.rowspan = Number(attr.rowspan);
|
|
277
|
+
}
|
|
278
|
+
if ('colspan' in attr) {
|
|
279
|
+
attr.colspan = Number(attr.colspan);
|
|
280
|
+
}
|
|
281
|
+
return attr;
|
|
282
|
+
}
|
|
283
|
+
setAttr(keyOrProp, value) {
|
|
284
|
+
if (typeof keyOrProp !== 'string') {
|
|
285
|
+
for (const [key, val] of Object.entries(keyOrProp)) {
|
|
286
|
+
this.setAttr(key, val);
|
|
287
|
+
}
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const key = keyOrProp.toLowerCase().trim();
|
|
291
|
+
let v;
|
|
292
|
+
if (typeof value === 'number' && (key === 'rowspan' || key === 'colspan')) {
|
|
293
|
+
v = value === 1 ? false : String(value);
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
v = value;
|
|
297
|
+
}
|
|
298
|
+
super.setAttr(key, v);
|
|
299
|
+
if (!String(this.childNodes[1])) {
|
|
300
|
+
this.#innerSyntax = '';
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/** @override */
|
|
304
|
+
escape() {
|
|
305
|
+
super.escape();
|
|
306
|
+
if (String(this.childNodes[1])) {
|
|
307
|
+
this.#innerSyntax ||= '{{!}}';
|
|
308
|
+
}
|
|
309
|
+
if (this.#innerSyntax === '|') {
|
|
310
|
+
this.#innerSyntax = '{{!}}';
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
return TdToken = _classThis;
|
|
315
|
+
})();
|
|
316
|
+
exports.TdToken = TdToken;
|
|
317
|
+
/* NOT FOR BROWSER */
|
|
318
|
+
/**
|
|
319
|
+
* 创建新的单元格
|
|
320
|
+
* @param inner 内部wikitext
|
|
321
|
+
* @param subtype 单元格类型
|
|
322
|
+
* @param attr 单元格属性
|
|
323
|
+
* @param include 是否嵌入
|
|
324
|
+
* @param config
|
|
325
|
+
*/
|
|
326
|
+
const createTd = (inner, subtype = 'td', attr = {}, include = false, config = index_1.default.getConfig()) => {
|
|
327
|
+
const innerToken = typeof inner === 'string' ? index_1.default.parse(inner, include, undefined, config) : inner,
|
|
328
|
+
// @ts-expect-error abstract class
|
|
329
|
+
token = debug_1.Shadow.run(() => new TdToken('\n|', undefined, config));
|
|
330
|
+
token.setSyntax(subtype);
|
|
331
|
+
token.lastChild.safeReplaceWith(innerToken);
|
|
332
|
+
token.setAttr(attr);
|
|
333
|
+
return token;
|
|
334
|
+
};
|
|
335
|
+
exports.createTd = createTd;
|
|
336
|
+
/* NOT FOR BROWSER END */
|
|
337
|
+
constants_1.classes['TdToken'] = __filename;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import Parser from '../../index';
|
|
2
|
+
import { TrBaseToken } from './trBase';
|
|
3
|
+
import type { Token, TdToken, TableToken, SyntaxToken, AttributesToken } from '../../internal';
|
|
4
|
+
/**
|
|
5
|
+
* 表格行,含开头的换行,不含结尾的换行
|
|
6
|
+
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken]}`
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class TrToken extends TrBaseToken {
|
|
9
|
+
#private;
|
|
10
|
+
readonly type = "tr";
|
|
11
|
+
readonly childNodes: readonly [SyntaxToken, AttributesToken, ...TdToken[]];
|
|
12
|
+
abstract get lastChild(): AttributesToken | TdToken;
|
|
13
|
+
abstract get parentNode(): TableToken | undefined;
|
|
14
|
+
abstract get nextSibling(): this | SyntaxToken | undefined;
|
|
15
|
+
abstract get previousSibling(): Token;
|
|
16
|
+
abstract get children(): [SyntaxToken, AttributesToken, ...TdToken[]];
|
|
17
|
+
abstract get lastElementChild(): AttributesToken | TdToken;
|
|
18
|
+
abstract get parentElement(): TableToken | undefined;
|
|
19
|
+
abstract get nextElementSibling(): this | SyntaxToken | undefined;
|
|
20
|
+
abstract get previousElementSibling(): Token;
|
|
21
|
+
/**
|
|
22
|
+
* @param syntax 表格语法
|
|
23
|
+
* @param attr 表格属性
|
|
24
|
+
*/
|
|
25
|
+
constructor(syntax: string, attr?: string, config?: Parser.Config, accum?: Token[]);
|
|
26
|
+
/** @override */
|
|
27
|
+
text(): string;
|
|
28
|
+
/** 获取下一行 */
|
|
29
|
+
getNextRow(): TrToken | undefined;
|
|
30
|
+
/** 获取前一行 */
|
|
31
|
+
getPreviousRow(): TrToken | undefined;
|
|
32
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.TrToken = void 0;
|
|
5
|
+
const constants_1 = require("../../util/constants");
|
|
6
|
+
const index_1 = require("../../index");
|
|
7
|
+
const trBase_1 = require("./trBase");
|
|
8
|
+
/**
|
|
9
|
+
* 表格行,含开头的换行,不含结尾的换行
|
|
10
|
+
* @classdesc `{childNodes: [SyntaxToken, AttributesToken, ?Token, ...TdToken]}`
|
|
11
|
+
*/
|
|
12
|
+
class TrToken extends trBase_1.TrBaseToken {
|
|
13
|
+
type = 'tr';
|
|
14
|
+
/* NOT FOR BROWSER END */
|
|
15
|
+
/**
|
|
16
|
+
* @param syntax 表格语法
|
|
17
|
+
* @param attr 表格属性
|
|
18
|
+
*/
|
|
19
|
+
constructor(syntax, attr, config = index_1.default.getConfig(), accum = []) {
|
|
20
|
+
super(/^\n[^\S\n]*(?:\|-+|\{\{\s*!\s*\}\}-+|\{\{\s*!-\s*\}\}-*)$/u, syntax, attr, config, accum, {
|
|
21
|
+
Token: 2, SyntaxToken: 0, AttributesToken: 1, TdToken: '2:',
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/* NOT FOR BROWSER */
|
|
25
|
+
/** @override */
|
|
26
|
+
text() {
|
|
27
|
+
const str = super.text();
|
|
28
|
+
return str.trim().includes('\n') ? str : '';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 获取相邻行
|
|
32
|
+
* @param subset 筛选兄弟节点的方法
|
|
33
|
+
*/
|
|
34
|
+
#getSiblingRow(subset) {
|
|
35
|
+
const { parentNode } = this;
|
|
36
|
+
if (!parentNode) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
const { childNodes } = parentNode, index = childNodes.indexOf(this);
|
|
40
|
+
for (const child of subset(childNodes, index)) {
|
|
41
|
+
if (child instanceof _a && child.getRowCount()) {
|
|
42
|
+
return child;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
/** 获取下一行 */
|
|
48
|
+
getNextRow() {
|
|
49
|
+
return this.#getSiblingRow((childNodes, index) => childNodes.slice(index + 1));
|
|
50
|
+
}
|
|
51
|
+
/** 获取前一行 */
|
|
52
|
+
getPreviousRow() {
|
|
53
|
+
return this.#getSiblingRow((childNodes, index) => childNodes.slice(0, index).reverse());
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.TrToken = TrToken;
|
|
57
|
+
_a = TrToken;
|
|
58
|
+
constants_1.classes['TrToken'] = __filename;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Token } from '..';
|
|
2
|
+
import { TableBaseToken } from './base';
|
|
3
|
+
import { TdToken } from './td';
|
|
4
|
+
import type { LintError } from '../../base';
|
|
5
|
+
import type { AstNodes, SyntaxToken, TrToken } from '../../internal';
|
|
6
|
+
import type { TdAttrs, TdSubtypes } from './td';
|
|
7
|
+
export interface TableCoords {
|
|
8
|
+
readonly row: number;
|
|
9
|
+
readonly column: number;
|
|
10
|
+
readonly x?: undefined;
|
|
11
|
+
readonly y?: undefined;
|
|
12
|
+
readonly start?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** 表格行或表格 */
|
|
15
|
+
export declare abstract class TrBaseToken extends TableBaseToken {
|
|
16
|
+
#private;
|
|
17
|
+
type: 'table' | 'tr';
|
|
18
|
+
/** @override */
|
|
19
|
+
lint(start?: number): LintError[];
|
|
20
|
+
/** @override */
|
|
21
|
+
text(): string;
|
|
22
|
+
/**
|
|
23
|
+
* @override
|
|
24
|
+
* @param i 移除位置
|
|
25
|
+
*/
|
|
26
|
+
removeAt(i: number): AstNodes;
|
|
27
|
+
/**
|
|
28
|
+
* @override
|
|
29
|
+
* @param token 待插入的子节点
|
|
30
|
+
* @param i 插入位置
|
|
31
|
+
*/
|
|
32
|
+
insertAt<T extends Token>(token: T, i?: number): T;
|
|
33
|
+
/** 获取行数 */
|
|
34
|
+
getRowCount(): number;
|
|
35
|
+
/** 获取列数 */
|
|
36
|
+
getColCount(): number;
|
|
37
|
+
/**
|
|
38
|
+
* 获取第n列
|
|
39
|
+
* @param n 列号
|
|
40
|
+
* @param insert 是否用于判断插入新列的位置
|
|
41
|
+
* @throws `RangeError` 不存在对应单元格
|
|
42
|
+
*/
|
|
43
|
+
getNthCol(n: number, insert?: false): TdToken | undefined;
|
|
44
|
+
getNthCol(n: number, insert: true): TdToken | TrToken | SyntaxToken | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* 插入新的单元格
|
|
47
|
+
* @param inner 单元格内部wikitext
|
|
48
|
+
* @param {TableCoords} coord 单元格坐标
|
|
49
|
+
* @param subtype 单元格类型
|
|
50
|
+
* @param attr 单元格属性
|
|
51
|
+
*/
|
|
52
|
+
insertTableCell(inner: string | Token, { column }: TableCoords, subtype?: TdSubtypes, attr?: TdAttrs): TdToken;
|
|
53
|
+
}
|