wikiparser-node 1.40.0 → 1.42.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.
Files changed (66) hide show
  1. package/README.md +55 -7
  2. package/bundle/bundle-es8.min.js +27 -27
  3. package/bundle/bundle-lsp.min.js +29 -29
  4. package/bundle/bundle.min.js +19 -19
  5. package/config/.schema.json +5 -0
  6. package/config/default.json +1 -1
  7. package/config/enwiki.json +3 -2
  8. package/config/jawiki.json +6 -5
  9. package/config/llwiki.json +2 -1
  10. package/config/minimum.json +1 -1
  11. package/config/moegirl.json +2 -1
  12. package/config/zhwiki.json +3 -2
  13. package/dist/addon/attribute.js +1 -1
  14. package/dist/addon/transclude.js +1 -3
  15. package/dist/base.d.mts +5 -3
  16. package/dist/base.d.ts +5 -3
  17. package/dist/bin/config.js +11 -10
  18. package/dist/index.js +1 -2
  19. package/dist/lib/element.d.ts +3 -8
  20. package/dist/lib/element.js +2 -26
  21. package/dist/lib/lintConfig.js +30 -23
  22. package/dist/lib/lsp.d.ts +2 -0
  23. package/dist/lib/lsp.js +8 -20
  24. package/dist/lib/node.d.ts +2 -0
  25. package/dist/lib/node.js +0 -7
  26. package/dist/lib/range.d.ts +0 -7
  27. package/dist/lib/range.js +5 -14
  28. package/dist/lib/text.js +4 -6
  29. package/dist/map.d.ts +66 -0
  30. package/dist/map.js +2 -0
  31. package/dist/mixin/attributesParent.d.ts +4 -3
  32. package/dist/mixin/elementLike.d.ts +13 -0
  33. package/dist/mixin/elementLike.js +66 -53
  34. package/dist/parser/selector.js +3 -3
  35. package/dist/render/extension.js +139 -8
  36. package/dist/render/html.js +72 -3
  37. package/dist/render/magicWords.js +6 -3
  38. package/dist/src/attribute.d.ts +2 -2
  39. package/dist/src/attribute.js +18 -14
  40. package/dist/src/attributes.d.ts +3 -3
  41. package/dist/src/attributes.js +35 -19
  42. package/dist/src/extLink.js +5 -4
  43. package/dist/src/heading.js +11 -3
  44. package/dist/src/index.js +3 -4
  45. package/dist/src/link/base.js +2 -4
  46. package/dist/src/link/file.js +5 -5
  47. package/dist/src/link/galleryImage.js +1 -3
  48. package/dist/src/magicLink.js +6 -5
  49. package/dist/src/multiLine/gallery.js +2 -3
  50. package/dist/src/nowiki/doubleUnderscore.d.ts +1 -0
  51. package/dist/src/nowiki/doubleUnderscore.js +4 -1
  52. package/dist/src/nowiki/quote.js +1 -3
  53. package/dist/src/parameter.js +5 -2
  54. package/dist/src/table/td.d.ts +2 -2
  55. package/dist/src/table/td.js +1 -1
  56. package/dist/src/tag/html.js +29 -12
  57. package/dist/src/tagPair/ext.js +4 -1
  58. package/dist/src/tagPair/translate.d.ts +1 -1
  59. package/dist/src/tagPair/translate.js +1 -1
  60. package/dist/util/debug.js +5 -7
  61. package/dist/util/html.js +3 -11
  62. package/dist/util/sharable.js +2 -0
  63. package/dist/util/sharable.mjs +3 -1
  64. package/extensions/dist/base.js +1 -1
  65. package/extensions/dist/env.js +34 -0
  66. package/package.json +19 -20
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,42 @@ 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
+
119
+ Parser.config = "enwiki";
120
+ const root = Parser.parse("{{Infobox|name=Old}}\nText"),
121
+ template = root.querySelector<TranscludeToken>("template#Template:Infobox");
122
+ template?.setValue("name", "New");
123
+ const wikitext = String(root);
124
+ assert.strictEqual(wikitext, "{{Infobox|name=New}}\nText");
125
+ ```
126
+
89
127
  ## Performance
90
128
 
91
129
  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
130
 
131
+ ## Best fit
132
+
133
+ - MediaWiki bot workflows that require robust AST manipulation and round-trip-safe edits.
134
+ - Node.js pipelines for linting and refactoring Wikitext.
135
+ - LSP-based language tooling.
136
+ - Browser-side editing helpers, and gadgets/user scripts that require Wikitext parsing.
137
+
93
138
  ## Known issues
94
139
 
140
+ The following limitations are documented for transparency.
141
+
95
142
  ### Parser
96
143
 
97
144
  1. Memory leaks may occur in rare cases.
@@ -106,8 +153,8 @@ A full database dump (`*.xml.bz2`) [scan](https://www.npmjs.com/package/lint-wik
106
153
 
107
154
  #### Extension
108
155
 
109
- 1. Many extensions are not supported, such as `<indicator>` and `<ref>`.
110
- 1. `&` needs to be escaped in `<syntaxhighlight>` ([Example](http://bhsd-harry.github.io/wikiparser-node/tests.html#XSS%20is%20escaped)).
156
+ 1. Many extensions are not supported.
157
+ 1. [Sub-referencing](https://meta.wikimedia.org/wiki/WMDE_Technical_Wishes/Sub-referencing) is not supported.
111
158
 
112
159
  #### Transclusion
113
160
 
@@ -116,7 +163,7 @@ A full database dump (`*.xml.bz2`) [scan](https://www.npmjs.com/package/lint-wik
116
163
 
117
164
  #### Heading
118
165
 
119
- 1. The table of contents (TOC) is not supported.
166
+ 1. RTL support in the table of contents (TOC) ([Example](http://bhsd-harry.github.io/wikiparser-node/tests.html#span%20tags%20with%20directionality%20in%20TOC)).
120
167
 
121
168
  #### HTML tag
122
169
 
@@ -150,6 +197,7 @@ A full database dump (`*.xml.bz2`) [scan](https://www.npmjs.com/package/lint-wik
150
197
 
151
198
  1. Automatic language conversion is not supported.
152
199
  1. Support for manual language conversion is minimal ([Example](https://bhsd-harry.github.io/wikiparser-node/tests.html#Explicit%20session-wise%20one-way%20language%20variant%20mapping%20(A%20flag%20and%20-%20flag))).
200
+ 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))).
153
201
 
154
202
  #### Miscellaneous
155
203