wikiparser-node 0.8.0-m → 0.8.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/README.md +39 -0
- package/index.js +253 -11
- package/lib/element.js +481 -7
- package/lib/node.js +552 -6
- package/lib/ranges.js +130 -0
- package/lib/text.js +108 -16
- package/lib/title.js +21 -0
- package/mixin/attributeParent.js +117 -0
- package/mixin/fixedToken.js +40 -0
- package/mixin/hidden.js +3 -0
- package/mixin/singleLine.js +31 -0
- package/mixin/sol.js +65 -0
- package/package.json +5 -4
- package/parser/brackets.js +1 -0
- package/parser/commentAndExt.js +4 -3
- package/parser/converter.js +1 -0
- package/parser/externalLinks.js +1 -0
- package/parser/hrAndDoubleUnderscore.js +1 -0
- package/parser/html.js +1 -0
- package/parser/links.js +5 -4
- package/parser/list.js +1 -0
- package/parser/magicLinks.js +5 -4
- package/parser/quotes.js +2 -1
- package/parser/selector.js +177 -0
- package/parser/table.js +1 -0
- package/src/arg.js +116 -2
- package/src/atom/hidden.js +2 -0
- package/src/atom/index.js +17 -0
- package/src/attribute.js +181 -4
- package/src/attributes.js +308 -4
- package/src/charinsert.js +97 -0
- package/src/converter.js +108 -2
- package/src/converterFlags.js +187 -0
- package/src/converterRule.js +184 -1
- package/src/extLink.js +120 -1
- package/src/gallery.js +57 -6
- package/src/hasNowiki/index.js +12 -0
- package/src/hasNowiki/pre.js +12 -0
- package/src/heading.js +55 -4
- package/src/html.js +118 -3
- package/src/imageParameter.js +176 -5
- package/src/imagemap.js +60 -1
- package/src/imagemapLink.js +13 -1
- package/src/index.js +529 -3
- package/src/link/category.js +37 -1
- package/src/link/file.js +159 -2
- package/src/link/galleryImage.js +59 -1
- package/src/link/index.js +259 -1
- package/src/magicLink.js +90 -9
- package/src/nested/choose.js +1 -0
- package/src/nested/combobox.js +1 -0
- package/src/nested/index.js +30 -3
- package/src/nested/references.js +1 -0
- package/src/nowiki/comment.js +25 -1
- package/src/nowiki/dd.js +47 -1
- package/src/nowiki/doubleUnderscore.js +31 -1
- package/src/nowiki/hr.js +20 -1
- package/src/nowiki/index.js +23 -1
- package/src/nowiki/list.js +5 -2
- package/src/nowiki/noinclude.js +14 -0
- package/src/nowiki/quote.js +16 -2
- package/src/onlyinclude.js +26 -1
- package/src/paramTag/index.js +24 -1
- package/src/paramTag/inputbox.js +4 -1
- package/src/parameter.js +148 -6
- package/src/syntax.js +68 -0
- package/src/table/index.js +940 -2
- package/src/table/td.js +225 -5
- package/src/table/tr.js +247 -2
- package/src/tagPair/ext.js +24 -3
- package/src/tagPair/include.js +24 -0
- package/src/tagPair/index.js +51 -2
- package/src/transclude.js +512 -11
- package/tool/index.js +1202 -0
- package/util/debug.js +73 -0
- package/util/string.js +48 -1
- package/config/minimum.json +0 -142
package/src/tagPair/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const Parser = require('../..'),
|
|
4
|
+
fixedToken = require('../../mixin/fixedToken'),
|
|
4
5
|
Token = require('..');
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* 成对标签
|
|
8
9
|
* @classdesc `{childNodes: [AstText|AttributesToken, AstText|Token]}`
|
|
9
10
|
*/
|
|
10
|
-
class TagPairToken extends Token {
|
|
11
|
+
class TagPairToken extends fixedToken(Token) {
|
|
11
12
|
#selfClosing;
|
|
12
13
|
#closed;
|
|
13
14
|
#tags;
|
|
@@ -17,6 +18,28 @@ class TagPairToken extends Token {
|
|
|
17
18
|
return this.#closed;
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
set closed(value) {
|
|
22
|
+
this.#closed ||= Boolean(value);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** getter */
|
|
26
|
+
get selfClosing() {
|
|
27
|
+
return this.#selfClosing;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
set selfClosing(value) {
|
|
31
|
+
value = Boolean(value);
|
|
32
|
+
if (value !== this.#selfClosing && this.lastChild.text()) {
|
|
33
|
+
Parser.warn(`<${this.name}>标签内部的${value ? '文本将被隐藏' : '原有文本将再次可见'}!`);
|
|
34
|
+
}
|
|
35
|
+
this.#selfClosing = value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 内部wikitext */
|
|
39
|
+
get innerText() {
|
|
40
|
+
return this.#selfClosing ? undefined : this.lastChild.text();
|
|
41
|
+
}
|
|
42
|
+
|
|
20
43
|
/**
|
|
21
44
|
* @param {string} name 标签名
|
|
22
45
|
* @param {string|Token} attr 标签属性
|
|
@@ -43,10 +66,17 @@ class TagPairToken extends Token {
|
|
|
43
66
|
|
|
44
67
|
/**
|
|
45
68
|
* @override
|
|
69
|
+
* @param {string} selector
|
|
46
70
|
*/
|
|
47
71
|
toString(selector) {
|
|
48
|
-
const {firstChild, lastChild} = this,
|
|
72
|
+
const {firstChild, lastChild, nextSibling, name} = this,
|
|
49
73
|
[opening, closing] = this.#tags;
|
|
74
|
+
if (selector && this.matches(selector)) {
|
|
75
|
+
return '';
|
|
76
|
+
} else if (!this.#closed && nextSibling) {
|
|
77
|
+
Parser.error(`自动闭合 <${name}>`, lastChild);
|
|
78
|
+
this.#closed = true;
|
|
79
|
+
}
|
|
50
80
|
return this.#selfClosing
|
|
51
81
|
? `<${opening}${String(firstChild)}/>`
|
|
52
82
|
: `<${opening}${String(firstChild)}>${String(lastChild)}${this.#closed ? `</${closing}>` : ''}`;
|
|
@@ -72,6 +102,25 @@ class TagPairToken extends Token {
|
|
|
72
102
|
getGaps() {
|
|
73
103
|
return 1;
|
|
74
104
|
}
|
|
105
|
+
|
|
106
|
+
/** @override */
|
|
107
|
+
print() {
|
|
108
|
+
const [opening, closing] = this.#tags;
|
|
109
|
+
return super.print(this.#selfClosing
|
|
110
|
+
? {pre: `<${opening}`, post: '/>'}
|
|
111
|
+
: {pre: `<${opening}`, sep: '>', post: this.#closed ? `</${closing}>` : ''});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @override
|
|
116
|
+
* @template {string} T
|
|
117
|
+
* @param {T} key 属性键
|
|
118
|
+
* @returns {TokenAttribute<T>}
|
|
119
|
+
*/
|
|
120
|
+
getAttribute(key) {
|
|
121
|
+
return key === 'tags' ? [...this.#tags] : super.getAttribute(key);
|
|
122
|
+
}
|
|
75
123
|
}
|
|
76
124
|
|
|
125
|
+
Parser.classes.TagPairToken = __filename;
|
|
77
126
|
module.exports = TagPairToken;
|