wikiparser-node 1.4.3 → 1.4.4
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.en.md +1 -1
- package/README.md +1 -1
- package/dist/lib/element.js +9 -4
- package/dist/src/attributes.js +1 -1
- package/dist/src/html.js +8 -6
- package/dist/src/imageParameter.js +1 -3
- package/dist/src/table/index.js +10 -0
- package/i18n/zh-hans.json +1 -0
- package/i18n/zh-hant.json +1 -0
- package/package.json +2 -2
package/README.en.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
# Introduction
|
|
10
10
|
|
|
11
|
-
wikiparser-node is an offline [Wikitext](https://www.mediawiki.org/wiki/Wikitext) parser developed by Bhsd for the [Node.js](https://nodejs.org/) environment. It can parse almost all wiki syntax and generate an [Abstract Syntax Tree (AST)](https://en.wikipedia.org/wiki/Abstract_syntax_tree). It also allows for easy querying and modification of the AST, and returns the modified wikitext.
|
|
11
|
+
wikiparser-node is an offline [Wikitext](https://www.mediawiki.org/wiki/Wikitext) parser developed by Bhsd for the [Node.js](https://nodejs.org/) environment. It can parse almost all wiki syntax and generate an [Abstract Syntax Tree (AST)](https://en.wikipedia.org/wiki/Abstract_syntax_tree) ([Try it online](https://bhsd-harry.github.io/wikiparser-node/#editor)). It also allows for easy querying and modification of the AST, and returns the modified wikitext.
|
|
12
12
|
|
|
13
13
|
# Other Versions
|
|
14
14
|
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
# 简介
|
|
10
10
|
|
|
11
|
-
wikiparser-node 是一款由 Bhsd 开发的基于 [Node.js](https://nodejs.org/) 环境的离线[维基文本](https://www.mediawiki.org/wiki/Wikitext)语法解析器,可以解析几乎全部的维基语法并生成[语法树](https://en.wikipedia.org/wiki/Abstract_syntax_tree)
|
|
11
|
+
wikiparser-node 是一款由 Bhsd 开发的基于 [Node.js](https://nodejs.org/) 环境的离线[维基文本](https://www.mediawiki.org/wiki/Wikitext)语法解析器,可以解析几乎全部的维基语法并生成[语法树](https://en.wikipedia.org/wiki/Abstract_syntax_tree)([在线解析](https://bhsd-harry.github.io/wikiparser-node/#editor)),还可以很方便地对语法树进行查询和修改,最后返回修改后的维基文本。
|
|
12
12
|
|
|
13
13
|
# 其他版本
|
|
14
14
|
|
package/dist/lib/element.js
CHANGED
|
@@ -116,16 +116,21 @@ class AstElement extends node_1.AstNode {
|
|
|
116
116
|
normalize() {
|
|
117
117
|
const childNodes = [...this.childNodes];
|
|
118
118
|
for (let i = childNodes.length - 1; i >= 0; i--) {
|
|
119
|
-
const { type, data } = childNodes[i]
|
|
119
|
+
const { type, data } = childNodes[i];
|
|
120
120
|
if (type !== 'text' || this.getGaps(i - 1)) {
|
|
121
121
|
//
|
|
122
122
|
}
|
|
123
123
|
else if (data === '') {
|
|
124
124
|
childNodes.splice(i, 1);
|
|
125
|
+
/* NOT FOR BROWSER */
|
|
125
126
|
}
|
|
126
|
-
else
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
else {
|
|
128
|
+
const prev = childNodes[i - 1];
|
|
129
|
+
if (prev?.type === 'text') {
|
|
130
|
+
prev.setAttribute('data', prev.data + data);
|
|
131
|
+
childNodes.splice(i, 1);
|
|
132
|
+
}
|
|
133
|
+
/* NOT FOR BROWSER END */
|
|
129
134
|
}
|
|
130
135
|
}
|
|
131
136
|
this.setAttribute('childNodes', childNodes);
|
package/dist/src/attributes.js
CHANGED
|
@@ -179,7 +179,7 @@ class AttributesToken extends index_2.Token {
|
|
|
179
179
|
/** @override */
|
|
180
180
|
print() {
|
|
181
181
|
return String(this)
|
|
182
|
-
? `<span class="wpb-${this.type}">${this.childNodes.map(child => child.print(child instanceof atom_1.AtomToken
|
|
182
|
+
? `<span class="wpb-${this.type}">${this.childNodes.map(child => child.print(child instanceof atom_1.AtomToken ? { class: 'attr-dirty' } : undefined)).join('')}</span>`
|
|
183
183
|
: '';
|
|
184
184
|
}
|
|
185
185
|
/* NOT FOR BROWSER */
|
package/dist/src/html.js
CHANGED
|
@@ -155,11 +155,15 @@ let HtmlToken = (() => {
|
|
|
155
155
|
}
|
|
156
156
|
/** @override */
|
|
157
157
|
text() {
|
|
158
|
-
const { closing,
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
const { closing,
|
|
159
|
+
/* NOT FOR BROWSER */
|
|
160
|
+
name, } = this, { html: [, , voidTags] } = this.getAttribute('config'), tag = `${this.#tag}${closing ? '' : super.text()}`;
|
|
161
|
+
/* NOT FOR BROWSER */
|
|
162
|
+
if (voidTags.includes(name)) {
|
|
163
|
+
return closing && name !== 'br' ? '' : `<${tag}/>`;
|
|
161
164
|
}
|
|
162
|
-
|
|
165
|
+
/* NOT FOR BROWSER END */
|
|
166
|
+
return `<${closing ? '/' : ''}${tag}${this.#selfClosing ? '/' : ''}>`;
|
|
163
167
|
}
|
|
164
168
|
/** @private */
|
|
165
169
|
getAttribute(key) {
|
|
@@ -271,11 +275,9 @@ let HtmlToken = (() => {
|
|
|
271
275
|
}
|
|
272
276
|
/** @override */
|
|
273
277
|
print() {
|
|
274
|
-
const { closing, name } = this, { html } = this.getAttribute('config');
|
|
275
278
|
return super.print({
|
|
276
279
|
pre: `<${this.closing ? '/' : ''}${this.#tag}`,
|
|
277
280
|
post: `${this.#selfClosing ? '/' : ''}>`,
|
|
278
|
-
class: closing && html[2].includes(name) && name !== 'br' ? 'html-invalid' : 'html',
|
|
279
281
|
});
|
|
280
282
|
}
|
|
281
283
|
/** @override */
|
|
@@ -186,9 +186,7 @@ class ImageParameterToken extends index_2.Token {
|
|
|
186
186
|
/** @override */
|
|
187
187
|
print() {
|
|
188
188
|
if (this.#syntax) {
|
|
189
|
-
return this.
|
|
190
|
-
? `<span class="wpb-image-invalid">${this.#syntax.replace('$1', (0, string_1.print)(this.childNodes))}</span>`
|
|
191
|
-
: `<span class="wpb-image-parameter">${this.#syntax.replace('$1', `<span class="wpb-image-caption">${(0, string_1.print)(this.childNodes)}</span>`)}</span>`;
|
|
189
|
+
return `<span class="wpb-image-parameter">${this.#syntax.replace('$1', `<span class="wpb-image-caption">${(0, string_1.print)(this.childNodes)}</span>`)}</span>`;
|
|
192
190
|
}
|
|
193
191
|
return super.print({ class: 'image-caption' });
|
|
194
192
|
}
|
package/dist/src/table/index.js
CHANGED
|
@@ -43,6 +43,16 @@ class TableToken extends trBase_1.TrBaseToken {
|
|
|
43
43
|
if (!this.closed) {
|
|
44
44
|
errors.push((0, lint_1.generateForChild)(this.firstChild, { start }, index_1.default.msg('unclosed $1', 'table')));
|
|
45
45
|
}
|
|
46
|
+
/* NOT FOR BROWSER */
|
|
47
|
+
const layout = this.getLayout(), { length } = layout;
|
|
48
|
+
if (length > 1) {
|
|
49
|
+
const j = new Array(length - 1).fill(undefined)
|
|
50
|
+
.findIndex((_, i) => layout[i].length !== layout[i + 1].length) + 1;
|
|
51
|
+
if (j) {
|
|
52
|
+
errors.push((0, lint_1.generateForChild)(this.getNthRow(j), { start }, 'inconsistent table layout', 'warning'));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/* NOT FOR BROWSER END */
|
|
46
56
|
return errors;
|
|
47
57
|
}
|
|
48
58
|
/**
|
package/i18n/zh-hans.json
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"HTML tag in table attributes": "表格属性中的HTML标签",
|
|
22
22
|
"illegal attribute name": "非法的属性名",
|
|
23
23
|
"illegal module name": "非法的模块名称",
|
|
24
|
+
"inconsistent table layout": "不一致的表格布局",
|
|
24
25
|
"insecure style": "不安全的样式",
|
|
25
26
|
"internal link in an external link": "外链中的内链",
|
|
26
27
|
"invalid content in <$1>": "<$1>内的无效内容",
|
package/i18n/zh-hant.json
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"HTML tag in table attributes": "表格屬性中的HTML標籤",
|
|
22
22
|
"illegal attribute name": "非法的屬性名",
|
|
23
23
|
"illegal module name": "非法的模組名稱",
|
|
24
|
+
"inconsistent table layout": "不一致的表格佈局",
|
|
24
25
|
"insecure style": "不安全的樣式",
|
|
25
26
|
"internal link in an external link": "外部連結中的內部連結",
|
|
26
27
|
"invalid content in <$1>": "<$1>內的無效內容",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wikiparser-node",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "A Node.js parser for MediaWiki markup with AST",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mediawiki",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"declaration": "grep -rl --include='*.d.ts' '@private' dist/ | xargs bash sed.sh -i -E '/^\\s+\\/\\*\\* @private/,+1d'; node ./dist/bin/declaration.js",
|
|
32
32
|
"prepublishOnly": "npm run build && rm dist/internal.js dist/base.js dist/[pu]*/*.d.ts",
|
|
33
33
|
"build": "bash build.sh",
|
|
34
|
-
"diff": "
|
|
34
|
+
"diff": "bash diff.sh",
|
|
35
35
|
"diff:stat": "f() { git diff --stat --ignore-all-space --color=always $1 $2 -- . ':!extensions/' ':!bin/' | grep '\\.ts'; }; f",
|
|
36
36
|
"lint:ts": "tsc --noEmit && eslint --cache .",
|
|
37
37
|
"lint:json": "ajv -s config/.schema.json -d 'config/*.json' --strict=true --strict-required=false",
|