wikiparser-node 1.1.6 → 1.2.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/dist/lib/element.js
CHANGED
|
@@ -358,7 +358,7 @@ class AstElement extends node_1.AstNode {
|
|
|
358
358
|
* @throws `SyntaxError` 未定义的伪选择器
|
|
359
359
|
*/
|
|
360
360
|
#matches(step) {
|
|
361
|
-
const { parentNode, type, name, childNodes, link
|
|
361
|
+
const { parentNode, type, name, childNodes, link } = this, children = parentNode?.children, childrenOfType = children?.filter(({ type: t }) => t === type), siblingsCount = children?.length ?? 1, siblingsCountOfType = childrenOfType?.length ?? 1, index = (children?.indexOf(this) ?? 0) + 1, indexOfType = (childrenOfType?.indexOf(this) ?? 0) + 1, lastIndex = siblingsCount - index + 1, lastIndexOfType = siblingsCountOfType - indexOfType + 1;
|
|
362
362
|
return step.every(selector => {
|
|
363
363
|
if (typeof selector === 'string') {
|
|
364
364
|
switch (selector) { // 情形1:简单伪选择器、type和name
|
|
@@ -396,12 +396,8 @@ class AstElement extends node_1.AstNode {
|
|
|
396
396
|
case ':local-link':
|
|
397
397
|
return (type === 'link' || type === 'file' || type === 'gallery-image')
|
|
398
398
|
&& link instanceof title_1.Title && link.title === '';
|
|
399
|
-
case ':read-only':
|
|
400
|
-
return fixed;
|
|
401
|
-
case ':read-write':
|
|
402
|
-
return !fixed;
|
|
403
399
|
case ':invalid':
|
|
404
|
-
return type === 'table-inter' ||
|
|
400
|
+
return type === 'table-inter' || type === 'image-parameter' && name === 'invalid';
|
|
405
401
|
case ':required':
|
|
406
402
|
return this.#isProtected() === true;
|
|
407
403
|
case ':optional':
|
package/dist/parser/links.js
CHANGED
|
@@ -14,7 +14,7 @@ const category_1 = require("../src/link/category");
|
|
|
14
14
|
*/
|
|
15
15
|
const parseLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
|
|
16
16
|
const { parseQuotes } = require('./quotes');
|
|
17
|
-
const regex = /^((?:(?!\0\d+!\x7F)[^\n
|
|
17
|
+
const regex = /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(?:(\||\0\d+!\x7F)(.*?[^\]]))?\]\](.*)$/su, regexImg = /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(\||\0\d+!\x7F)(.*)$/su, regexExt = new RegExp(`^\\s*(?:${config.protocol})`, 'iu'), bits = wikitext.split('[[');
|
|
18
18
|
let s = bits.shift();
|
|
19
19
|
for (let i = 0; i < bits.length; i++) {
|
|
20
20
|
let mightBeImg = false, link, delimiter, text, after;
|
package/dist/parser/selector.js
CHANGED
package/dist/src/attributes.js
CHANGED
|
@@ -178,7 +178,7 @@ class AttributesToken extends index_1.Token {
|
|
|
178
178
|
/** @override */
|
|
179
179
|
print() {
|
|
180
180
|
return String(this)
|
|
181
|
-
? `<span class="wpb-${this.type}">${this.childNodes.map(child => child.print(child instanceof atom_1.AtomToken && child.text().trim() ? { class: '
|
|
181
|
+
? `<span class="wpb-${this.type}">${this.childNodes.map(child => child.print(child instanceof atom_1.AtomToken && child.text().trim() ? { class: 'attr-dirty' } : undefined)).join('')}</span>`
|
|
182
182
|
: '';
|
|
183
183
|
}
|
|
184
184
|
/* NOT FOR BROWSER */
|
package/dist/src/gallery.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import * as Parser from '../index';
|
|
2
2
|
import { Token } from './index';
|
|
3
3
|
import { GalleryImageToken } from './link/galleryImage';
|
|
4
|
-
import {
|
|
4
|
+
import { NoincludeToken } from './nowiki/noinclude';
|
|
5
5
|
import type { LintError } from '../base';
|
|
6
6
|
import type { AstNodes, AstText, AttributesToken, ExtToken } from '../internal';
|
|
7
7
|
/**
|
|
8
8
|
* gallery标签
|
|
9
|
-
* @classdesc `{childNodes: ...(GalleryImageToken|
|
|
9
|
+
* @classdesc `{childNodes: ...(GalleryImageToken|NoincludeToken|AstText)}`
|
|
10
10
|
*/
|
|
11
11
|
export declare class GalleryToken extends Token {
|
|
12
12
|
#private;
|
|
13
13
|
readonly type = "ext-inner";
|
|
14
14
|
readonly name: 'gallery';
|
|
15
|
-
readonly childNodes: (GalleryImageToken |
|
|
16
|
-
abstract get children(): (GalleryImageToken |
|
|
17
|
-
abstract get firstChild(): GalleryImageToken |
|
|
18
|
-
abstract get firstElementChild(): GalleryImageToken |
|
|
19
|
-
abstract get lastChild(): GalleryImageToken |
|
|
20
|
-
abstract get lastElementChild(): GalleryImageToken |
|
|
15
|
+
readonly childNodes: (GalleryImageToken | NoincludeToken | AstText)[];
|
|
16
|
+
abstract get children(): (GalleryImageToken | NoincludeToken)[];
|
|
17
|
+
abstract get firstChild(): GalleryImageToken | NoincludeToken | AstText | undefined;
|
|
18
|
+
abstract get firstElementChild(): GalleryImageToken | NoincludeToken | undefined;
|
|
19
|
+
abstract get lastChild(): GalleryImageToken | NoincludeToken | AstText | undefined;
|
|
20
|
+
abstract get lastElementChild(): GalleryImageToken | NoincludeToken | undefined;
|
|
21
21
|
abstract get nextSibling(): undefined;
|
|
22
22
|
abstract get nextElementSibling(): undefined;
|
|
23
23
|
abstract get previousSibling(): AttributesToken;
|
package/dist/src/gallery.js
CHANGED
|
@@ -6,10 +6,10 @@ const constants_1 = require("../util/constants");
|
|
|
6
6
|
const Parser = require("../index");
|
|
7
7
|
const index_1 = require("./index");
|
|
8
8
|
const galleryImage_1 = require("./link/galleryImage");
|
|
9
|
-
const
|
|
9
|
+
const noinclude_1 = require("./nowiki/noinclude");
|
|
10
10
|
/**
|
|
11
11
|
* gallery标签
|
|
12
|
-
* @classdesc `{childNodes: ...(GalleryImageToken|
|
|
12
|
+
* @classdesc `{childNodes: ...(GalleryImageToken|NoincludeToken|AstText)}`
|
|
13
13
|
*/
|
|
14
14
|
class GalleryToken extends index_1.Token {
|
|
15
15
|
type = 'ext-inner';
|
|
@@ -22,16 +22,12 @@ class GalleryToken extends index_1.Token {
|
|
|
22
22
|
/** @param inner 标签内部wikitext */
|
|
23
23
|
constructor(inner, config = Parser.getConfig(), accum = []) {
|
|
24
24
|
super(undefined, config, accum, {
|
|
25
|
-
AstText: ':', GalleryImageToken: ':',
|
|
25
|
+
AstText: ':', GalleryImageToken: ':', NoincludeToken: ':',
|
|
26
26
|
});
|
|
27
27
|
for (const line of inner?.split('\n') ?? []) {
|
|
28
28
|
const matches = /^([^|]+)(?:\|(.*))?/u.exec(line);
|
|
29
29
|
if (!matches) {
|
|
30
|
-
super.insertAt((line.trim()
|
|
31
|
-
? new hidden_1.HiddenToken(line, config, [], {
|
|
32
|
-
AstText: ':',
|
|
33
|
-
})
|
|
34
|
-
: line));
|
|
30
|
+
super.insertAt((line.trim() ? new noinclude_1.NoincludeToken(line, config) : line));
|
|
35
31
|
continue;
|
|
36
32
|
}
|
|
37
33
|
const [, file, alt] = matches;
|
|
@@ -39,9 +35,7 @@ class GalleryToken extends index_1.Token {
|
|
|
39
35
|
super.insertAt(new galleryImage_1.GalleryImageToken('gallery', file, alt, config, accum));
|
|
40
36
|
}
|
|
41
37
|
else {
|
|
42
|
-
super.insertAt(new
|
|
43
|
-
AstText: ':',
|
|
44
|
-
}));
|
|
38
|
+
super.insertAt(new noinclude_1.NoincludeToken(line, config));
|
|
45
39
|
}
|
|
46
40
|
}
|
|
47
41
|
}
|
|
@@ -69,7 +63,7 @@ class GalleryToken extends index_1.Token {
|
|
|
69
63
|
const { top, left } = this.getRootNode().posFromIndex(start), errors = [];
|
|
70
64
|
for (let i = 0; i < this.length; i++) {
|
|
71
65
|
const child = this.childNodes[i], str = String(child), { length } = str, trimmed = str.trim(), startLine = top + i, startCol = i ? 0 : left;
|
|
72
|
-
if (child.type === '
|
|
66
|
+
if (child.type === 'noinclude' && trimmed && !/^<!--.*-->$/u.test(trimmed)) {
|
|
73
67
|
errors.push({
|
|
74
68
|
message: Parser.msg('invalid content in <$1>', 'gallery'),
|
|
75
69
|
severity: 'error',
|
|
@@ -82,7 +76,7 @@ class GalleryToken extends index_1.Token {
|
|
|
82
76
|
excerpt: String(child).slice(0, 50),
|
|
83
77
|
});
|
|
84
78
|
}
|
|
85
|
-
else if (child.type !== '
|
|
79
|
+
else if (child.type !== 'noinclude' && child.type !== 'text') {
|
|
86
80
|
errors.push(...child.lint(start));
|
|
87
81
|
}
|
|
88
82
|
start += length + 1;
|
|
@@ -119,7 +113,7 @@ class GalleryToken extends index_1.Token {
|
|
|
119
113
|
}
|
|
120
114
|
/** @ignore */
|
|
121
115
|
insertAt(token, i = this.length) {
|
|
122
|
-
if (typeof token === 'string' && token.trim() || token instanceof
|
|
116
|
+
if (typeof token === 'string' && token.trim() || token instanceof noinclude_1.NoincludeToken) {
|
|
123
117
|
throw new RangeError('请勿向图库中插入不可见内容!');
|
|
124
118
|
}
|
|
125
119
|
return super.insertAt(token, i);
|
|
@@ -176,9 +176,12 @@ class ImageParameterToken extends index_1.Token {
|
|
|
176
176
|
}
|
|
177
177
|
/** @override */
|
|
178
178
|
print() {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
179
|
+
if (this.#syntax) {
|
|
180
|
+
return this.name === 'invalid'
|
|
181
|
+
? `<span class="wpb-image-invalid">${this.#syntax.replace('$1', (0, string_1.print)(this.childNodes))}</span>`
|
|
182
|
+
: `<span class="wpb-image-parameter">${this.#syntax.replace('$1', `<span class="wpb-image-caption">${(0, string_1.print)(this.childNodes)}</span>`)}</span>`;
|
|
183
|
+
}
|
|
184
|
+
return super.print({ class: 'image-caption' });
|
|
182
185
|
}
|
|
183
186
|
/* NOT FOR BROWSER */
|
|
184
187
|
/** @override */
|