Skip to content

t7ru/wikistxr

Repository files navigation

wikistxr logo

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 wikistxr

Usage

WikitextHighlighter

Static, full-pass syntax highlighting

  • Tokenizes input in one pass.
  • Renders to HTML strings.
import { WikitextHighlighter } from "wikistxr";

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 { WikitextEditor } from "wikistxr";

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

License

MIT

About

A blazingly fast Wikitext library for syntax highlighting or editing.

Resources

License

Stars

Watchers

Forks