Home (EN) - bhsd-harry/wikiparser-node GitHub Wiki

Other Languages

Introduction

WikiParser-Node is an offline Wikitext parser developed by Bhsd for the Node.js environment. It can parse almost all wiki syntax and generate an Abstract Syntax Tree (AST). It also allows for easy querying and modification of the AST, and returns the modified Wikitext.

Each node of the AST corresponds to a class Token modeled after the HTMLElement class. This Wiki will introduce the properties and methods available for each type of Token corresponding to different wiki syntax.

Used by

Helix qBittorrent MediaWiki euporie Flow Control LSP for Sublime Text

Other Versions

This version provides a CLI, but only retains the parsing and linting functionality. At the cost of losing AST modification and HTML rendering capabilities, it executes 2.4x faster. Projects can use WikiLint in their CI pipelines to automatically lint wiki content (e.g., qBittorrent).

It powers the Wikitext LSP, which provides multiple language services for editors such as VS Code, Sublime Text, and Helix.

A list of available linting rules can be found here.

Note: The major version number of WikiLint is always higher than that of WikiParser-Node by 1.

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) that focus on template manipulation.

A browser-compatible version, which can be used for code highlighting or as a LSP plugin in conjunction with editors such as CodeMirror and Monaco (Usage example). It has been integrated into the MediaWiki official CodeMirror extension since MediaWiki Release 1.45.

To ensure maximum responsiveness within browser environments, the parser is optimized for speed and memory usage while AST manipulation and HTML rendering are intentionally excluded to prevent main-thread blocking.

Installation

Node.js

Please install the corresponding version as needed (WikiParser-Node or WikiLint), for example:

npm i wikiparser-node

or

npm i wikilint

Optional dependencies

You can install any of the following optional packages to enable advanced features:

Package Purpose
mathoid-texvcjs Diagnostics and HTML conversion support for <math> and <chem> extension tags
stylelint-config-recommended Diagnostics for style attributes
vscode-css-languageservice CSS language support for style attributes
vscode-html-languageservice Language support for HTML tags
vscode-json-languageservice JSON language support for <templatedata>, <mapframe> and <maplink> tags
ajv + ajv-errors HTML conversion support for <templatedata> extension tags
katex HTML conversion support for <math> and <chem> extension tags
prismjs + prism-wiki Syntax highlighting of <syntaxhighlight> extension tags
# Full LanguageService features for `Parser.createLanguageService()`
npm i mathoid-texvcjs stylelint-config-recommended vscode-css-languageservice vscode-html-languageservice vscode-json-languageservice

# Full HTML conversion support for `Parser.toHtml()`
npm i ajv ajv-errors katex mathoid-texvcjs prismjs prism-wiki

Browser

You can download the code via CDN, for example:

<script src="//cdn.jsdelivr.net/npm/wikiparser-node"></script>

or

<script src="//unpkg.com/wikiparser-node/bundle/bundle-lsp.min.js"></script>

For more browser extensions, please refer to the corresponding documentation.

Usage

Please refer to the document of the main entry and the corresponding documents of each type of Token.

Examples

Rules

A full list of linting rules can be found here.

Tests

WikiParser-Node has been extensively tested against the official MediaWiki PHP parser tests with ~3,000 test cases, covering various edge cases and peculiarities of Wikitext. These tests are available here.

⚠️ **GitHub.com Fallback** ⚠️