wikistxr
v0.1.5
Published
Lightweight wikitext library for syntax highlighting and editing.
Maintainers
Readme
wikistxr
A blazingly fast library for Wikitext that has a syntax highlighter and editor written in Rust and TypeScript.
Neat Little Facts About It
- Supports all wikitext syntax.
- SIMD-accelerated tokenization via Rust.
- Configurable protocols, redirect keywords, extension tags, etc.
- Semantic CSS classes via
getDefaultStyles().
Installation
npm i wikistxrUsage
Await ready before constructing classes.
WikitextHighlighter
Static, full-pass syntax highlighting
- Tokenizes input in one pass.
- Renders to HTML strings.
import { ready, WikitextHighlighter } from "wikistxr";
await ready;
const highlighter = new WikitextHighlighter();
const html = highlighter.highlight(wikitextString);WikitextEditor
Incremental, live editing with DOM patching
- Caches tokenizer state and tokens per line.
- Handles cursor persistence and DOM synchronization.
import { ready, WikitextEditor } from "wikistxr";
await ready;
const editor = new WikitextEditor();
editor.attach(editableDiv);
editor.update(wikitextString);Configuration
Both classes accept the same options:
const config = {
urlProtocols: "http|https|mailto",
redirectKeywords: ["REDIRECT", "WEITERLEITUNG"],
extensionTags: ["nowiki", "ref", "gallery"],
contentPreservingTags: ["nowiki", "pre"],
};
const highlighter = new WikitextHighlighter(config);To apply default styles:
const styles = WikitextHighlighter.getDefaultStyles();Development
# Build Rust core and TypeScript bundles
bun run build
# Run development demo
bun run dev