wikiparser-node 1.12.5-b → 1.12.6
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 +203 -0
- package/config/default.json +30 -29
- package/config/enwiki.json +829 -15
- package/config/llwiki.json +56 -21
- package/config/moegirl.json +65 -21
- package/config/zhwiki.json +494 -28
- package/dist/addon/table.js +494 -0
- package/dist/addon/token.js +392 -0
- package/dist/addon/transclude.js +184 -0
- package/dist/base.d.ts +82 -0
- package/dist/base.js +40 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +275 -0
- package/dist/internal.d.ts +47 -0
- package/dist/lib/element.d.ts +125 -0
- package/dist/lib/element.js +377 -0
- package/dist/lib/node.d.ts +173 -0
- package/dist/lib/node.js +478 -0
- package/dist/lib/range.d.ts +105 -0
- package/dist/lib/range.js +406 -0
- package/dist/lib/ranges.d.ts +28 -0
- package/dist/lib/ranges.js +126 -0
- package/dist/lib/rect.d.ts +18 -0
- package/dist/lib/rect.js +36 -0
- package/dist/lib/text.d.ts +58 -0
- package/dist/lib/text.js +414 -0
- package/dist/lib/title.d.ts +49 -0
- package/dist/lib/title.js +253 -0
- package/dist/mixin/attributesParent.d.ts +49 -0
- package/dist/mixin/attributesParent.js +80 -0
- package/dist/mixin/fixed.d.ts +5 -0
- package/dist/mixin/fixed.js +32 -0
- package/dist/mixin/flagsParent.d.ts +43 -0
- package/dist/mixin/flagsParent.js +64 -0
- package/dist/mixin/hidden.d.ts +7 -0
- package/dist/mixin/hidden.js +39 -0
- package/dist/mixin/magicLinkParent.d.ts +19 -0
- package/dist/mixin/magicLinkParent.js +43 -0
- package/dist/mixin/singleLine.d.ts +5 -0
- package/dist/mixin/singleLine.js +25 -0
- package/dist/mixin/sol.d.ts +6 -0
- package/dist/mixin/sol.js +45 -0
- package/dist/mixin/syntax.d.ts +8 -0
- package/dist/mixin/syntax.js +46 -0
- package/dist/parser/braces.js +152 -0
- package/dist/parser/commentAndExt.js +84 -0
- package/dist/parser/converter.js +41 -0
- package/dist/parser/externalLinks.js +39 -0
- package/dist/parser/hrAndDoubleUnderscore.js +44 -0
- package/dist/parser/html.js +40 -0
- package/dist/parser/links.js +103 -0
- package/dist/parser/list.js +116 -0
- package/dist/parser/magicLinks.js +55 -0
- package/dist/parser/quotes.js +69 -0
- package/dist/parser/redirect.js +28 -0
- package/dist/parser/selector.js +393 -0
- package/dist/parser/table.js +125 -0
- package/dist/src/arg.d.ts +49 -0
- package/dist/src/arg.js +220 -0
- package/dist/src/atom.d.ts +14 -0
- package/dist/src/atom.js +54 -0
- package/dist/src/attribute.d.ts +64 -0
- package/dist/src/attribute.js +482 -0
- package/dist/src/attributes.d.ts +103 -0
- package/dist/src/attributes.js +380 -0
- package/dist/src/converter.d.ts +28 -0
- package/dist/src/converter.js +153 -0
- package/dist/src/converterFlags.d.ts +80 -0
- package/dist/src/converterFlags.js +241 -0
- package/dist/src/converterRule.d.ts +71 -0
- package/dist/src/converterRule.js +218 -0
- package/dist/src/extLink.d.ts +36 -0
- package/dist/src/extLink.js +223 -0
- package/dist/src/gallery.d.ts +51 -0
- package/dist/src/gallery.js +166 -0
- package/dist/src/heading.d.ts +44 -0
- package/dist/src/heading.js +222 -0
- package/dist/src/hidden.d.ts +9 -0
- package/dist/src/hidden.js +82 -0
- package/dist/src/html.d.ts +61 -0
- package/dist/src/html.js +344 -0
- package/dist/src/imageParameter.d.ts +60 -0
- package/dist/src/imageParameter.js +262 -0
- package/dist/src/imagemap.d.ts +47 -0
- package/dist/src/imagemap.js +148 -0
- package/dist/src/imagemapLink.d.ts +35 -0
- package/dist/src/imagemapLink.js +99 -0
- package/dist/src/index.d.ts +136 -0
- package/dist/src/index.js +790 -0
- package/dist/src/link/base.d.ts +52 -0
- package/dist/src/link/base.js +258 -0
- package/dist/src/link/category.d.ts +22 -0
- package/dist/src/link/category.js +36 -0
- package/dist/src/link/file.d.ts +102 -0
- package/dist/src/link/file.js +345 -0
- package/dist/src/link/galleryImage.d.ts +29 -0
- package/dist/src/link/galleryImage.js +133 -0
- package/dist/src/link/index.d.ts +39 -0
- package/dist/src/link/index.js +100 -0
- package/dist/src/link/redirectTarget.d.ts +27 -0
- package/dist/src/link/redirectTarget.js +71 -0
- package/dist/src/magicLink.d.ts +57 -0
- package/dist/src/magicLink.js +261 -0
- package/dist/src/nested.d.ts +40 -0
- package/dist/src/nested.js +108 -0
- package/dist/src/nowiki/base.d.ts +28 -0
- package/dist/src/nowiki/base.js +90 -0
- package/dist/src/nowiki/comment.d.ts +14 -0
- package/dist/src/nowiki/comment.js +123 -0
- package/dist/src/nowiki/dd.d.ts +8 -0
- package/dist/src/nowiki/dd.js +74 -0
- package/dist/src/nowiki/doubleUnderscore.d.ts +15 -0
- package/dist/src/nowiki/doubleUnderscore.js +101 -0
- package/dist/src/nowiki/hr.d.ts +5 -0
- package/dist/src/nowiki/hr.js +72 -0
- package/dist/src/nowiki/index.d.ts +14 -0
- package/dist/src/nowiki/index.js +30 -0
- package/dist/src/nowiki/list.d.ts +5 -0
- package/dist/src/nowiki/list.js +67 -0
- package/dist/src/nowiki/listBase.d.ts +23 -0
- package/dist/src/nowiki/listBase.js +100 -0
- package/dist/src/nowiki/noinclude.d.ts +6 -0
- package/dist/src/nowiki/noinclude.js +77 -0
- package/dist/src/nowiki/quote.d.ts +14 -0
- package/dist/src/nowiki/quote.js +149 -0
- package/dist/src/onlyinclude.d.ts +13 -0
- package/dist/src/onlyinclude.js +60 -0
- package/dist/src/paramTag/index.d.ts +28 -0
- package/dist/src/paramTag/index.js +80 -0
- package/dist/src/paramTag/inputbox.d.ts +8 -0
- package/dist/src/paramTag/inputbox.js +24 -0
- package/dist/src/parameter.d.ts +60 -0
- package/dist/src/parameter.js +267 -0
- package/dist/src/pre.d.ts +28 -0
- package/dist/src/pre.js +62 -0
- package/dist/src/redirect.d.ts +30 -0
- package/dist/src/redirect.js +128 -0
- package/dist/src/syntax.d.ts +15 -0
- package/dist/src/syntax.js +87 -0
- package/dist/src/table/base.d.ts +28 -0
- package/dist/src/table/base.js +81 -0
- package/dist/src/table/index.d.ts +230 -0
- package/dist/src/table/index.js +506 -0
- package/dist/src/table/td.d.ts +72 -0
- package/dist/src/table/td.js +375 -0
- package/dist/src/table/tr.d.ts +30 -0
- package/dist/src/table/tr.js +61 -0
- package/dist/src/table/trBase.d.ts +49 -0
- package/dist/src/table/trBase.js +165 -0
- package/dist/src/tagPair/ext.d.ts +29 -0
- package/dist/src/tagPair/ext.js +229 -0
- package/dist/src/tagPair/include.d.ts +33 -0
- package/dist/src/tagPair/include.js +132 -0
- package/dist/src/tagPair/index.d.ts +23 -0
- package/dist/src/tagPair/index.js +130 -0
- package/dist/src/transclude.d.ts +159 -0
- package/dist/src/transclude.js +598 -0
- package/dist/util/constants.js +26 -0
- package/dist/util/debug.js +95 -0
- package/dist/util/diff.js +83 -0
- package/dist/util/html.js +146 -0
- package/dist/util/lint.js +32 -0
- package/dist/util/string.js +107 -0
- package/errors/README +3 -0
- package/package.json +21 -28
- package/printed/README +3 -0
- package/bundle/bundle.min.js +0 -37
- package/extensions/dist/base.js +0 -163
- package/extensions/dist/codejar.js +0 -52
- package/extensions/dist/editor.js +0 -159
- package/extensions/dist/highlight.js +0 -30
- package/extensions/dist/lint.js +0 -72
- package/extensions/editor.css +0 -59
- package/extensions/ui.css +0 -162
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
closed: true;
|
|
15
|
+
readonly childNodes: readonly [AttributesToken, Token];
|
|
16
|
+
abstract get firstChild(): AttributesToken;
|
|
17
|
+
abstract get lastChild(): Token;
|
|
18
|
+
abstract get children(): [AttributesToken, Token];
|
|
19
|
+
abstract get firstElementChild(): AttributesToken;
|
|
20
|
+
get type(): 'ext';
|
|
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
|
+
cloneNode(): this;
|
|
29
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
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 rect_1 = require("../../lib/rect");
|
|
40
|
+
const index_1 = require("../../index");
|
|
41
|
+
const index_2 = require("../index");
|
|
42
|
+
const index_3 = require("./index");
|
|
43
|
+
const attributes_1 = require("../attributes");
|
|
44
|
+
const pre_1 = require("../pre");
|
|
45
|
+
const index_4 = require("../paramTag/index");
|
|
46
|
+
const inputbox_1 = require("../paramTag/inputbox");
|
|
47
|
+
const gallery_1 = require("../gallery");
|
|
48
|
+
const imagemap_1 = require("../imagemap");
|
|
49
|
+
const index_5 = require("../nowiki/index");
|
|
50
|
+
/* NOT FOR BROWSER */
|
|
51
|
+
const debug_1 = require("../../util/debug");
|
|
52
|
+
const constants_1 = require("../../util/constants");
|
|
53
|
+
const string_1 = require("../../util/string");
|
|
54
|
+
const html_1 = require("../../util/html");
|
|
55
|
+
const attributesParent_1 = require("../../mixin/attributesParent");
|
|
56
|
+
/* NOT FOR BROWSER END */
|
|
57
|
+
/**
|
|
58
|
+
* 从数组中删除指定元素
|
|
59
|
+
* @param arr 数组
|
|
60
|
+
* @param ele 元素
|
|
61
|
+
*/
|
|
62
|
+
const del = (arr, ele) => {
|
|
63
|
+
const set = new Set(arr);
|
|
64
|
+
set.delete(ele);
|
|
65
|
+
return [...set];
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* 扩展标签
|
|
69
|
+
* @classdesc `{childNodes: [AttributesToken, Token]}`
|
|
70
|
+
*/
|
|
71
|
+
let ExtToken = (() => {
|
|
72
|
+
let _classDecorators = [(0, attributesParent_1.attributesParent)()];
|
|
73
|
+
let _classDescriptor;
|
|
74
|
+
let _classExtraInitializers = [];
|
|
75
|
+
let _classThis;
|
|
76
|
+
let _classSuper = index_3.TagPairToken;
|
|
77
|
+
var ExtToken = class extends _classSuper {
|
|
78
|
+
static { _classThis = this; }
|
|
79
|
+
static {
|
|
80
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
81
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
82
|
+
ExtToken = _classThis = _classDescriptor.value;
|
|
83
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
84
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
85
|
+
}
|
|
86
|
+
/* NOT FOR BROWSER END */
|
|
87
|
+
get type() {
|
|
88
|
+
return 'ext';
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* @param name 标签名
|
|
92
|
+
* @param attr 标签属性
|
|
93
|
+
* @param inner 内部wikitext
|
|
94
|
+
* @param closed 是否封闭
|
|
95
|
+
*/
|
|
96
|
+
constructor(name, attr, inner, closed, config = index_1.default.getConfig(), accum = []) {
|
|
97
|
+
const lcName = name.toLowerCase(),
|
|
98
|
+
// @ts-expect-error abstract class
|
|
99
|
+
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 ?? []] };
|
|
100
|
+
let innerToken;
|
|
101
|
+
switch (lcName) {
|
|
102
|
+
case 'tab':
|
|
103
|
+
newConfig.ext = del(newConfig.ext, 'tabs');
|
|
104
|
+
// fall through
|
|
105
|
+
case 'indicator':
|
|
106
|
+
case 'poem':
|
|
107
|
+
case 'ref':
|
|
108
|
+
case 'option':
|
|
109
|
+
case 'combooption':
|
|
110
|
+
case 'tabs':
|
|
111
|
+
case 'poll':
|
|
112
|
+
case 'seo':
|
|
113
|
+
if (lcName === 'poem') {
|
|
114
|
+
newConfig.excludes.push('heading');
|
|
115
|
+
}
|
|
116
|
+
innerToken = new index_2.Token(inner, newConfig, accum);
|
|
117
|
+
break;
|
|
118
|
+
case 'pre':
|
|
119
|
+
// @ts-expect-error abstract class
|
|
120
|
+
innerToken = new pre_1.PreToken(inner, newConfig, accum);
|
|
121
|
+
break;
|
|
122
|
+
case 'dynamicpagelist':
|
|
123
|
+
// @ts-expect-error abstract class
|
|
124
|
+
innerToken = new index_4.ParamTagToken(inner, newConfig, accum);
|
|
125
|
+
break;
|
|
126
|
+
case 'inputbox':
|
|
127
|
+
newConfig.excludes.push('heading');
|
|
128
|
+
// @ts-expect-error abstract class
|
|
129
|
+
innerToken = new inputbox_1.InputboxToken(inner, newConfig, accum);
|
|
130
|
+
break;
|
|
131
|
+
case 'references': {
|
|
132
|
+
const { NestedToken } = require('../nested');
|
|
133
|
+
// @ts-expect-error abstract class
|
|
134
|
+
innerToken = new NestedToken(inner, /<!--.*?(?:-->|$)|<(ref)(\s[^>]*?)?(?:\/>|>(.*?)<\/(ref\s*)>)/gisu, ['ref'], newConfig, accum);
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
case 'choose': {
|
|
138
|
+
const { NestedToken } = require('../nested');
|
|
139
|
+
// @ts-expect-error abstract class
|
|
140
|
+
innerToken = new NestedToken(inner, /<(option|choicetemplate)(\s[^>]*?)?(?:\/>|>(.*?)<\/(\1)>)/gsu, ['option', 'choicetemplate'], newConfig, accum);
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
case 'combobox': {
|
|
144
|
+
const { NestedToken } = require('../nested');
|
|
145
|
+
// @ts-expect-error abstract class
|
|
146
|
+
innerToken = new NestedToken(inner, /<(combooption)(\s[^>]*?)?(?:\/>|>(.*?)<\/(combooption\s*)>)/gisu, ['combooption'], newConfig, accum);
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
case 'gallery':
|
|
150
|
+
// @ts-expect-error abstract class
|
|
151
|
+
innerToken = new gallery_1.GalleryToken(inner, newConfig, accum);
|
|
152
|
+
break;
|
|
153
|
+
case 'imagemap':
|
|
154
|
+
// @ts-expect-error abstract class
|
|
155
|
+
innerToken = new imagemap_1.ImagemapToken(inner, newConfig, accum);
|
|
156
|
+
break;
|
|
157
|
+
// 更多定制扩展的代码示例:
|
|
158
|
+
// ```
|
|
159
|
+
// case 'extensionName': {
|
|
160
|
+
// const {ExtensionToken}: typeof import('../extension') = require('../extension');
|
|
161
|
+
// innerToken = new ExtensionToken(inner, newConfig, accum);
|
|
162
|
+
// break;
|
|
163
|
+
// }
|
|
164
|
+
// ```
|
|
165
|
+
default:
|
|
166
|
+
// @ts-expect-error abstract class
|
|
167
|
+
innerToken = new index_5.NowikiToken(inner, newConfig, accum);
|
|
168
|
+
}
|
|
169
|
+
innerToken.setAttribute('name', lcName);
|
|
170
|
+
if (innerToken.type === 'plain') {
|
|
171
|
+
innerToken.type = 'ext-inner';
|
|
172
|
+
}
|
|
173
|
+
super(name, attrToken, innerToken, closed, config, accum);
|
|
174
|
+
this.seal('closed', true);
|
|
175
|
+
}
|
|
176
|
+
/** @private */
|
|
177
|
+
lint(start = this.getAbsoluteIndex(), re) {
|
|
178
|
+
const errors = super.lint(start, re), rect = new rect_1.BoundingRect(this, start);
|
|
179
|
+
if (this.name !== 'nowiki' && this.closest('html-attrs,table-attrs')) {
|
|
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
|
+
errors.push((0, lint_1.generateForSelf)(this, rect, 'var-anchor', 'variable anchor in a section header'));
|
|
184
|
+
}
|
|
185
|
+
return errors;
|
|
186
|
+
}
|
|
187
|
+
/* NOT FOR BROWSER */
|
|
188
|
+
cloneNode() {
|
|
189
|
+
const inner = this.lastChild.cloneNode(), tags = this.getAttribute('tags'), config = this.getAttribute('config'), attr = this.firstChild.toString();
|
|
190
|
+
return debug_1.Shadow.run(() => {
|
|
191
|
+
// @ts-expect-error abstract class
|
|
192
|
+
const token = new ExtToken(tags[0], attr, '', this.selfClosing ? undefined : tags[1], config);
|
|
193
|
+
token.lastChild.safeReplaceWith(inner);
|
|
194
|
+
return token;
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/** @private */
|
|
198
|
+
toHtmlInternal(_, nocc) {
|
|
199
|
+
const { name, firstChild, lastChild } = this;
|
|
200
|
+
switch (name) {
|
|
201
|
+
case 'nowiki':
|
|
202
|
+
return (0, html_1.font)(this, (0, string_1.newline)(lastChild.toHtmlInternal()));
|
|
203
|
+
case 'pre':
|
|
204
|
+
return (0, html_1.font)(this, `<pre${firstChild.toHtmlInternal()}>${(0, string_1.newline)(lastChild.toHtmlInternal(false, nocc))}</pre>`);
|
|
205
|
+
case 'poem':
|
|
206
|
+
firstChild.classList.add('poem');
|
|
207
|
+
return (0, html_1.font)(this, `<div${firstChild.toHtmlInternal()}>${lastChild.toHtmlInternal(false, nocc).replace(/(?<!^|<hr>)\n(?!$)/gu, '<br>\n')
|
|
208
|
+
.replace(/^ +/gmu, p => ' '.repeat(p.length))}</div>`);
|
|
209
|
+
case 'gallery': {
|
|
210
|
+
const caption = firstChild.getAttrToken('caption'), perrow = parseInt(String(firstChild.getAttr('perrow'))), mode = firstChild.getAttr('mode'), nolines = typeof mode === 'string' && mode.toLowerCase() === 'nolines', padding = nolines ? 9 : 43;
|
|
211
|
+
firstChild.classList.add('gallery');
|
|
212
|
+
if (nolines) {
|
|
213
|
+
firstChild.classList.add('mw-gallery-nolines');
|
|
214
|
+
}
|
|
215
|
+
if (perrow > 0) {
|
|
216
|
+
const style = firstChild.getAttr('style');
|
|
217
|
+
firstChild.setAttr('style', `max-width: ${(lastChild.widths + padding) * perrow}px;${typeof style === 'string' ? style : ''}`);
|
|
218
|
+
}
|
|
219
|
+
return (0, html_1.font)(this, `<ul${firstChild.toHtmlInternal()}>\n${caption ? `\t<li class="gallerycaption">${caption.lastChild.toHtmlInternal(true)}</li>\n` : ''}${lastChild.toHtmlInternal()}\n</ul>`);
|
|
220
|
+
}
|
|
221
|
+
default:
|
|
222
|
+
return '';
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
return ExtToken = _classThis;
|
|
227
|
+
})();
|
|
228
|
+
exports.ExtToken = ExtToken;
|
|
229
|
+
constants_1.classes['ExtToken'] = __filename;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { TagPairToken } from './index';
|
|
2
|
+
import type { LintError, Config } from '../../base';
|
|
3
|
+
import type { AstText, Token } from '../../internal';
|
|
4
|
+
/**
|
|
5
|
+
* `<includeonly>`或`<noinclude>`或`<onlyinclude>`
|
|
6
|
+
* @classdesc `{childNodes: [AstText, AstText]}`
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class IncludeToken extends TagPairToken {
|
|
9
|
+
readonly childNodes: readonly [AstText, AstText];
|
|
10
|
+
abstract get firstChild(): AstText;
|
|
11
|
+
abstract get lastChild(): AstText;
|
|
12
|
+
abstract get children(): [];
|
|
13
|
+
abstract get firstElementChild(): undefined;
|
|
14
|
+
abstract get lastElementChild(): undefined;
|
|
15
|
+
get type(): 'include';
|
|
16
|
+
get innerText(): string | undefined;
|
|
17
|
+
set innerText(text: string | undefined);
|
|
18
|
+
/**
|
|
19
|
+
* @param name 标签名
|
|
20
|
+
* @param attr 标签属性
|
|
21
|
+
* @param inner 内部wikitext
|
|
22
|
+
* @param closed 是否封闭
|
|
23
|
+
*/
|
|
24
|
+
constructor(name: string, attr?: string, inner?: string, closed?: string, config?: Config, accum?: Token[]);
|
|
25
|
+
cloneNode(): this;
|
|
26
|
+
/**
|
|
27
|
+
* @override
|
|
28
|
+
* @param str 新文本
|
|
29
|
+
*/
|
|
30
|
+
setText(str: string): string;
|
|
31
|
+
/** 清除标签属性 */
|
|
32
|
+
removeAttr(): void;
|
|
33
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
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.IncludeToken = void 0;
|
|
38
|
+
const lint_1 = require("../../util/lint");
|
|
39
|
+
const hidden_1 = require("../../mixin/hidden");
|
|
40
|
+
const index_1 = require("../../index");
|
|
41
|
+
const index_2 = require("./index");
|
|
42
|
+
/* NOT FOR BROWSER */
|
|
43
|
+
const debug_1 = require("../../util/debug");
|
|
44
|
+
const constants_1 = require("../../util/constants");
|
|
45
|
+
/* NOT FOR BROWSER END */
|
|
46
|
+
/**
|
|
47
|
+
* `<includeonly>`或`<noinclude>`或`<onlyinclude>`
|
|
48
|
+
* @classdesc `{childNodes: [AstText, AstText]}`
|
|
49
|
+
*/
|
|
50
|
+
let IncludeToken = (() => {
|
|
51
|
+
let _classDecorators = [(0, hidden_1.hiddenToken)(false)];
|
|
52
|
+
let _classDescriptor;
|
|
53
|
+
let _classExtraInitializers = [];
|
|
54
|
+
let _classThis;
|
|
55
|
+
let _classSuper = index_2.TagPairToken;
|
|
56
|
+
var IncludeToken = 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
|
+
IncludeToken = _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
|
+
/* NOT FOR BROWSER END */
|
|
66
|
+
get type() {
|
|
67
|
+
return 'include';
|
|
68
|
+
}
|
|
69
|
+
/* NOT FOR BROWSER */
|
|
70
|
+
get innerText() {
|
|
71
|
+
return this.selfClosing ? undefined : this.lastChild.data;
|
|
72
|
+
}
|
|
73
|
+
set innerText(text) {
|
|
74
|
+
if (text === undefined) {
|
|
75
|
+
this.selfClosing = true;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this.selfClosing = false;
|
|
79
|
+
this.setText(text);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/* NOT FOR BROWSER END */
|
|
83
|
+
/**
|
|
84
|
+
* @param name 标签名
|
|
85
|
+
* @param attr 标签属性
|
|
86
|
+
* @param inner 内部wikitext
|
|
87
|
+
* @param closed 是否封闭
|
|
88
|
+
*/
|
|
89
|
+
constructor(name, attr = '', inner, closed, config, accum) {
|
|
90
|
+
super(name, attr, inner ?? '', inner === undefined ? closed : closed ?? '', config, accum);
|
|
91
|
+
}
|
|
92
|
+
/** @private */
|
|
93
|
+
toString(skip) {
|
|
94
|
+
return skip ? '' : super.toString();
|
|
95
|
+
}
|
|
96
|
+
/** @private */
|
|
97
|
+
lint(start = this.getAbsoluteIndex()) {
|
|
98
|
+
if (this.closed) {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
const e = (0, lint_1.generateForSelf)(this, { start }, 'unclosed-comment', index_1.default.msg('unclosed $1', `<${this.name}>`));
|
|
102
|
+
e.suggestions = [
|
|
103
|
+
{
|
|
104
|
+
desc: 'close',
|
|
105
|
+
range: [e.endIndex, e.endIndex],
|
|
106
|
+
text: `</${this.name}>`,
|
|
107
|
+
},
|
|
108
|
+
];
|
|
109
|
+
return [e];
|
|
110
|
+
}
|
|
111
|
+
/* NOT FOR BROWSER */
|
|
112
|
+
cloneNode() {
|
|
113
|
+
const tags = this.getAttribute('tags'), config = this.getAttribute('config'), { innerText } = this, closing = this.selfClosing || !this.closed ? undefined : tags[1];
|
|
114
|
+
// @ts-expect-error abstract class
|
|
115
|
+
return debug_1.Shadow.run(() => new IncludeToken(tags[0], this.firstChild.data, innerText, closing, config));
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* @override
|
|
119
|
+
* @param str 新文本
|
|
120
|
+
*/
|
|
121
|
+
setText(str) {
|
|
122
|
+
return super.setText(str, 1);
|
|
123
|
+
}
|
|
124
|
+
/** 清除标签属性 */
|
|
125
|
+
removeAttr() {
|
|
126
|
+
super.setText('');
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
return IncludeToken = _classThis;
|
|
130
|
+
})();
|
|
131
|
+
exports.IncludeToken = IncludeToken;
|
|
132
|
+
constants_1.classes['IncludeToken'] = __filename;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Token } from '../index';
|
|
2
|
+
import type { Config } from '../../base';
|
|
3
|
+
import type { AstNodes } from '../../lib/node';
|
|
4
|
+
/** 成对标签 */
|
|
5
|
+
export declare abstract class TagPairToken extends Token {
|
|
6
|
+
#private;
|
|
7
|
+
readonly name: string;
|
|
8
|
+
closed: boolean;
|
|
9
|
+
selfClosing: boolean;
|
|
10
|
+
abstract get type(): 'ext' | 'include';
|
|
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?: Config, accum?: Token[]);
|
|
23
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
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 index_1 = require("../index");
|
|
39
|
+
/* NOT FOR BROWSER */
|
|
40
|
+
const constants_1 = require("../../util/constants");
|
|
41
|
+
const fixed_1 = require("../../mixin/fixed");
|
|
42
|
+
const index_2 = require("../../index");
|
|
43
|
+
/* NOT FOR BROWSER END */
|
|
44
|
+
/** 成对标签 */
|
|
45
|
+
let TagPairToken = (() => {
|
|
46
|
+
let _classDecorators = [fixed_1.fixedToken];
|
|
47
|
+
let _classDescriptor;
|
|
48
|
+
let _classExtraInitializers = [];
|
|
49
|
+
let _classThis;
|
|
50
|
+
let _classSuper = index_1.Token;
|
|
51
|
+
var TagPairToken = class extends _classSuper {
|
|
52
|
+
static { _classThis = this; }
|
|
53
|
+
static {
|
|
54
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
55
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
56
|
+
TagPairToken = _classThis = _classDescriptor.value;
|
|
57
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
58
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
59
|
+
}
|
|
60
|
+
#tags;
|
|
61
|
+
closed;
|
|
62
|
+
selfClosing;
|
|
63
|
+
/* NOT FOR BROWSER END */
|
|
64
|
+
/** 内部wikitext */
|
|
65
|
+
get innerText() {
|
|
66
|
+
return this.selfClosing ? undefined : this.lastChild.text();
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @param name 标签名
|
|
70
|
+
* @param attr 标签属性
|
|
71
|
+
* @param inner 内部wikitext
|
|
72
|
+
* @param closed 是否封闭;约定`undefined`表示自封闭,`''`表示未闭合
|
|
73
|
+
*/
|
|
74
|
+
constructor(name, attr, inner, closed, config, accum = []) {
|
|
75
|
+
super(undefined, config);
|
|
76
|
+
this.setAttribute('name', name.toLowerCase());
|
|
77
|
+
this.#tags = [name, closed || name];
|
|
78
|
+
this.closed = closed !== '';
|
|
79
|
+
this.selfClosing = closed === undefined;
|
|
80
|
+
this.append(attr, inner);
|
|
81
|
+
const index = typeof attr === 'string' ? -1 : accum.indexOf(attr);
|
|
82
|
+
accum.splice(index === -1 ? Infinity : index, 0, this);
|
|
83
|
+
}
|
|
84
|
+
/** @private */
|
|
85
|
+
toString(skip) {
|
|
86
|
+
const { selfClosing, firstChild, lastChild,
|
|
87
|
+
/* NOT FOR BROWSER */
|
|
88
|
+
nextSibling, name, closed, } = this, [opening, closing] = this.#tags;
|
|
89
|
+
/* NOT FOR BROWSER */
|
|
90
|
+
if (!closed && nextSibling) {
|
|
91
|
+
index_2.default.error(`Auto-closing <${name}>`, lastChild);
|
|
92
|
+
this.closed = true;
|
|
93
|
+
}
|
|
94
|
+
/* NOT FOR BROWSER END */
|
|
95
|
+
return selfClosing
|
|
96
|
+
? `<${opening}${firstChild.toString(skip)}/>`
|
|
97
|
+
: `<${opening}${firstChild.toString(skip)}>${lastChild.toString(skip)}${this.closed ? `</${closing}>` : ''}`;
|
|
98
|
+
}
|
|
99
|
+
/** @private */
|
|
100
|
+
text() {
|
|
101
|
+
const [opening, closing] = this.#tags;
|
|
102
|
+
return this.selfClosing
|
|
103
|
+
? `<${opening}${this.firstChild.text()}/>`
|
|
104
|
+
: `<${opening}${super.text('>')}${this.closed ? `</${closing}>` : ''}`;
|
|
105
|
+
}
|
|
106
|
+
/** @private */
|
|
107
|
+
getAttribute(key) {
|
|
108
|
+
/* NOT FOR BROWSER */
|
|
109
|
+
if (key === 'tags') {
|
|
110
|
+
return this.#tags;
|
|
111
|
+
}
|
|
112
|
+
/* NOT FOR BROWSER END */
|
|
113
|
+
return key === 'padding' ? this.#tags[0].length + 1 : super.getAttribute(key);
|
|
114
|
+
}
|
|
115
|
+
/** @private */
|
|
116
|
+
getGaps() {
|
|
117
|
+
return 1;
|
|
118
|
+
}
|
|
119
|
+
/** @private */
|
|
120
|
+
print() {
|
|
121
|
+
const [opening, closing] = this.#tags;
|
|
122
|
+
return super.print(this.selfClosing
|
|
123
|
+
? { pre: `<${opening}`, post: '/>' }
|
|
124
|
+
: { pre: `<${opening}`, sep: '>', post: this.closed ? `</${closing}>` : '' });
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
return TagPairToken = _classThis;
|
|
128
|
+
})();
|
|
129
|
+
exports.TagPairToken = TagPairToken;
|
|
130
|
+
constants_1.classes['TagPairToken'] = __filename;
|