wikiparser-node 1.13.0-b → 1.13.0
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 +32 -31
- package/config/enwiki.json +829 -15
- package/config/llwiki.json +56 -21
- package/config/moegirl.json +65 -21
- package/config/zhwiki.json +498 -32
- 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 +109 -0
- package/dist/base.js +67 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +279 -0
- package/dist/internal.d.ts +47 -0
- package/dist/lib/element.d.ts +125 -0
- package/dist/lib/element.js +364 -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 +251 -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 +443 -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 +383 -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 -53
- 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,52 @@
|
|
|
1
|
+
import 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
|
+
readonly name: string;
|
|
13
|
+
abstract get type(): 'link' | 'category' | 'file' | 'gallery-image' | 'imagemap-image' | 'redirect-target';
|
|
14
|
+
readonly childNodes: readonly [AtomToken, ...Token[]];
|
|
15
|
+
abstract get firstChild(): AtomToken;
|
|
16
|
+
abstract get lastChild(): Token;
|
|
17
|
+
abstract get children(): [AtomToken, ...Token[]];
|
|
18
|
+
abstract get firstElementChild(): AtomToken;
|
|
19
|
+
abstract get lastElementChild(): Token;
|
|
20
|
+
/** 完整链接 */
|
|
21
|
+
get link(): string | Title;
|
|
22
|
+
set link(link: string);
|
|
23
|
+
/** 片段标识符 */
|
|
24
|
+
get fragment(): string | undefined;
|
|
25
|
+
set fragment(fragment: string | undefined);
|
|
26
|
+
/** interwiki */
|
|
27
|
+
get interwiki(): string;
|
|
28
|
+
/** @throws `RangeError` 非法的跨维基前缀 */
|
|
29
|
+
set interwiki(interwiki: string);
|
|
30
|
+
/**
|
|
31
|
+
* @param link 链接标题
|
|
32
|
+
* @param linkText 链接显示文字
|
|
33
|
+
* @param delimiter `|`
|
|
34
|
+
*/
|
|
35
|
+
constructor(link: string, linkText?: string, config?: Parser.Config, accum?: Token[], delimiter?: string);
|
|
36
|
+
cloneNode(): this;
|
|
37
|
+
/**
|
|
38
|
+
* 设置链接目标
|
|
39
|
+
* @param link 链接目标
|
|
40
|
+
*/
|
|
41
|
+
setTarget(link: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* 设置片段标识符
|
|
44
|
+
* @param fragment 片段标识符
|
|
45
|
+
*/
|
|
46
|
+
setFragment(fragment?: string): void;
|
|
47
|
+
/**
|
|
48
|
+
* 设置链接显示文字
|
|
49
|
+
* @param linkStr 链接显示文字
|
|
50
|
+
*/
|
|
51
|
+
setLinkText(linkStr?: string): void;
|
|
52
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LinkBaseToken = void 0;
|
|
4
|
+
const lint_1 = require("../../util/lint");
|
|
5
|
+
const constants_1 = require("../../util/constants");
|
|
6
|
+
const rect_1 = require("../../lib/rect");
|
|
7
|
+
const index_1 = require("../../index");
|
|
8
|
+
const index_2 = require("../index");
|
|
9
|
+
const atom_1 = require("../atom");
|
|
10
|
+
/* NOT FOR BROWSER */
|
|
11
|
+
const debug_1 = require("../../util/debug");
|
|
12
|
+
const string_1 = require("../../util/string");
|
|
13
|
+
const html_1 = require("../../util/html");
|
|
14
|
+
/* NOT FOR BROWSER END */
|
|
15
|
+
/**
|
|
16
|
+
* 是否为普通内链
|
|
17
|
+
* @param type 节点类型
|
|
18
|
+
*/
|
|
19
|
+
const isLink = (type) => type === 'redirect-target' || type === 'link';
|
|
20
|
+
/**
|
|
21
|
+
* 内链
|
|
22
|
+
* @classdesc `{childNodes: [AtomToken, ...Token]}`
|
|
23
|
+
*/
|
|
24
|
+
class LinkBaseToken extends index_2.Token {
|
|
25
|
+
#bracket = true;
|
|
26
|
+
#delimiter;
|
|
27
|
+
#title;
|
|
28
|
+
/** 完整链接 */
|
|
29
|
+
get link() {
|
|
30
|
+
return this.#title;
|
|
31
|
+
}
|
|
32
|
+
set link(link) {
|
|
33
|
+
this.setTarget(link);
|
|
34
|
+
}
|
|
35
|
+
/** 片段标识符 */
|
|
36
|
+
get fragment() {
|
|
37
|
+
return this.#title.fragment;
|
|
38
|
+
}
|
|
39
|
+
set fragment(fragment) {
|
|
40
|
+
this.setFragment(fragment);
|
|
41
|
+
}
|
|
42
|
+
/** interwiki */
|
|
43
|
+
get interwiki() {
|
|
44
|
+
return this.#title.interwiki;
|
|
45
|
+
}
|
|
46
|
+
/** @throws `RangeError` 非法的跨维基前缀 */
|
|
47
|
+
set interwiki(interwiki) {
|
|
48
|
+
if (isLink(this.type)) {
|
|
49
|
+
const { prefix, main, fragment } = this.#title, link = `${interwiki}:${prefix}${main}${fragment === undefined ? '' : `#${fragment}`}`;
|
|
50
|
+
if (interwiki && !this.isInterwiki(link)) {
|
|
51
|
+
throw new RangeError(`${interwiki} is not a valid interwiki prefix!`);
|
|
52
|
+
}
|
|
53
|
+
this.setTarget(link);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/* NOT FOR BROWSER END */
|
|
57
|
+
/**
|
|
58
|
+
* @param link 链接标题
|
|
59
|
+
* @param linkText 链接显示文字
|
|
60
|
+
* @param delimiter `|`
|
|
61
|
+
*/
|
|
62
|
+
constructor(link, linkText, config = index_1.default.getConfig(), accum = [], delimiter = '|') {
|
|
63
|
+
super(undefined, config, accum, {
|
|
64
|
+
AtomToken: 0, Token: 1,
|
|
65
|
+
});
|
|
66
|
+
this.insertAt(new atom_1.AtomToken(link, 'link-target', config, accum, {
|
|
67
|
+
'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '',
|
|
68
|
+
}));
|
|
69
|
+
if (linkText !== undefined) {
|
|
70
|
+
const inner = new index_2.Token(linkText, config, accum, {
|
|
71
|
+
'Stage-5': ':', QuoteToken: ':', ConverterToken: ':',
|
|
72
|
+
});
|
|
73
|
+
inner.type = 'link-text';
|
|
74
|
+
inner.setAttribute('stage', constants_1.MAX_STAGE - 1);
|
|
75
|
+
this.insertAt(inner);
|
|
76
|
+
}
|
|
77
|
+
this.#delimiter = delimiter;
|
|
78
|
+
/* NOT FOR BROWSER */
|
|
79
|
+
this.protectChildren(0);
|
|
80
|
+
}
|
|
81
|
+
/** @private */
|
|
82
|
+
afterBuild() {
|
|
83
|
+
this.#title = this.getTitle();
|
|
84
|
+
if (this.#delimiter.includes('\0')) {
|
|
85
|
+
this.#delimiter = this.buildFromStr(this.#delimiter, constants_1.BuildMethod.String);
|
|
86
|
+
}
|
|
87
|
+
this.setAttribute('name', this.#title.title);
|
|
88
|
+
super.afterBuild();
|
|
89
|
+
/* NOT FOR BROWSER */
|
|
90
|
+
const /** @implements */ linkListener = (e, data) => {
|
|
91
|
+
const { prevTarget } = e, { type } = this;
|
|
92
|
+
if (prevTarget?.type === 'link-target') {
|
|
93
|
+
const name = prevTarget.toString(true), titleObj = this.getTitle(), { title, interwiki, ns, valid } = titleObj;
|
|
94
|
+
if (!valid) {
|
|
95
|
+
(0, debug_1.undo)(e, data);
|
|
96
|
+
throw new Error(`Invalid link target: ${name}`);
|
|
97
|
+
}
|
|
98
|
+
else if (type === 'category' && (interwiki || ns !== 14)
|
|
99
|
+
|| (type === 'file' || type === 'gallery-image' || type === 'imagemap-image')
|
|
100
|
+
&& (interwiki || ns !== 6)) {
|
|
101
|
+
(0, debug_1.undo)(e, data);
|
|
102
|
+
throw new Error(`${type === 'category' ? 'Category' : 'File'} link cannot change namespace: ${name}`);
|
|
103
|
+
}
|
|
104
|
+
else if (type === 'link' && !interwiki && (ns === 6 || ns === 14) && !name.trim().startsWith(':')) {
|
|
105
|
+
const { firstChild } = prevTarget;
|
|
106
|
+
if (firstChild?.type === 'text') {
|
|
107
|
+
firstChild.insertData(0, ':');
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
prevTarget.prepend(':');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
this.#title = titleObj;
|
|
114
|
+
this.setAttribute('name', title);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
this.addEventListener(['remove', 'insert', 'replace', 'text'], linkListener);
|
|
118
|
+
}
|
|
119
|
+
/** @private */
|
|
120
|
+
setAttribute(key, value) {
|
|
121
|
+
if (key === 'bracket') {
|
|
122
|
+
this.#bracket = value;
|
|
123
|
+
}
|
|
124
|
+
else if (key === 'title') {
|
|
125
|
+
this.#title = value;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
super.setAttribute(key, value);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/** @private */
|
|
132
|
+
toString(skip) {
|
|
133
|
+
const str = super.toString(skip, this.#delimiter);
|
|
134
|
+
return this.#bracket ? `[[${str}]]` : str;
|
|
135
|
+
}
|
|
136
|
+
/** @private */
|
|
137
|
+
text() {
|
|
138
|
+
const str = super.text('|');
|
|
139
|
+
return this.#bracket ? `[[${str}]]` : str;
|
|
140
|
+
}
|
|
141
|
+
/** @private */
|
|
142
|
+
getAttribute(key) {
|
|
143
|
+
if (key === 'title') {
|
|
144
|
+
return this.#title;
|
|
145
|
+
}
|
|
146
|
+
return key === 'padding' ? 2 : super.getAttribute(key);
|
|
147
|
+
}
|
|
148
|
+
/** @private */
|
|
149
|
+
getGaps(i) {
|
|
150
|
+
return i === 0 ? this.#delimiter.length : 1;
|
|
151
|
+
}
|
|
152
|
+
/** @private */
|
|
153
|
+
lint(start = this.getAbsoluteIndex(), re) {
|
|
154
|
+
const errors = super.lint(start, re), { childNodes: [target, linkText], type } = this, { encoded, fragment } = this.#title, rect = new rect_1.BoundingRect(this, start);
|
|
155
|
+
if (target.childNodes.some(({ type: t }) => t === 'template')) {
|
|
156
|
+
errors.push((0, lint_1.generateForChild)(target, rect, 'unknown-page', 'template in an internal link target', 'warning'));
|
|
157
|
+
}
|
|
158
|
+
if (encoded) {
|
|
159
|
+
errors.push((0, lint_1.generateForChild)(target, rect, 'url-encoding', 'unnecessary URL encoding in an internal link'));
|
|
160
|
+
}
|
|
161
|
+
if (type === 'link' || type === 'category') {
|
|
162
|
+
const textNode = linkText?.childNodes.find((c) => c.type === 'text' && c.data.includes('|'));
|
|
163
|
+
if (textNode) {
|
|
164
|
+
const e = (0, lint_1.generateForChild)(linkText, rect, 'pipe-like', 'additional "|" in the link text', 'warning'), i = e.startIndex + textNode.getRelativeIndex();
|
|
165
|
+
e.suggestions = [
|
|
166
|
+
{
|
|
167
|
+
desc: 'escape',
|
|
168
|
+
range: [i, i + textNode.data.length],
|
|
169
|
+
text: textNode.data.replace(/\|/gu, '|'),
|
|
170
|
+
},
|
|
171
|
+
];
|
|
172
|
+
errors.push(e);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (fragment !== undefined && !isLink(type)) {
|
|
176
|
+
const e = (0, lint_1.generateForChild)(target, rect, 'no-ignored', 'useless fragment'), textNode = target.childNodes.find((c) => c.type === 'text' && c.data.includes('#'));
|
|
177
|
+
if (textNode) {
|
|
178
|
+
e.fix = {
|
|
179
|
+
range: [e.startIndex + textNode.getRelativeIndex() + textNode.data.indexOf('#'), e.endIndex],
|
|
180
|
+
text: '',
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
errors.push(e);
|
|
184
|
+
}
|
|
185
|
+
return errors;
|
|
186
|
+
}
|
|
187
|
+
/** @private */
|
|
188
|
+
getTitle(halfParsed) {
|
|
189
|
+
return this.normalizeTitle(this.firstChild.toString(true), 0, halfParsed, true, true);
|
|
190
|
+
}
|
|
191
|
+
/** @private */
|
|
192
|
+
print() {
|
|
193
|
+
return super.print(this.#bracket ? { pre: '[[', post: ']]', sep: this.#delimiter } : { sep: this.#delimiter });
|
|
194
|
+
}
|
|
195
|
+
/* NOT FOR BROWSER */
|
|
196
|
+
cloneNode() {
|
|
197
|
+
const [link, ...linkText] = this.cloneChildNodes();
|
|
198
|
+
return debug_1.Shadow.run(() => {
|
|
199
|
+
const C = this.constructor, token = new C('', undefined, this.getAttribute('config'));
|
|
200
|
+
token.firstChild.safeReplaceWith(link);
|
|
201
|
+
token.append(...linkText);
|
|
202
|
+
return token;
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* 设置链接目标
|
|
207
|
+
* @param link 链接目标
|
|
208
|
+
*/
|
|
209
|
+
setTarget(link) {
|
|
210
|
+
const config = this.getAttribute('config'), { childNodes } = index_1.default.parse(link, this.getAttribute('include'), 2, config), token = debug_1.Shadow.run(() => new atom_1.AtomToken(undefined, 'link-target', config, [], {
|
|
211
|
+
'Stage-2': ':', '!ExtToken': '', '!HeadingToken': '',
|
|
212
|
+
}));
|
|
213
|
+
token.append(...childNodes);
|
|
214
|
+
this.firstChild.safeReplaceWith(token);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* 设置片段标识符
|
|
218
|
+
* @param fragment 片段标识符
|
|
219
|
+
*/
|
|
220
|
+
setFragment(fragment) {
|
|
221
|
+
const { type, name } = this;
|
|
222
|
+
if (fragment === undefined || isLink(type)) {
|
|
223
|
+
fragment &&= (0, string_1.encode)(fragment);
|
|
224
|
+
this.setTarget(`${name}${fragment === undefined ? '' : `#${fragment}`}`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* 设置链接显示文字
|
|
229
|
+
* @param linkStr 链接显示文字
|
|
230
|
+
*/
|
|
231
|
+
setLinkText(linkStr) {
|
|
232
|
+
if (linkStr === undefined) {
|
|
233
|
+
this.childNodes[1]?.remove();
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const root = index_1.default.parse(linkStr, this.getAttribute('include'), undefined, this.getAttribute('config'));
|
|
237
|
+
if (this.length === 1) {
|
|
238
|
+
root.type = 'link-text';
|
|
239
|
+
root.setAttribute('acceptable', {
|
|
240
|
+
'Stage-5': ':', QuoteToken: ':', ConverterToken: ':',
|
|
241
|
+
});
|
|
242
|
+
this.insertAt(root);
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
this.lastChild.replaceChildren(...root.childNodes);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/** @private */
|
|
249
|
+
toHtmlInternal(_, nocc) {
|
|
250
|
+
if (this.is('link') || this.is('redirect-target')) {
|
|
251
|
+
const { link, length, lastChild, type } = this, title = link.getTitleAttr();
|
|
252
|
+
return (0, html_1.font)(this, `<a${link.interwiki && ' class="extiw"'} href="${link.getUrl()}"${title && ` title="${title}"`}>${type === 'link' && length > 1 ? lastChild.toHtmlInternal(true, nocc) : (0, string_1.sanitize)(this.innerText)}</a>`);
|
|
253
|
+
}
|
|
254
|
+
return '';
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
exports.LinkBaseToken = LinkBaseToken;
|
|
258
|
+
constants_1.classes['LinkBaseToken'] = __filename;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { LinkBaseToken } from './base';
|
|
2
|
+
import type { Token, AtomToken } from '../../internal';
|
|
3
|
+
import type { Title } from '../../lib/title';
|
|
4
|
+
/**
|
|
5
|
+
* 分类
|
|
6
|
+
* @classdesc `{childNodes: [AtomToken, ?Token]}`
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class CategoryToken extends LinkBaseToken {
|
|
9
|
+
readonly childNodes: readonly [AtomToken] | readonly [AtomToken, Token];
|
|
10
|
+
abstract get children(): [AtomToken] | [AtomToken, Token];
|
|
11
|
+
abstract get link(): Title;
|
|
12
|
+
abstract set link(link: string);
|
|
13
|
+
get type(): 'category';
|
|
14
|
+
/** 分类排序关键字 */
|
|
15
|
+
get sortkey(): string | undefined;
|
|
16
|
+
set sortkey(text: string | undefined);
|
|
17
|
+
/**
|
|
18
|
+
* 设置排序关键字
|
|
19
|
+
* @param text 排序关键字
|
|
20
|
+
*/
|
|
21
|
+
setSortkey(text?: string): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CategoryToken = void 0;
|
|
4
|
+
const base_1 = require("./base");
|
|
5
|
+
/* NOT FOR BROWSER */
|
|
6
|
+
const string_1 = require("../../util/string");
|
|
7
|
+
const constants_1 = require("../../util/constants");
|
|
8
|
+
/* NOT FOR BROWSER END */
|
|
9
|
+
/**
|
|
10
|
+
* 分类
|
|
11
|
+
* @classdesc `{childNodes: [AtomToken, ?Token]}`
|
|
12
|
+
*/
|
|
13
|
+
class CategoryToken extends base_1.LinkBaseToken {
|
|
14
|
+
/* NOT FOR BROWSER END */
|
|
15
|
+
get type() {
|
|
16
|
+
return 'category';
|
|
17
|
+
}
|
|
18
|
+
/* NOT FOR BROWSER */
|
|
19
|
+
/** 分类排序关键字 */
|
|
20
|
+
get sortkey() {
|
|
21
|
+
const { childNodes: [, child] } = this;
|
|
22
|
+
return child && (0, string_1.decodeHtml)(child.text());
|
|
23
|
+
}
|
|
24
|
+
set sortkey(text) {
|
|
25
|
+
this.setSortkey(text);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 设置排序关键字
|
|
29
|
+
* @param text 排序关键字
|
|
30
|
+
*/
|
|
31
|
+
setSortkey(text) {
|
|
32
|
+
this.setLinkText(text);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.CategoryToken = CategoryToken;
|
|
36
|
+
constants_1.classes['CategoryToken'] = __filename;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import Parser from '../../index';
|
|
2
|
+
import { LinkBaseToken } from './base';
|
|
3
|
+
import { ImageParameterToken } from '../imageParameter';
|
|
4
|
+
import type { LintError } from '../../base';
|
|
5
|
+
import type { Token, AtomToken } from '../../internal';
|
|
6
|
+
import { Title } from '../../lib/title';
|
|
7
|
+
/**
|
|
8
|
+
* 图片
|
|
9
|
+
* @classdesc `{childNodes: [AtomToken, ...ImageParameterToken]}`
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class FileToken extends LinkBaseToken {
|
|
12
|
+
#private;
|
|
13
|
+
readonly childNodes: readonly [AtomToken, ...ImageParameterToken[]];
|
|
14
|
+
abstract get lastChild(): AtomToken | ImageParameterToken;
|
|
15
|
+
abstract get children(): [AtomToken, ...ImageParameterToken[]];
|
|
16
|
+
abstract get lastElementChild(): AtomToken | ImageParameterToken;
|
|
17
|
+
get type(): 'file' | 'gallery-image' | 'imagemap-image';
|
|
18
|
+
/** 扩展名 */
|
|
19
|
+
get extension(): string | undefined;
|
|
20
|
+
/** 图片链接 */
|
|
21
|
+
get link(): string | Title;
|
|
22
|
+
set link(value: string);
|
|
23
|
+
/** 图片大小 */
|
|
24
|
+
get size(): {
|
|
25
|
+
width: string;
|
|
26
|
+
height: string;
|
|
27
|
+
} | undefined;
|
|
28
|
+
set size(size: {
|
|
29
|
+
width: string;
|
|
30
|
+
height: string;
|
|
31
|
+
} | undefined);
|
|
32
|
+
/** 图片宽度 */
|
|
33
|
+
get width(): string | undefined;
|
|
34
|
+
set width(width: string | undefined);
|
|
35
|
+
/** 图片高度 */
|
|
36
|
+
get height(): string | undefined;
|
|
37
|
+
set height(height: string | undefined);
|
|
38
|
+
/**
|
|
39
|
+
* @param link 文件名
|
|
40
|
+
* @param text 图片参数
|
|
41
|
+
* @param delimiter `|`
|
|
42
|
+
*/
|
|
43
|
+
constructor(link: string, text?: string, config?: Parser.Config, accum?: Token[], delimiter?: string);
|
|
44
|
+
/** 获取所有图片参数节点 */
|
|
45
|
+
getAllArgs(): ImageParameterToken[];
|
|
46
|
+
/**
|
|
47
|
+
* 获取指定图片参数
|
|
48
|
+
* @param key 参数名
|
|
49
|
+
*/
|
|
50
|
+
getArgs(key: string): ImageParameterToken[];
|
|
51
|
+
/**
|
|
52
|
+
* 获取生效的指定图片参数
|
|
53
|
+
* @param key 参数名
|
|
54
|
+
*/
|
|
55
|
+
getArg(key: string): ImageParameterToken | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* 获取生效的指定图片参数值
|
|
58
|
+
* @param key 参数名
|
|
59
|
+
*/
|
|
60
|
+
getValue(key: string): string | true | undefined;
|
|
61
|
+
/** 获取图片框架属性参数节点 */
|
|
62
|
+
getFrameArgs(): ImageParameterToken[];
|
|
63
|
+
/** 获取图片水平对齐参数节点 */
|
|
64
|
+
getHorizAlignArgs(): ImageParameterToken[];
|
|
65
|
+
/** 获取图片垂直对齐参数节点 */
|
|
66
|
+
getVertAlignArgs(): ImageParameterToken[];
|
|
67
|
+
/** 获取生效的图片框架属性参数 */
|
|
68
|
+
getFrame(): string | Title | undefined;
|
|
69
|
+
/** 获取生效的图片水平对齐参数 */
|
|
70
|
+
getHorizAlign(): string | undefined;
|
|
71
|
+
/** 获取生效的图片垂直对齐参数 */
|
|
72
|
+
getVertAlign(): string | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* 是否具有指定图片参数
|
|
75
|
+
* @param key 参数名
|
|
76
|
+
*/
|
|
77
|
+
hasArg(key: string): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* 移除指定图片参数
|
|
80
|
+
* @param key 参数名
|
|
81
|
+
*/
|
|
82
|
+
removeArg(key: string): void;
|
|
83
|
+
/** 获取图片参数名 */
|
|
84
|
+
getKeys(): Set<string>;
|
|
85
|
+
/**
|
|
86
|
+
* 获取指定的图片参数值
|
|
87
|
+
* @param key 参数名
|
|
88
|
+
*/
|
|
89
|
+
getValues(key: string): (string | true)[];
|
|
90
|
+
/**
|
|
91
|
+
* 设置图片参数
|
|
92
|
+
* @param key 参数名
|
|
93
|
+
* @param value 参数值
|
|
94
|
+
* @throws `RangeError` 未定义的图片参数
|
|
95
|
+
*/
|
|
96
|
+
setValue(key: string, value?: string | boolean): void;
|
|
97
|
+
/**
|
|
98
|
+
* @override
|
|
99
|
+
* @throws `Error` 不适用于图片
|
|
100
|
+
*/
|
|
101
|
+
setLinkText(): never;
|
|
102
|
+
}
|