wikiparser-node 1.5.4 → 1.5.5
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/dist/lib/element.js +7 -6
- package/dist/lib/node.js +1 -3
- package/dist/src/heading.js +1 -1
- package/dist/src/imagemap.d.ts +0 -2
- package/dist/src/imagemap.js +0 -6
- package/dist/src/index.d.ts +2 -2
- package/dist/src/link/index.js +1 -1
- package/dist/src/nowiki/list.js +14 -2
- package/dist/src/table/td.js +2 -2
- package/package.json +1 -1
package/dist/lib/element.js
CHANGED
|
@@ -33,6 +33,7 @@ const matchesLang = ({ attributes }, regex) => {
|
|
|
33
33
|
const lang = attributes?.['lang'];
|
|
34
34
|
return typeof lang === 'string' && regex.test(lang);
|
|
35
35
|
};
|
|
36
|
+
const primitives = new Set(['string', 'number', 'boolean', 'undefined']);
|
|
36
37
|
/* NOT FOR BROWSER END */
|
|
37
38
|
/** 类似HTMLElement */
|
|
38
39
|
class AstElement extends node_1.AstNode {
|
|
@@ -316,9 +317,6 @@ class AstElement extends node_1.AstNode {
|
|
|
316
317
|
if (!(key in this) && (!isAttr || !this.hasAttr(key))) {
|
|
317
318
|
return equal === '!=';
|
|
318
319
|
}
|
|
319
|
-
else if (!equal) {
|
|
320
|
-
return true;
|
|
321
|
-
}
|
|
322
320
|
const v = toCase(val, i);
|
|
323
321
|
let thisVal = this.getAttribute(key);
|
|
324
322
|
if (isAttr) {
|
|
@@ -327,7 +325,10 @@ class AstElement extends node_1.AstNode {
|
|
|
327
325
|
thisVal = attr === true ? '' : attr;
|
|
328
326
|
}
|
|
329
327
|
}
|
|
330
|
-
if (
|
|
328
|
+
if (!equal) {
|
|
329
|
+
return thisVal !== undefined && thisVal !== false;
|
|
330
|
+
}
|
|
331
|
+
else if (thisVal instanceof RegExp) {
|
|
331
332
|
thisVal = thisVal.source;
|
|
332
333
|
}
|
|
333
334
|
if (equal === '~=') {
|
|
@@ -335,10 +336,10 @@ class AstElement extends node_1.AstNode {
|
|
|
335
336
|
return Boolean(thisVals?.[Symbol.iterator])
|
|
336
337
|
&& [...thisVals].some(w => typeof w === 'string' && toCase(w, i) === v);
|
|
337
338
|
}
|
|
338
|
-
else if (typeof thisVal
|
|
339
|
+
else if (!primitives.has(typeof thisVal) && !(thisVal instanceof title_1.Title)) {
|
|
339
340
|
throw new RangeError(`复杂属性 ${key} 不能用于选择器!`);
|
|
340
341
|
}
|
|
341
|
-
const stringVal = toCase(thisVal, i);
|
|
342
|
+
const stringVal = toCase(String(thisVal), i);
|
|
342
343
|
switch (equal) {
|
|
343
344
|
case '|=':
|
|
344
345
|
return stringVal === v || stringVal.startsWith(`${v}-`);
|
package/dist/lib/node.js
CHANGED
package/dist/src/heading.js
CHANGED
package/dist/src/imagemap.d.ts
CHANGED
|
@@ -26,8 +26,6 @@ export declare abstract class ImagemapToken extends Token {
|
|
|
26
26
|
abstract get parentElement(): ExtToken | undefined;
|
|
27
27
|
/** 图片 */
|
|
28
28
|
get image(): GalleryImageToken | undefined;
|
|
29
|
-
/** 链接 */
|
|
30
|
-
get links(): ImagemapLinkToken[];
|
|
31
29
|
/** @param inner 标签内部wikitext */
|
|
32
30
|
constructor(inner?: string, config?: Parser.Config, accum?: Token[]);
|
|
33
31
|
/** @override */
|
package/dist/src/imagemap.js
CHANGED
|
@@ -21,12 +21,6 @@ class ImagemapToken extends index_2.Token {
|
|
|
21
21
|
get image() {
|
|
22
22
|
return this.childNodes.find((0, debug_1.isToken)('imagemap-image'));
|
|
23
23
|
}
|
|
24
|
-
/* NOT FOR BROWSER */
|
|
25
|
-
/** 链接 */
|
|
26
|
-
get links() {
|
|
27
|
-
return this.childNodes.filter((0, debug_1.isToken)('imagemap-link'));
|
|
28
|
-
}
|
|
29
|
-
/* NOT FOR BROWSER END */
|
|
30
24
|
/** @param inner 标签内部wikitext */
|
|
31
25
|
constructor(inner, config = index_1.default.getConfig(), accum = []) {
|
|
32
26
|
super(undefined, config, accum, {
|
package/dist/src/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { AstText } from '../lib/text';
|
|
|
6
6
|
import type { LintError } from '../base';
|
|
7
7
|
import type { Range } from '../lib/ranges';
|
|
8
8
|
import type { Title } from '../lib/title';
|
|
9
|
-
import type { AstNodes, IncludeToken, HtmlToken, ExtToken, TranscludeToken, CommentToken, FileToken, LinkToken, ExtLinkToken, MagicLinkToken, ImageParameterToken
|
|
9
|
+
import type { AstNodes, IncludeToken, HtmlToken, ExtToken, TranscludeToken, CommentToken, FileToken, LinkToken, ExtLinkToken, MagicLinkToken, ImageParameterToken } from '../internal';
|
|
10
10
|
import type { CaretPosition } from '../lib/node';
|
|
11
11
|
import type { TokenTypes } from '../util/constants';
|
|
12
12
|
declare type TagToken = IncludeToken | ExtToken | HtmlToken;
|
|
@@ -20,7 +20,7 @@ export declare class Token extends AstElement {
|
|
|
20
20
|
/** 所有图片,包括图库 */
|
|
21
21
|
get images(): FileToken[];
|
|
22
22
|
/** 所有内链、外链和自由外链 */
|
|
23
|
-
get links(): (LinkToken | ExtLinkToken | MagicLinkToken | ImageParameterToken
|
|
23
|
+
get links(): (LinkToken | ExtLinkToken | MagicLinkToken | ImageParameterToken)[];
|
|
24
24
|
/** 所有模板和模块 */
|
|
25
25
|
get embeds(): TranscludeToken[];
|
|
26
26
|
/** @class */
|
package/dist/src/link/index.js
CHANGED
|
@@ -12,7 +12,7 @@ class LinkToken extends base_1.LinkBaseToken {
|
|
|
12
12
|
type = 'link';
|
|
13
13
|
/** 链接显示文字 */
|
|
14
14
|
get innerText() {
|
|
15
|
-
return this.length > 1 ? this.lastChild.text() : this.firstChild.text().replace(/^\s
|
|
15
|
+
return this.length > 1 ? this.lastChild.text() : this.firstChild.text().replace(/^\s*:?/u, '');
|
|
16
16
|
}
|
|
17
17
|
set innerText(text) {
|
|
18
18
|
this.setLinkText(text);
|
package/dist/src/nowiki/list.js
CHANGED
|
@@ -75,14 +75,26 @@ let ListToken = (() => {
|
|
|
75
75
|
/** 获取列表行的范围 */
|
|
76
76
|
getRange() {
|
|
77
77
|
const range = this.createRange();
|
|
78
|
+
let nDt = this.dt ? this.innerText.split(';').length - 2 : 0;
|
|
78
79
|
range.setStartBefore(this);
|
|
79
80
|
let { nextSibling } = this;
|
|
80
81
|
while (nextSibling && (nextSibling.type !== 'text' || !nextSibling.data.includes('\n'))) {
|
|
82
|
+
if (nextSibling.type === 'dd') {
|
|
83
|
+
nDt -= nextSibling.indent;
|
|
84
|
+
}
|
|
85
|
+
if (nDt < 0) {
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
81
88
|
({ nextSibling } = nextSibling);
|
|
82
89
|
}
|
|
83
90
|
if (nextSibling) {
|
|
84
|
-
|
|
85
|
-
|
|
91
|
+
if (nDt < 0) {
|
|
92
|
+
range.setEndBefore(nextSibling);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
const i = nextSibling.data.indexOf('\n');
|
|
96
|
+
range.setEnd(nextSibling, i);
|
|
97
|
+
}
|
|
86
98
|
}
|
|
87
99
|
else {
|
|
88
100
|
const { parentNode } = this;
|
package/dist/src/table/td.js
CHANGED
|
@@ -89,7 +89,7 @@ let TdToken = (() => {
|
|
|
89
89
|
}
|
|
90
90
|
/** 内部wikitext */
|
|
91
91
|
get innerText() {
|
|
92
|
-
return this.lastChild.text();
|
|
92
|
+
return this.lastChild.text().trim();
|
|
93
93
|
}
|
|
94
94
|
set innerText(text) {
|
|
95
95
|
this.lastChild.replaceChildren(...index_1.default.parse(text, true, undefined, this.getAttribute('config')).childNodes);
|
|
@@ -245,7 +245,7 @@ let TdToken = (() => {
|
|
|
245
245
|
/** @private */
|
|
246
246
|
setAttribute(key, value) {
|
|
247
247
|
if (key === 'innerSyntax') {
|
|
248
|
-
this.#innerSyntax = value ?? '';
|
|
248
|
+
this.#innerSyntax = (value ?? '');
|
|
249
249
|
}
|
|
250
250
|
else {
|
|
251
251
|
super.setAttribute(key, value);
|