wikiparser-node 1.40.0 → 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 CHANGED
@@ -5,9 +5,10 @@
5
5
  [![npm version](https://badge.fury.io/js/wikiparser-node.svg)](https://www.npmjs.com/package/wikiparser-node)
6
6
  [![CodeQL](https://github.com/bhsd-harry/wikiparser-node/actions/workflows/codeql.yml/badge.svg)](https://github.com/bhsd-harry/wikiparser-node/actions/workflows/codeql.yml)
7
7
  [![CI](https://github.com/bhsd-harry/wikiparser-node/actions/workflows/node.js.yml/badge.svg)](https://github.com/bhsd-harry/wikiparser-node/actions/workflows/node.js.yml)
8
+ [![NPM downloads](https://img.shields.io/npm/dm/wikiparser-node)](https://www.npmjs.com/package/wikiparser-node)
8
9
  [![jsDelivr hits (npm)](https://img.shields.io/jsdelivr/npm/hm/wikiparser-node)](https://www.npmjs.com/package/wikiparser-node)
9
10
  [![Codacy Badge](https://app.codacy.com/project/badge/Grade/a2fbe7641031451baca2947ae6d7891f)](https://app.codacy.com/gh/bhsd-harry/wikiparser-node/dashboard)
10
- ![Istanbul coverage](./coverage/badge.svg)
11
+ ![Coverage](./coverage/badge.svg)
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 originally designed to convert Wikitext to HTML, it provides a limited capability to do so. [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.
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
- ### Mini (also known as [WikiLint](https://www.npmjs.com/package/wikilint))
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,19 +103,41 @@ The generated configuration file will be saved in the [`config` directory](https
79
103
 
80
104
  ```javascript
81
105
  // For example:
82
- Parser.config = 'frwiki';
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.