wikiparser-node 1.39.1 → 1.41.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 +51 -5
- package/bundle/bundle-es8.min.js +30 -29
- package/bundle/bundle-lsp.min.js +28 -28
- package/bundle/bundle.min.js +16 -16
- package/config/.schema.json +5 -0
- package/config/default.json +11 -2
- package/config/enwiki.json +91 -89
- package/config/jawiki.json +168 -158
- package/config/llwiki.json +2 -1
- package/config/minimum.json +3 -81
- package/config/moegirl.json +2 -1
- package/config/zhwiki.json +128 -126
- package/data/signatures.json +1 -1
- package/dist/addon/attribute.js +1 -1
- package/dist/addon/table.js +1 -1
- package/dist/addon/transclude.js +3 -1
- package/dist/base.d.mts +11 -9
- package/dist/base.d.ts +11 -9
- package/dist/base.js +1 -0
- package/dist/base.mjs +1 -0
- package/dist/bin/config.js +11 -10
- package/dist/index.d.ts +5 -5
- package/dist/index.js +5 -1
- package/dist/lib/lintConfig.js +42 -23
- package/dist/lib/lsp.js +6 -12
- package/dist/lib/node.js +5 -2
- package/dist/lib/text.js +5 -2
- package/dist/lib/title.js +8 -4
- package/dist/mixin/elementLike.js +2 -2
- package/dist/parser/commentAndExt.js +2 -1
- package/dist/render/expand.js +3 -3
- package/dist/render/extension.js +15 -3
- package/dist/render/magicWords.js +13 -10
- package/dist/src/attribute.d.ts +4 -1
- package/dist/src/attribute.js +5 -4
- package/dist/src/attributes.js +29 -7
- package/dist/src/heading.js +8 -3
- package/dist/src/link/base.d.ts +1 -1
- package/dist/src/link/base.js +10 -6
- package/dist/src/link/file.js +2 -2
- package/dist/src/magicLink.js +20 -16
- package/dist/src/multiLine/gallery.d.ts +5 -3
- package/dist/src/multiLine/gallery.js +6 -4
- package/dist/src/nowiki/base.d.ts +1 -1
- package/dist/src/parameter.js +5 -2
- package/dist/src/table/tr.js +1 -1
- package/dist/src/tagPair/ext.js +12 -18
- package/dist/src/tagPair/index.d.ts +1 -1
- package/dist/src/transclude.d.ts +6 -1
- package/dist/src/transclude.js +27 -19
- package/dist/util/constants.js +2 -1
- package/dist/util/sharable.js +2 -0
- package/dist/util/sharable.mjs +3 -1
- package/extensions/dist/base.js +3 -2
- package/extensions/dist/env.js +34 -0
- package/i18n/en.json +1 -0
- package/i18n/zh-hans.json +1 -0
- package/i18n/zh-hant.json +1 -0
- package/package.json +20 -33
package/README.md
CHANGED
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
[](https://www.npmjs.com/package/wikiparser-node)
|
|
6
6
|
[](https://github.com/bhsd-harry/wikiparser-node/actions/workflows/codeql.yml)
|
|
7
7
|
[](https://github.com/bhsd-harry/wikiparser-node/actions/workflows/node.js.yml)
|
|
8
|
+
[](https://www.npmjs.com/package/wikiparser-node)
|
|
8
9
|
[](https://www.npmjs.com/package/wikiparser-node)
|
|
9
10
|
[](https://app.codacy.com/gh/bhsd-harry/wikiparser-node/dashboard)
|
|
10
|
-

|
|
11
12
|
|
|
12
13
|
## Other Languages
|
|
13
14
|
|
|
@@ -17,11 +18,30 @@
|
|
|
17
18
|
|
|
18
19
|
WikiParser-Node is an offline [Wikitext](https://www.mediawiki.org/wiki/Wikitext) parser developed by [Bhsd](https://github.com/bhsd-harry) for the [Node.js](https://nodejs.org/) environment. It can parse almost all [wiki syntax](https://www.mediawiki.org/wiki/Help:Advanced_editing) 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.
|
|
19
20
|
|
|
20
|
-
Although WikiParser-Node is not
|
|
21
|
+
Although WikiParser-Node is not primarily designed to convert Wikitext to HTML, it provides pragmatic HTML rendering for many situations. [Here](https://bhsd-harry.github.io/wikiparser-website/) is a list of example HTML pages from [MediaWiki.org](https://www.mediawiki.org/) rendered using this package.
|
|
22
|
+
|
|
23
|
+
WikiParser-Node has been extensively tested against the official [MediaWiki PHP parser tests](https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/core/+/refs/heads/master/tests/parser/) with ~3,000 test cases, covering various edge cases and peculiarities of Wikitext. These tests are available [here](https://bhsd-harry.github.io/wikiparser-node/tests.html).
|
|
24
|
+
|
|
25
|
+
## Why WikiParser-Node
|
|
26
|
+
|
|
27
|
+
- **Round-trip editing for bots and automation**: parse Wikitext into an AST, query and modify nodes, then write back valid Wikitext.
|
|
28
|
+
- **LSP and linting ready for Node.js tooling**: powers [WikiLint](https://www.npmjs.com/package/wikilint) and [Wikitext LSP](https://www.npmjs.com/package/wikitext-lsp).
|
|
29
|
+
- **Browser/editor integration**: works with [CodeMirror](https://www.npmjs.com/package/@bhsd/codemirror-mediawiki), [Monaco](https://www.npmjs.com/package/monaco-wiki), and MediaWiki's official [CodeMirror extension](https://www.mediawiki.org/wiki/Extension:CodeMirror).
|
|
30
|
+
- **Large-scale usage evidence**: [full-dump parsing and linting on English Wikipedia scale](https://lint-wiki-dumps.toolforge.org/) is practical on consumer hardware.
|
|
31
|
+
- **Transparent quality signals**: [CI](https://github.com/bhsd-harry/wikiparser-node/actions/workflows/node.js.yml), [CodeQL](https://github.com/bhsd-harry/wikiparser-node/actions/workflows/codeql.yml), public [parser-test results](https://bhsd-harry.github.io/wikiparser-node/tests.html), and coverage are all visible in this repository.
|
|
32
|
+
|
|
33
|
+
## Used by
|
|
34
|
+
|
|
35
|
+
<div align="center">
|
|
36
|
+
<a href="https://www.mediawiki.org/"><img src="https://www.mediawiki.org/static/images/icons/mediawikiwiki.svg" width="50" height="50" alt="MediaWiki"></a>
|
|
37
|
+
<a href="https://helix-editor.com/"><img src="https://helix-editor.com/logo.svg" width="50" height="50" alt="Helix"></a>
|
|
38
|
+
<a href="https://lsp.sublimetext.io/"><img src="https://avatars.githubusercontent.com/u/48095564?s=100" width="50" height="50" alt="LSP for Sublime Text"></a>
|
|
39
|
+
<a href="http://www.qbittorrent.org/"><img src="https://avatars.githubusercontent.com/u/2131270?s=100" width="50" height="50" alt="qBittorrent"></a>
|
|
40
|
+
</div>
|
|
21
41
|
|
|
22
42
|
## Other Versions
|
|
23
43
|
|
|
24
|
-
###
|
|
44
|
+
### [WikiLint](https://www.npmjs.com/package/wikilint)
|
|
25
45
|
|
|
26
46
|
This version provides a [CLI](https://en.wikipedia.org/wiki/Command-line_interface), but only retains the parsing and linting functionality. The parsed AST cannot be modified. It powers the [Wikitext LSP](https://www.npmjs.com/package/wikitext-lsp), which provides multiple language services for editors such as [VS Code](https://marketplace.visualstudio.com/items?itemName=Bhsd.vscode-extension-wikiparser), [Sublime Text](https://lsp.sublimetext.io/language_servers/#mediawiki), and [Helix](https://github.com/helix-editor/helix/wiki/Language-Server-Configurations#wikitext).
|
|
27
47
|
|
|
@@ -31,6 +51,10 @@ A list of available linting rules can be found [here](https://github.com/bhsd-ha
|
|
|
31
51
|
|
|
32
52
|
A browser-compatible version, which can be used for code highlighting or as a [LSP](https://microsoft.github.io/language-server-protocol/) plugin in conjunction with editors such as [CodeMirror](https://www.npmjs.com/package/@bhsd/codemirror-mediawiki) and [Monaco](https://www.npmjs.com/package/monaco-wiki) ([Usage example](https://bhsd-harry.github.io/wikiparser-node)). It has been integrated into the MediaWiki official [CodeMirror extension](https://www.mediawiki.org/wiki/Extension:CodeMirror) since Release 1.45.
|
|
33
53
|
|
|
54
|
+
### [WikiParser-Template](https://www.npmjs.com/package/wikiparser-template)
|
|
55
|
+
|
|
56
|
+
A lightweight version that only supports parsing and manipulation of templates. This version is designed for use cases where only template processing is needed, such as certain types of bots or web tools (e.g., [GANReviewTool](https://en.wikipedia.org/wiki/User:Novem_Linguae/Scripts/GANReviewTool)) that focus on template manipulation.
|
|
57
|
+
|
|
34
58
|
## Installation
|
|
35
59
|
|
|
36
60
|
### Node.js
|
|
@@ -79,24 +103,46 @@ The generated configuration file will be saved in the [`config` directory](https
|
|
|
79
103
|
|
|
80
104
|
```javascript
|
|
81
105
|
// For example:
|
|
82
|
-
Parser.config =
|
|
106
|
+
Parser.config = "frwiki";
|
|
83
107
|
```
|
|
84
108
|
|
|
85
109
|
### API usage
|
|
86
110
|
|
|
87
111
|
Please refer to the [Wiki](https://github.com/bhsd-harry/wikiparser-node/wiki/Home-%28EN%29). In particular, there are some [usage examples](https://github.com/bhsd-harry/wikiparser-node/wiki/Home-%28EN%29#examples) that demonstrate how to use this package to complete various tasks.
|
|
88
112
|
|
|
113
|
+
#### Round-trip editing quickstart (TypeScript)
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import Parser from "wikiparser-node";
|
|
117
|
+
import type {TranscludeToken} from "wikiparser-node";
|
|
118
|
+
Parser.config = "enwiki";
|
|
119
|
+
const root = Parser.parse("{{Infobox|name=Old}}\nText"),
|
|
120
|
+
template = root.querySelector<TranscludeToken>("template#Template:Infobox");
|
|
121
|
+
template?.setValue("name", "New");
|
|
122
|
+
const wikitext = String(root);
|
|
123
|
+
assert.strictEqual(wikitext, "{{Infobox|name=New}}\nText");
|
|
124
|
+
```
|
|
125
|
+
|
|
89
126
|
## Performance
|
|
90
127
|
|
|
91
128
|
A full database dump (`*.xml.bz2`) [scan](https://www.npmjs.com/package/lint-wiki-dumps) of English Wikipedia's ~19 million articles (parsing and linting) on a personal MacBook Air takes about 5 hours.
|
|
92
129
|
|
|
130
|
+
## Best fit
|
|
131
|
+
|
|
132
|
+
- MediaWiki bot workflows that require robust AST manipulation and round-trip-safe edits.
|
|
133
|
+
- Node.js pipelines for linting and refactoring Wikitext.
|
|
134
|
+
- LSP-based language tooling.
|
|
135
|
+
- Browser-side editing helpers, and gadgets/user scripts that require Wikitext parsing.
|
|
136
|
+
|
|
93
137
|
## Known issues
|
|
94
138
|
|
|
139
|
+
The following limitations are documented for transparency.
|
|
140
|
+
|
|
95
141
|
### Parser
|
|
96
142
|
|
|
97
143
|
1. Memory leaks may occur in rare cases.
|
|
98
144
|
1. Invalid page names with unicode characters are treated like valid ones ([Example](http://bhsd-harry.github.io/wikiparser-node/tests.html#Render%20invalid%20page%20names%20as%20plain%20text%20(T53090))).
|
|
99
|
-
1. Preformatted text with a leading space is only processed by [`Token
|
|
145
|
+
1. Preformatted text with a leading space is only processed by [`Token#toHtml`](https://github.com/bhsd-harry/wikiparser-node/wiki/Token-%28EN%29#tohtml).
|
|
100
146
|
1. BCP 47 language codes are not supported in language conversion ([Example](https://bhsd-harry.github.io/wikiparser-node/tests.html#Explicit%20definition%20of%20language%20variant%20alternatives%20(BCP%2047%20codes))).
|
|
101
147
|
|
|
102
148
|
### HTML conversion
|