Synesthesia

A lightweight, pluggable syntax highlighting editor with perfect textarea alignment

v1.0.2 ~22.1KB minified MIT License TypeScript Support Zero Dependencies

๐Ÿ”Œ Pluggable Parser Architecture

Easy to extend with custom language parsers. Built-in support for JavaScript and plain text, with a simple API for adding more.

๐ŸŽจ Advanced Theme System

CSS variable-based theming with built-in light and dark themes. Create custom themes with full control over syntax colors.

๐Ÿ“ฆ Multiple Build Formats

Ships with ESM, CJS, and IIFE builds. Use it with any bundler or directly in the browser via CDN.

โœจ Perfect Alignment

Transparent textarea overlay ensures perfect WYSIWYG alignment between input and highlighted preview.

๐Ÿ” TypeScript Support

Full TypeScript definitions included for excellent IDE support and type safety.

๐Ÿงช Well Tested

Comprehensive test suite ensures reliability. DOM recovery and parser registry thoroughly tested.

Quick Start

Install via npm:

Or use via CDN:

Live Demos

๐Ÿ“š How to Use Prism.js with Synesthesia

HTML Markup Language

CSS Stylesheets

JavaScript Programming

Python Programming

Java Programming

Go Programming

Core API

new Synesthesia(target, options)

Initialize editor on target element(s)

Returns: Array<Synesthesia> - Array of instances

instance.getValue()

Get the current editor content

Returns: string

instance.setValue(text)

Set the editor content

Parameters: text: string

instance.setLanguage(language)

Change the syntax highlighting language

Parameters: language: string

Synesthesia.parserRegistry

Access the global parser registry to add custom language support

Methods: register(), get(), getByLanguage(), list()

Synesthesia.setTheme(theme)

Set the global theme for all instances

Parameters: theme: string | Theme