wikiparser-node 1.3.2 → 1.3.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 +36 -0
- package/config/llwiki.json +1 -35
- package/config/moegirl.json +1 -44
- package/config/zhwiki.json +1 -466
- package/extensions/dist/base.js +68 -0
- package/extensions/dist/editor.js +159 -0
- package/extensions/dist/highlight.js +30 -0
- package/extensions/dist/lint.js +48 -0
- package/extensions/editor.css +63 -0
- package/extensions/ui.css +114 -0
- package/package.json +32 -12
- 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 -45
- package/dist/bin/toc.js +0 -18
- package/dist/index.d.ts +0 -31
- package/dist/index.js +0 -209
- package/dist/internal.d.ts +0 -44
- package/dist/lib/element.d.ts +0 -155
- package/dist/lib/element.js +0 -634
- package/dist/lib/node.d.ts +0 -146
- package/dist/lib/node.js +0 -419
- 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 -117
- package/dist/lib/text.d.ts +0 -62
- package/dist/lib/text.js +0 -248
- package/dist/lib/title.d.ts +0 -38
- package/dist/lib/title.js +0 -162
- package/dist/mixin/attributesParent.js +0 -94
- package/dist/mixin/fixed.js +0 -32
- package/dist/mixin/flagsParent.js +0 -70
- package/dist/mixin/hidden.js +0 -26
- package/dist/mixin/magicLinkParent.js +0 -41
- package/dist/mixin/singleLine.js +0 -25
- package/dist/mixin/sol.js +0 -43
- package/dist/mixin/syntax.js +0 -56
- package/dist/parser/braces.js +0 -121
- package/dist/parser/commentAndExt.js +0 -69
- package/dist/parser/converter.js +0 -40
- package/dist/parser/externalLinks.js +0 -28
- package/dist/parser/hrAndDoubleUnderscore.js +0 -38
- package/dist/parser/html.js +0 -36
- package/dist/parser/links.js +0 -94
- package/dist/parser/list.js +0 -59
- package/dist/parser/magicLinks.js +0 -40
- package/dist/parser/quotes.js +0 -67
- package/dist/parser/selector.js +0 -162
- package/dist/parser/table.js +0 -112
- package/dist/src/arg.d.ts +0 -58
- package/dist/src/arg.js +0 -189
- package/dist/src/atom.d.ts +0 -12
- package/dist/src/atom.js +0 -27
- package/dist/src/attribute.d.ts +0 -87
- package/dist/src/attribute.js +0 -392
- package/dist/src/attributes.d.ts +0 -107
- package/dist/src/attributes.js +0 -341
- package/dist/src/converter.d.ts +0 -52
- package/dist/src/converter.js +0 -79
- package/dist/src/converterFlags.d.ts +0 -87
- package/dist/src/converterFlags.js +0 -224
- package/dist/src/converterRule.d.ts +0 -81
- package/dist/src/converterRule.js +0 -212
- package/dist/src/extLink.d.ts +0 -54
- package/dist/src/extLink.js +0 -122
- package/dist/src/gallery.d.ts +0 -55
- package/dist/src/gallery.js +0 -122
- package/dist/src/heading.d.ts +0 -74
- package/dist/src/heading.js +0 -127
- package/dist/src/hidden.d.ts +0 -22
- package/dist/src/hidden.js +0 -23
- package/dist/src/html.d.ts +0 -101
- package/dist/src/html.js +0 -222
- package/dist/src/imageParameter.d.ts +0 -66
- package/dist/src/imageParameter.js +0 -247
- package/dist/src/imagemap.d.ts +0 -57
- package/dist/src/imagemap.js +0 -148
- package/dist/src/imagemapLink.d.ts +0 -59
- package/dist/src/imagemapLink.js +0 -40
- package/dist/src/index.d.ts +0 -146
- package/dist/src/index.js +0 -777
- package/dist/src/link/base.d.ts +0 -52
- package/dist/src/link/base.js +0 -209
- package/dist/src/link/category.d.ts +0 -13
- package/dist/src/link/category.js +0 -29
- package/dist/src/link/file.d.ts +0 -96
- package/dist/src/link/file.js +0 -255
- package/dist/src/link/galleryImage.d.ts +0 -44
- package/dist/src/link/galleryImage.js +0 -106
- package/dist/src/link/index.d.ts +0 -53
- package/dist/src/link/index.js +0 -123
- package/dist/src/magicLink.d.ts +0 -70
- package/dist/src/magicLink.js +0 -147
- package/dist/src/nested.d.ts +0 -44
- package/dist/src/nested.js +0 -87
- package/dist/src/nowiki/base.d.ts +0 -47
- package/dist/src/nowiki/base.js +0 -42
- package/dist/src/nowiki/comment.d.ts +0 -40
- package/dist/src/nowiki/comment.js +0 -67
- package/dist/src/nowiki/dd.d.ts +0 -8
- package/dist/src/nowiki/dd.js +0 -25
- package/dist/src/nowiki/doubleUnderscore.d.ts +0 -45
- package/dist/src/nowiki/doubleUnderscore.js +0 -50
- package/dist/src/nowiki/hr.d.ts +0 -31
- package/dist/src/nowiki/hr.js +0 -14
- package/dist/src/nowiki/index.d.ts +0 -16
- package/dist/src/nowiki/index.js +0 -21
- package/dist/src/nowiki/list.d.ts +0 -30
- package/dist/src/nowiki/list.js +0 -48
- package/dist/src/nowiki/listBase.d.ts +0 -19
- package/dist/src/nowiki/listBase.js +0 -12
- package/dist/src/nowiki/noinclude.d.ts +0 -26
- package/dist/src/nowiki/noinclude.js +0 -25
- package/dist/src/nowiki/quote.d.ts +0 -23
- package/dist/src/nowiki/quote.js +0 -45
- 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 -68
- package/dist/src/paramTag/inputbox.d.ts +0 -8
- package/dist/src/paramTag/inputbox.js +0 -23
- package/dist/src/parameter.d.ts +0 -85
- package/dist/src/parameter.js +0 -205
- package/dist/src/pre.d.ts +0 -28
- package/dist/src/pre.js +0 -51
- package/dist/src/syntax.d.ts +0 -28
- package/dist/src/syntax.js +0 -34
- package/dist/src/table/base.d.ts +0 -53
- package/dist/src/table/base.js +0 -78
- package/dist/src/table/index.d.ts +0 -229
- package/dist/src/table/index.js +0 -379
- package/dist/src/table/td.d.ts +0 -104
- package/dist/src/table/td.js +0 -261
- package/dist/src/table/tr.d.ts +0 -32
- package/dist/src/table/tr.js +0 -56
- package/dist/src/table/trBase.d.ts +0 -54
- package/dist/src/table/trBase.js +0 -159
- package/dist/src/tagPair/ext.d.ts +0 -56
- package/dist/src/tagPair/ext.js +0 -142
- package/dist/src/tagPair/include.d.ts +0 -53
- package/dist/src/tagPair/include.js +0 -63
- package/dist/src/tagPair/index.d.ts +0 -48
- package/dist/src/tagPair/index.js +0 -93
- package/dist/src/transclude.d.ts +0 -167
- package/dist/src/transclude.js +0 -689
- package/dist/util/constants.js +0 -108
- package/dist/util/debug.js +0 -64
- package/dist/util/diff.js +0 -72
- package/dist/util/lint.js +0 -46
- package/dist/util/string.js +0 -61
- package/errors/README +0 -1
- package/printed/README +0 -1
package/dist/src/link/base.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import * as Parser from '../../index';
|
|
2
|
-
import { Token } from '../index';
|
|
3
|
-
import { AtomToken } from '../atom';
|
|
4
|
-
import type { LintError } from '../../base';
|
|
5
|
-
import type { Title } from '../../lib/title';
|
|
6
|
-
/**
|
|
7
|
-
* 内链
|
|
8
|
-
* @classdesc `{childNodes: [AtomToken, ...Token]}`
|
|
9
|
-
*/
|
|
10
|
-
export declare abstract class LinkBaseToken extends Token {
|
|
11
|
-
#private;
|
|
12
|
-
type: 'link' | 'category' | 'file' | 'gallery-image' | 'imagemap-image';
|
|
13
|
-
readonly name: string;
|
|
14
|
-
readonly childNodes: [AtomToken, ...Token[]];
|
|
15
|
-
abstract get children(): [AtomToken, ...Token[]];
|
|
16
|
-
abstract get firstChild(): AtomToken;
|
|
17
|
-
abstract get firstElementChild(): AtomToken;
|
|
18
|
-
abstract get lastChild(): Token;
|
|
19
|
-
abstract get lastElementChild(): Token;
|
|
20
|
-
/** 完整链接 */
|
|
21
|
-
get link(): string | Title;
|
|
22
|
-
set link(link: string);
|
|
23
|
-
/** fragment */
|
|
24
|
-
get fragment(): string | undefined;
|
|
25
|
-
set fragment(fragment: string | undefined);
|
|
26
|
-
/**
|
|
27
|
-
* @param link 链接标题
|
|
28
|
-
* @param linkText 链接显示文字
|
|
29
|
-
* @param delimiter `|`
|
|
30
|
-
*/
|
|
31
|
-
constructor(link: string, linkText?: string, config?: Parser.Config, accum?: Token[], delimiter?: string);
|
|
32
|
-
/** @override */
|
|
33
|
-
text(): string;
|
|
34
|
-
/** @override */
|
|
35
|
-
lint(start?: number): LintError[];
|
|
36
|
-
/** @override */
|
|
37
|
-
print(): string;
|
|
38
|
-
/** @override */
|
|
39
|
-
cloneNode(this: this & {
|
|
40
|
-
constructor: new (...args: any[]) => unknown;
|
|
41
|
-
}): this;
|
|
42
|
-
/**
|
|
43
|
-
* 设置链接目标
|
|
44
|
-
* @param link 链接目标
|
|
45
|
-
*/
|
|
46
|
-
setTarget(link: string): void;
|
|
47
|
-
/**
|
|
48
|
-
* 设置链接显示文字
|
|
49
|
-
* @param linkStr 链接显示文字
|
|
50
|
-
*/
|
|
51
|
-
setLinkText(linkStr?: string): void;
|
|
52
|
-
}
|
package/dist/src/link/base.js
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LinkBaseToken = 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 Parser = require("../../index");
|
|
8
|
-
const index_1 = require("../index");
|
|
9
|
-
const atom_1 = require("../atom");
|
|
10
|
-
/**
|
|
11
|
-
* 内链
|
|
12
|
-
* @classdesc `{childNodes: [AtomToken, ...Token]}`
|
|
13
|
-
*/
|
|
14
|
-
class LinkBaseToken extends index_1.Token {
|
|
15
|
-
#bracket = true;
|
|
16
|
-
#delimiter;
|
|
17
|
-
#title;
|
|
18
|
-
/* NOT FOR BROWSER */
|
|
19
|
-
/** 完整链接 */
|
|
20
|
-
get link() {
|
|
21
|
-
return this.#title;
|
|
22
|
-
}
|
|
23
|
-
set link(link) {
|
|
24
|
-
this.setTarget(link);
|
|
25
|
-
}
|
|
26
|
-
/** fragment */
|
|
27
|
-
get fragment() {
|
|
28
|
-
return this.#title.fragment;
|
|
29
|
-
}
|
|
30
|
-
set fragment(fragment) {
|
|
31
|
-
if (fragment === undefined) {
|
|
32
|
-
this.setTarget(this.name);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
/* NOT FOR BROWSER END */
|
|
36
|
-
/**
|
|
37
|
-
* @param link 链接标题
|
|
38
|
-
* @param linkText 链接显示文字
|
|
39
|
-
* @param delimiter `|`
|
|
40
|
-
*/
|
|
41
|
-
constructor(link, linkText, config = Parser.getConfig(), accum = [], delimiter = '|') {
|
|
42
|
-
super(undefined, config, accum, {
|
|
43
|
-
AtomToken: 0, Token: 1,
|
|
44
|
-
});
|
|
45
|
-
this.insertAt(new atom_1.AtomToken(link, 'link-target', config, accum, {
|
|
46
|
-
'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '',
|
|
47
|
-
}));
|
|
48
|
-
if (linkText !== undefined) {
|
|
49
|
-
const inner = new index_1.Token(linkText, config, accum, {
|
|
50
|
-
'Stage-5': ':', QuoteToken: ':', ConverterToken: ':',
|
|
51
|
-
});
|
|
52
|
-
inner.type = 'link-text';
|
|
53
|
-
inner.setAttribute('stage', constants_1.MAX_STAGE - 1);
|
|
54
|
-
this.insertAt(inner);
|
|
55
|
-
}
|
|
56
|
-
this.#delimiter = delimiter;
|
|
57
|
-
this.protectChildren(0);
|
|
58
|
-
}
|
|
59
|
-
/** @private */
|
|
60
|
-
afterBuild() {
|
|
61
|
-
this.#title = this.getTitle();
|
|
62
|
-
this.setAttribute('name', this.#title.title);
|
|
63
|
-
if (this.#delimiter.includes('\0')) {
|
|
64
|
-
this.#delimiter = this.buildFromStr(this.#delimiter, 'string');
|
|
65
|
-
}
|
|
66
|
-
const /** @implements */ linkListener = (e, data) => {
|
|
67
|
-
const { prevTarget } = e;
|
|
68
|
-
if (prevTarget?.type === 'link-target') {
|
|
69
|
-
const name = prevTarget.text(), titleObj = this.getTitle(), { title, interwiki, ns, valid } = titleObj;
|
|
70
|
-
if (!valid) {
|
|
71
|
-
(0, debug_1.undo)(e, data);
|
|
72
|
-
throw new Error(`非法的内链目标:${name}`);
|
|
73
|
-
}
|
|
74
|
-
else if (this.type === 'category' && (interwiki || ns !== 14)
|
|
75
|
-
|| this.type === 'file' && (interwiki || ns !== 6)) {
|
|
76
|
-
(0, debug_1.undo)(e, data);
|
|
77
|
-
throw new Error(`${this.type === 'file' ? '文件' : '分类'}链接不可更改命名空间:${name}`);
|
|
78
|
-
}
|
|
79
|
-
else if (this.type === 'link'
|
|
80
|
-
&& !interwiki
|
|
81
|
-
&& (ns === 6 || ns === 14)
|
|
82
|
-
&& !name.trim().startsWith(':')) {
|
|
83
|
-
const { firstChild } = prevTarget;
|
|
84
|
-
if (firstChild?.type === 'text') {
|
|
85
|
-
firstChild.insertData(0, ':');
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
prevTarget.prepend(':');
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
this.#title = titleObj;
|
|
92
|
-
this.setAttribute('name', title);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
this.addEventListener(['remove', 'insert', 'replace', 'text'], linkListener);
|
|
96
|
-
}
|
|
97
|
-
/** @private */
|
|
98
|
-
setAttribute(key, value) {
|
|
99
|
-
if (key === 'bracket') {
|
|
100
|
-
this.#bracket = Boolean(value);
|
|
101
|
-
}
|
|
102
|
-
else if (key === 'title') {
|
|
103
|
-
this.#title = value;
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
super.setAttribute(key, value);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
/** @private */
|
|
110
|
-
toString(omit) {
|
|
111
|
-
const str = super.toString(omit, this.#delimiter);
|
|
112
|
-
return this.#bracket
|
|
113
|
-
&& !(omit && this.matchesTypes(omit))
|
|
114
|
-
? `[[${str}]]`
|
|
115
|
-
: str;
|
|
116
|
-
}
|
|
117
|
-
/** @override */
|
|
118
|
-
text() {
|
|
119
|
-
const str = super.text('|');
|
|
120
|
-
return this.#bracket ? `[[${str}]]` : str;
|
|
121
|
-
}
|
|
122
|
-
/** @private */
|
|
123
|
-
getAttribute(key) {
|
|
124
|
-
if (key === 'title') {
|
|
125
|
-
return this.#title;
|
|
126
|
-
}
|
|
127
|
-
return key === 'padding' ? 2 : super.getAttribute(key);
|
|
128
|
-
}
|
|
129
|
-
/** @private */
|
|
130
|
-
getGaps(i) {
|
|
131
|
-
return i === 0 ? this.#delimiter.length : 1;
|
|
132
|
-
}
|
|
133
|
-
/** @override */
|
|
134
|
-
lint(start = this.getAbsoluteIndex()) {
|
|
135
|
-
const errors = super.lint(start), { childNodes: [target, linkText], type: linkType } = this, { encoded, fragment } = this.#title;
|
|
136
|
-
let rect;
|
|
137
|
-
if (linkType === 'link' && target.childNodes.some(({ type }) => type === 'template')) {
|
|
138
|
-
rect = { start, ...this.getRootNode().posFromIndex(start) };
|
|
139
|
-
errors.push((0, lint_1.generateForChild)(target, rect, 'template in an internal link target', 'warning'));
|
|
140
|
-
}
|
|
141
|
-
if (encoded) {
|
|
142
|
-
rect ??= { start, ...this.getRootNode().posFromIndex(start) };
|
|
143
|
-
errors.push((0, lint_1.generateForChild)(target, rect, 'unnecessary URL encoding in an internal link'));
|
|
144
|
-
}
|
|
145
|
-
if (linkType === 'link' && linkText?.childNodes.some(({ type, data }) => type === 'text' && data.includes('|'))) {
|
|
146
|
-
rect ??= { start, ...this.getRootNode().posFromIndex(start) };
|
|
147
|
-
errors.push((0, lint_1.generateForChild)(linkText, rect, 'additional "|" in the link text', 'warning'));
|
|
148
|
-
}
|
|
149
|
-
else if (linkType !== 'link' && fragment !== undefined) {
|
|
150
|
-
rect ??= { start, ...this.getRootNode().posFromIndex(start) };
|
|
151
|
-
errors.push((0, lint_1.generateForChild)(target, rect, 'useless fragment'));
|
|
152
|
-
}
|
|
153
|
-
return errors;
|
|
154
|
-
}
|
|
155
|
-
/** @private */
|
|
156
|
-
getTitle() {
|
|
157
|
-
return this.normalizeTitle(this.firstChild.text(), 0, false, true, true);
|
|
158
|
-
}
|
|
159
|
-
/** @override */
|
|
160
|
-
print() {
|
|
161
|
-
return super.print(this.#bracket ? { pre: '[[', post: ']]', sep: this.#delimiter } : { sep: this.#delimiter });
|
|
162
|
-
}
|
|
163
|
-
/* NOT FOR BROWSER */
|
|
164
|
-
/** @override */
|
|
165
|
-
cloneNode() {
|
|
166
|
-
const [link, ...linkText] = this.cloneChildNodes();
|
|
167
|
-
return debug_1.Shadow.run(() => {
|
|
168
|
-
const token = new this.constructor('', undefined, this.getAttribute('config'));
|
|
169
|
-
token.firstChild.safeReplaceWith(link);
|
|
170
|
-
token.append(...linkText);
|
|
171
|
-
token.afterBuild();
|
|
172
|
-
return token;
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* 设置链接目标
|
|
177
|
-
* @param link 链接目标
|
|
178
|
-
*/
|
|
179
|
-
setTarget(link) {
|
|
180
|
-
const config = this.getAttribute('config'), { childNodes } = Parser.parse(String(link), this.getAttribute('include'), 2, config), token = debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'link-target', config, [], {
|
|
181
|
-
'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '',
|
|
182
|
-
}));
|
|
183
|
-
token.append(...childNodes);
|
|
184
|
-
this.firstChild.safeReplaceWith(token);
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* 设置链接显示文字
|
|
188
|
-
* @param linkStr 链接显示文字
|
|
189
|
-
*/
|
|
190
|
-
setLinkText(linkStr) {
|
|
191
|
-
if (linkStr === undefined) {
|
|
192
|
-
this.childNodes[1]?.remove();
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
const root = Parser.parse(linkStr, this.getAttribute('include'), undefined, this.getAttribute('config'));
|
|
196
|
-
if (this.length === 1) {
|
|
197
|
-
root.type = 'link-text';
|
|
198
|
-
root.setAttribute('acceptable', {
|
|
199
|
-
'Stage-5': ':', QuoteToken: ':', ConverterToken: ':',
|
|
200
|
-
});
|
|
201
|
-
this.insertAt(root);
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
this.lastChild.replaceChildren(...root.childNodes);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
exports.LinkBaseToken = LinkBaseToken;
|
|
209
|
-
constants_1.classes['LinkBaseToken'] = __filename;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { LinkBaseToken } from './base';
|
|
2
|
-
/** 分类 */
|
|
3
|
-
export declare class CategoryToken extends LinkBaseToken {
|
|
4
|
-
readonly type = "category";
|
|
5
|
-
/** 分类排序关键字 */
|
|
6
|
-
get sortkey(): string | undefined;
|
|
7
|
-
set sortkey(text: string | undefined);
|
|
8
|
-
/**
|
|
9
|
-
* 设置排序关键字
|
|
10
|
-
* @param text 排序关键字
|
|
11
|
-
*/
|
|
12
|
-
setSortkey(text?: string): void;
|
|
13
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CategoryToken = void 0;
|
|
4
|
-
const string_1 = require("../../util/string");
|
|
5
|
-
const constants_1 = require("../../util/constants");
|
|
6
|
-
const base_1 = require("./base");
|
|
7
|
-
/** 分类 */
|
|
8
|
-
// @ts-expect-error not implementing all abstract methods
|
|
9
|
-
class CategoryToken extends base_1.LinkBaseToken {
|
|
10
|
-
type = 'category';
|
|
11
|
-
/* NOT FOR BROWSER */
|
|
12
|
-
/** 分类排序关键字 */
|
|
13
|
-
get sortkey() {
|
|
14
|
-
const { childNodes: [, child] } = this;
|
|
15
|
-
return child && (0, string_1.decodeHtml)(child.text());
|
|
16
|
-
}
|
|
17
|
-
set sortkey(text) {
|
|
18
|
-
this.setSortkey(text);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* 设置排序关键字
|
|
22
|
-
* @param text 排序关键字
|
|
23
|
-
*/
|
|
24
|
-
setSortkey(text) {
|
|
25
|
-
this.setLinkText(text);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.CategoryToken = CategoryToken;
|
|
29
|
-
constants_1.classes['CategoryToken'] = __filename;
|
package/dist/src/link/file.d.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import * as Parser from '../../index';
|
|
2
|
-
import { LinkBaseToken } from './base';
|
|
3
|
-
import { ImageParameterToken } from '../imageParameter';
|
|
4
|
-
import type { Title } from '../../lib/title';
|
|
5
|
-
import type { LintError } from '../../base';
|
|
6
|
-
import type { Token, AtomToken } from '../../internal';
|
|
7
|
-
/**
|
|
8
|
-
* 图片
|
|
9
|
-
* @classdesc `{childNodes: [AtomToken, ...ImageParameterToken]}`
|
|
10
|
-
*/
|
|
11
|
-
export declare class FileToken extends LinkBaseToken {
|
|
12
|
-
#private;
|
|
13
|
-
readonly type: 'file' | 'gallery-image' | 'imagemap-image';
|
|
14
|
-
readonly childNodes: [AtomToken, ...ImageParameterToken[]];
|
|
15
|
-
abstract get children(): [AtomToken, ...ImageParameterToken[]];
|
|
16
|
-
abstract get lastChild(): AtomToken | ImageParameterToken;
|
|
17
|
-
abstract get lastElementChild(): AtomToken | ImageParameterToken;
|
|
18
|
-
/** 图片链接 */
|
|
19
|
-
get link(): string | Title;
|
|
20
|
-
set link(value: string);
|
|
21
|
-
/** 图片大小 */
|
|
22
|
-
get size(): {
|
|
23
|
-
width: string;
|
|
24
|
-
height: string;
|
|
25
|
-
} | undefined;
|
|
26
|
-
set size(size: {
|
|
27
|
-
width: string;
|
|
28
|
-
height: string;
|
|
29
|
-
} | undefined);
|
|
30
|
-
/** 图片宽度 */
|
|
31
|
-
get width(): string | undefined;
|
|
32
|
-
set width(width: string | undefined);
|
|
33
|
-
/** 图片高度 */
|
|
34
|
-
get height(): string | undefined;
|
|
35
|
-
set height(height: string | undefined);
|
|
36
|
-
/**
|
|
37
|
-
* @param link 文件名
|
|
38
|
-
* @param text 图片参数
|
|
39
|
-
* @param delimiter `|`
|
|
40
|
-
*/
|
|
41
|
-
constructor(link: string, text?: string, config?: Parser.Config, accum?: Token[], delimiter?: string);
|
|
42
|
-
/** @override */
|
|
43
|
-
lint(start?: number): LintError[];
|
|
44
|
-
/** 获取所有图片参数节点 */
|
|
45
|
-
getAllArgs(): readonly ImageParameterToken[];
|
|
46
|
-
/**
|
|
47
|
-
* 获取指定图片参数
|
|
48
|
-
* @param key 参数名
|
|
49
|
-
*/
|
|
50
|
-
getArgs(key: string): readonly ImageParameterToken[];
|
|
51
|
-
/** 获取图片框架属性参数节点 */
|
|
52
|
-
getFrameArgs(): readonly ImageParameterToken[];
|
|
53
|
-
/** 获取图片水平对齐参数节点 */
|
|
54
|
-
getHorizAlignArgs(): readonly ImageParameterToken[];
|
|
55
|
-
/** 获取图片垂直对齐参数节点 */
|
|
56
|
-
getVertAlignArgs(): readonly ImageParameterToken[];
|
|
57
|
-
/**
|
|
58
|
-
* 获取生效的指定图片参数
|
|
59
|
-
* @param key 参数名
|
|
60
|
-
*/
|
|
61
|
-
getArg(key: string): ImageParameterToken | undefined;
|
|
62
|
-
/**
|
|
63
|
-
* 是否具有指定图片参数
|
|
64
|
-
* @param key 参数名
|
|
65
|
-
*/
|
|
66
|
-
hasArg(key: string): boolean;
|
|
67
|
-
/**
|
|
68
|
-
* 移除指定图片参数
|
|
69
|
-
* @param key 参数名
|
|
70
|
-
*/
|
|
71
|
-
removeArg(key: string): void;
|
|
72
|
-
/** 获取图片参数名 */
|
|
73
|
-
getKeys(): Set<string>;
|
|
74
|
-
/**
|
|
75
|
-
* 获取指定的图片参数值
|
|
76
|
-
* @param key 参数名
|
|
77
|
-
*/
|
|
78
|
-
getValues(key: string): readonly (string | true)[];
|
|
79
|
-
/**
|
|
80
|
-
* 获取生效的指定图片参数值
|
|
81
|
-
* @param key 参数名
|
|
82
|
-
*/
|
|
83
|
-
getValue(key: string): string | true | undefined;
|
|
84
|
-
/**
|
|
85
|
-
* 设置图片参数
|
|
86
|
-
* @param key 参数名
|
|
87
|
-
* @param value 参数值
|
|
88
|
-
* @throws `RangeError` 未定义的图片参数
|
|
89
|
-
*/
|
|
90
|
-
setValue(key: string, value?: string | boolean): void;
|
|
91
|
-
/**
|
|
92
|
-
* @override
|
|
93
|
-
* @throws `Error` 不适用于图片
|
|
94
|
-
*/
|
|
95
|
-
setLinkText(): never;
|
|
96
|
-
}
|
package/dist/src/link/file.js
DELETED
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FileToken = void 0;
|
|
4
|
-
const string_1 = require("../../util/string");
|
|
5
|
-
const lint_1 = require("../../util/lint");
|
|
6
|
-
const debug_1 = require("../../util/debug");
|
|
7
|
-
const constants_1 = require("../../util/constants");
|
|
8
|
-
const Parser = require("../../index");
|
|
9
|
-
const base_1 = require("./base");
|
|
10
|
-
const imageParameter_1 = require("../imageParameter");
|
|
11
|
-
const frame = new Set(['manualthumb', 'frameless', 'framed', 'thumbnail']), horizAlign = new Set(['left', 'right', 'center', 'none']), vertAlign = new Set(['baseline', 'sub', 'super', 'top', 'text-top', 'middle', 'bottom', 'text-bottom']);
|
|
12
|
-
/**
|
|
13
|
-
* a more sophisticated string-explode function
|
|
14
|
-
* @param start start syntax of a nested AST node
|
|
15
|
-
* @param end end syntax of a nested AST node
|
|
16
|
-
* @param separator syntax for explosion
|
|
17
|
-
* @param str string to be exploded
|
|
18
|
-
*/
|
|
19
|
-
const explode = (start, end, separator, str) => {
|
|
20
|
-
if (str === undefined) {
|
|
21
|
-
return [];
|
|
22
|
-
}
|
|
23
|
-
const regex = new RegExp(`${[start, end, separator].map(string_1.escapeRegExp).join('|')}`, 'gu'), exploded = [];
|
|
24
|
-
let mt = regex.exec(str), depth = 0, lastIndex = 0;
|
|
25
|
-
while (mt) {
|
|
26
|
-
const { 0: match, index } = mt;
|
|
27
|
-
if (match !== separator) {
|
|
28
|
-
depth += match === start ? 1 : -1;
|
|
29
|
-
}
|
|
30
|
-
else if (depth === 0) {
|
|
31
|
-
exploded.push(str.slice(lastIndex, index));
|
|
32
|
-
({ lastIndex } = regex);
|
|
33
|
-
}
|
|
34
|
-
mt = regex.exec(str);
|
|
35
|
-
}
|
|
36
|
-
exploded.push(str.slice(lastIndex));
|
|
37
|
-
return exploded;
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* 图片
|
|
41
|
-
* @classdesc `{childNodes: [AtomToken, ...ImageParameterToken]}`
|
|
42
|
-
*/
|
|
43
|
-
// @ts-expect-error not implementing all abstract methods
|
|
44
|
-
class FileToken extends base_1.LinkBaseToken {
|
|
45
|
-
type = 'file';
|
|
46
|
-
/* NOT FOR BROWSER */
|
|
47
|
-
/** 图片链接 */
|
|
48
|
-
get link() {
|
|
49
|
-
return this.getArg('link')?.link ?? super.link;
|
|
50
|
-
}
|
|
51
|
-
set link(value) {
|
|
52
|
-
this.setValue('link', value);
|
|
53
|
-
}
|
|
54
|
-
/** 图片大小 */
|
|
55
|
-
get size() {
|
|
56
|
-
return this.getArg('width')?.size;
|
|
57
|
-
}
|
|
58
|
-
set size(size) {
|
|
59
|
-
this.setValue('width', size && `${size.width}${size.height && 'x'}${size.height}`);
|
|
60
|
-
}
|
|
61
|
-
/** 图片宽度 */
|
|
62
|
-
get width() {
|
|
63
|
-
return this.size?.width;
|
|
64
|
-
}
|
|
65
|
-
set width(width) {
|
|
66
|
-
const arg = this.getArg('width');
|
|
67
|
-
if (arg) {
|
|
68
|
-
arg.width = width;
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
this.setValue('width', width);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
/** 图片高度 */
|
|
75
|
-
get height() {
|
|
76
|
-
return this.size?.height;
|
|
77
|
-
}
|
|
78
|
-
set height(height) {
|
|
79
|
-
const arg = this.getArg('width');
|
|
80
|
-
if (arg) {
|
|
81
|
-
arg.height = height;
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
this.setValue('width', height && `x${height}`);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
/* NOT FOR BROWSER END */
|
|
88
|
-
/**
|
|
89
|
-
* @param link 文件名
|
|
90
|
-
* @param text 图片参数
|
|
91
|
-
* @param delimiter `|`
|
|
92
|
-
*/
|
|
93
|
-
constructor(link, text, config = Parser.getConfig(), accum = [], delimiter = '|') {
|
|
94
|
-
super(link, undefined, config, accum, delimiter);
|
|
95
|
-
this.setAttribute('acceptable', { AtomToken: 0, ImageParameterToken: '1:' });
|
|
96
|
-
this.append(...explode('-{', '}-', '|', text).map(part => new imageParameter_1.ImageParameterToken(part, config, accum)));
|
|
97
|
-
}
|
|
98
|
-
/** @override */
|
|
99
|
-
lint(start = this.getAbsoluteIndex()) {
|
|
100
|
-
const errors = super.lint(start), args = this.getAllArgs().filter(({ childNodes }) => {
|
|
101
|
-
const visibleNodes = childNodes.filter(node => node.text().trim());
|
|
102
|
-
return visibleNodes.length !== 1 || visibleNodes[0].type !== 'arg';
|
|
103
|
-
}), keys = [...new Set(args.map(({ name }) => name))].filter(key => key !== 'invalid'), frameKeys = keys.filter(key => frame.has(key)), horizAlignKeys = keys.filter(key => horizAlign.has(key)), vertAlignKeys = keys.filter(key => vertAlign.has(key));
|
|
104
|
-
if (args.length === keys.length
|
|
105
|
-
&& frameKeys.length < 2
|
|
106
|
-
&& horizAlignKeys.length < 2
|
|
107
|
-
&& vertAlignKeys.length < 2) {
|
|
108
|
-
return errors;
|
|
109
|
-
}
|
|
110
|
-
const rect = { start, ...this.getRootNode().posFromIndex(start) };
|
|
111
|
-
/**
|
|
112
|
-
* 图片参数到语法错误的映射
|
|
113
|
-
* @param msg 消息键
|
|
114
|
-
* @param p1 替换$1
|
|
115
|
-
*/
|
|
116
|
-
const generate = (msg, p1) => (arg) => (0, lint_1.generateForChild)(arg, rect, Parser.msg(`${msg} image $1 parameter`, p1));
|
|
117
|
-
for (const key of keys) {
|
|
118
|
-
let relevantArgs = args.filter(({ name }) => name === key);
|
|
119
|
-
if (key === 'caption') {
|
|
120
|
-
relevantArgs = [...relevantArgs.slice(0, -1).filter(arg => arg.text()), ...relevantArgs.slice(-1)];
|
|
121
|
-
}
|
|
122
|
-
if (relevantArgs.length > 1) {
|
|
123
|
-
errors.push(...relevantArgs.map(generate('duplicated', key)));
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
if (frameKeys.length > 1) {
|
|
127
|
-
errors.push(...args.filter(({ name }) => frame.has(name)).map(generate('conflicting', 'frame')));
|
|
128
|
-
}
|
|
129
|
-
if (horizAlignKeys.length > 1) {
|
|
130
|
-
errors.push(...args.filter(({ name }) => horizAlign.has(name)).map(generate('conflicting', 'horizontal-alignment')));
|
|
131
|
-
}
|
|
132
|
-
if (vertAlignKeys.length > 1) {
|
|
133
|
-
errors.push(...args.filter(({ name }) => vertAlign.has(name)).map(generate('conflicting', 'vertical-alignment')));
|
|
134
|
-
}
|
|
135
|
-
return errors;
|
|
136
|
-
}
|
|
137
|
-
/** 获取所有图片参数节点 */
|
|
138
|
-
getAllArgs() {
|
|
139
|
-
return this.childNodes.slice(1);
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* 获取指定图片参数
|
|
143
|
-
* @param key 参数名
|
|
144
|
-
*/
|
|
145
|
-
getArgs(key) {
|
|
146
|
-
return this.getAllArgs().filter(({ name }) => key === name);
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* 获取特定类型的图片属性参数节点
|
|
150
|
-
* @param keys 接受的参数名
|
|
151
|
-
* @param type 类型名
|
|
152
|
-
*/
|
|
153
|
-
#getTypedArgs(keys, type) {
|
|
154
|
-
const args = this.getAllArgs().filter(({ name }) => keys.has(name));
|
|
155
|
-
if (args.length > 1) {
|
|
156
|
-
Parser.warn(`图片 ${this.name} 带有 ${args.length} 个${type}参数,只有最后 1 个 ${args[0].name} 会生效!`);
|
|
157
|
-
}
|
|
158
|
-
return args;
|
|
159
|
-
}
|
|
160
|
-
/** 获取图片框架属性参数节点 */
|
|
161
|
-
getFrameArgs() {
|
|
162
|
-
return this.#getTypedArgs(frame, '框架');
|
|
163
|
-
}
|
|
164
|
-
/** 获取图片水平对齐参数节点 */
|
|
165
|
-
getHorizAlignArgs() {
|
|
166
|
-
return this.#getTypedArgs(horizAlign, '水平对齐');
|
|
167
|
-
}
|
|
168
|
-
/** 获取图片垂直对齐参数节点 */
|
|
169
|
-
getVertAlignArgs() {
|
|
170
|
-
return this.#getTypedArgs(vertAlign, '垂直对齐');
|
|
171
|
-
}
|
|
172
|
-
/* NOT FOR BROWSER */
|
|
173
|
-
/**
|
|
174
|
-
* 获取生效的指定图片参数
|
|
175
|
-
* @param key 参数名
|
|
176
|
-
*/
|
|
177
|
-
getArg(key) {
|
|
178
|
-
return this.getArgs(key).at(-1);
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* 是否具有指定图片参数
|
|
182
|
-
* @param key 参数名
|
|
183
|
-
*/
|
|
184
|
-
hasArg(key) {
|
|
185
|
-
return this.getArgs(key).length > 0;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* 移除指定图片参数
|
|
189
|
-
* @param key 参数名
|
|
190
|
-
*/
|
|
191
|
-
removeArg(key) {
|
|
192
|
-
for (const token of this.getArgs(key)) {
|
|
193
|
-
this.removeChild(token);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
/** 获取图片参数名 */
|
|
197
|
-
getKeys() {
|
|
198
|
-
return new Set(this.getAllArgs().map(({ name }) => name));
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* 获取指定的图片参数值
|
|
202
|
-
* @param key 参数名
|
|
203
|
-
*/
|
|
204
|
-
getValues(key) {
|
|
205
|
-
return this.getArgs(key).map(token => token.getValue());
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* 获取生效的指定图片参数值
|
|
209
|
-
* @param key 参数名
|
|
210
|
-
*/
|
|
211
|
-
getValue(key) {
|
|
212
|
-
return this.getArg(key)?.getValue();
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* 设置图片参数
|
|
216
|
-
* @param key 参数名
|
|
217
|
-
* @param value 参数值
|
|
218
|
-
* @throws `RangeError` 未定义的图片参数
|
|
219
|
-
*/
|
|
220
|
-
setValue(key, value = false) {
|
|
221
|
-
if (value === false) {
|
|
222
|
-
this.removeArg(key);
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
const token = this.getArg(key);
|
|
226
|
-
if (token) {
|
|
227
|
-
token.setValue(value);
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
const config = this.getAttribute('config'), syntax = key === 'caption' ? '$1' : Object.entries(config.img).find(([, name]) => name === key)?.[0];
|
|
231
|
-
if (syntax === undefined) {
|
|
232
|
-
throw new RangeError(`未定义的图片参数: ${key}`);
|
|
233
|
-
}
|
|
234
|
-
const free = syntax.includes('$1');
|
|
235
|
-
if (value === true && free) {
|
|
236
|
-
this.typeError('setValue', 'Boolean');
|
|
237
|
-
}
|
|
238
|
-
const parameter = debug_1.Shadow.run(() => new imageParameter_1.ImageParameterToken(syntax.replace('$1', ''), config));
|
|
239
|
-
if (free) {
|
|
240
|
-
const { childNodes } = Parser.parse(value, this.getAttribute('include'), undefined, config);
|
|
241
|
-
parameter.replaceChildren(...childNodes);
|
|
242
|
-
}
|
|
243
|
-
parameter.afterBuild();
|
|
244
|
-
this.insertAt(parameter);
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* @override
|
|
248
|
-
* @throws `Error` 不适用于图片
|
|
249
|
-
*/
|
|
250
|
-
setLinkText() {
|
|
251
|
-
throw new Error(`${this.constructor.name}.setLinkText 方法不适用于图片!`);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
exports.FileToken = FileToken;
|
|
255
|
-
constants_1.classes['FileToken'] = __filename;
|