Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ repos:
args: [--fix]
types_or: [python, pyi]

# Run the formatter
- id: ruff-format
types_or: [python, pyi]

- repo: local
hooks:
- id: ruff-format
name: ruff format
entry: uv run poe format

Copilot AI Mar 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ruff-format pre-commit hook runs uv run poe format, but there’s no poe/poethepoet configuration or dependency in the repo (no [tool.poe] in pyproject.toml, and poe isn’t in dev deps). As written, this hook will fail for contributors/CI unless they happen to have poe installed globally. Consider either restoring the ruff-format hook from astral-sh/ruff-pre-commit, changing the entry to uv run ruff format ..., or adding poethepoet + a format task to pyproject.toml.

Suggested change
entry: uv run poe format
entry: uv run ruff format

Copilot uses AI. Check for mistakes.
language: system
types: [python]
pass_filenames: false
- id: ty
name: ty type checker
entry: uv run ty check src/rosettes/
Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Python 3.14+](https://img.shields.io/badge/python-3.14+-blue.svg)](https://pypi.org/project/rosettes/)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

**Modern syntax highlighting for Python 3.14t**
**A Python syntax highlighter and Pygments alternative for secure code highlighting and existing CSS themes.**

```python
from rosettes import highlight
Expand All @@ -17,16 +17,25 @@ html = highlight("def hello(): print('world')", "python")

## What is Rosettes?

Rosettes is a syntax highlighter for Python 3.14t. Hand-written state machines, O(n) guaranteed, zero ReDoS risk. Safe for untrusted input in web apps and APIs.
Rosettes is a syntax highlighter for Python 3.14t. Hand-written state machines, O(n)
guaranteed, zero ReDoS risk. Safe for untrusted input in web apps and APIs.

**What's good about it:**
**Why people pick it:**

- **O(n) guaranteed** — Hand-written state machines, no regex backtracking
- **Zero ReDoS** — No exploitable patterns, safe for untrusted input
- **Free-threading native** — All lexer state is local variables, keyword tables are `frozenset`, tokens are immutable. Highlight from any number of threads with zero contention.
- **Pygments compatible** — Drop-in CSS class compatibility for existing themes
- **55 languages** — Python, JavaScript, Rust, Go, and 51 more

## Use Rosettes For

- **HTML code highlighting** — Highlight source code for docs, blogs, and web apps
- **Pygments migration paths** — Keep existing CSS themes with Pygments-compatible classes
- **Security-sensitive rendering** — Highlight untrusted input without regex backtracking risk
- **Parallel highlighting** — Process many code blocks across threads with `highlight_many()`
- **Python-native docs stacks** — Use with Bengal, Patitas, or custom site generators

---

## Installation
Expand Down Expand Up @@ -54,6 +63,7 @@ Requires Python 3.14+

| Feature | Description | Docs |
|---------|-------------|------|
| **Choosing Rosettes** | When it fits, migration from Pygments, and tradeoffs | [Choosing Rosettes →](https://lbliii.github.io/rosettes/docs/about/comparison/) |
| **Basic Highlighting** | `highlight()` and `tokenize()` functions | [Highlighting →](https://lbliii.github.io/rosettes/docs/highlighting/) |
| **Parallel Processing** | `highlight_many()` for multi-core systems | [Parallel →](https://lbliii.github.io/rosettes/docs/highlighting/parallel/) |
| **Line Highlighting** | Highlight specific lines, add line numbers | [Lines →](https://lbliii.github.io/rosettes/docs/highlighting/line-highlighting/) |
Expand Down
8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ build-backend = "setuptools.build_meta"
[project]
name = "rosettes"
version = "0.2.0"
description = "Modern syntax highlighting for Python 3.14t — O(n) guaranteed, zero ReDoS"
description = "Python syntax highlighter and Pygments alternative for secure code highlighting and existing CSS themes"
readme = "README.md"
requires-python = ">=3.14"
license = "MIT"
keywords = [
"syntax-highlighting",
"python-syntax-highlighter",
"lexer",
"free-threading",
"pygments",
"pygments-alternative",
"code-highlighting",
]
authors = [{ name = "Bengal Contributors" }]
Expand All @@ -30,8 +32,8 @@ classifiers = [
dependencies = [] # Pure Python, no runtime deps

[project.urls]
Homepage = "https://github.com/lbliii/rosettes"
Documentation = "https://github.com/lbliii/rosettes"
Homepage = "https://lbliii.github.io/rosettes/"
Documentation = "https://lbliii.github.io/rosettes/"
Repository = "https://github.com/lbliii/rosettes"
Issues = "https://github.com/lbliii/rosettes/issues"

Expand Down
23 changes: 17 additions & 6 deletions site/content/_index.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
title: Rosettes
description: Modern syntax highlighting for Python 3.14t
description: A Python syntax highlighter and Pygments alternative for secure code highlighting and existing CSS themes
template: home.html
weight: 100
type: page
draft: false
lang: en
keywords: [rosettes, syntax highlighting, python, free-threading, pygments]
keywords: [rosettes, python syntax highlighter, code highlighting, pygments alternative, secure syntax highlighting, pygments compatible]
category: home

# Hero configuration
Expand All @@ -24,11 +24,14 @@ cta_buttons:
show_recent_posts: false
---

## Syntax Highlighting, Reinvented
## Python Syntax Highlighter for Secure Code Highlighting

**O(n) guaranteed. Zero ReDoS. Thread-safe by design.**
**Pygments alternative. O(n) guaranteed. Safe for untrusted input.**

Rosettes is a pure-Python syntax highlighter built for the free-threaded era. Every lexer is a hand-written state machine—no regex backtracking, no exponential blowup, no security vulnerabilities.
Rosettes is a pure-Python syntax highlighter for HTML output, documentation sites, and
web applications. Every lexer is a hand-written state machine with no regex
backtracking, making it a good fit for secure code highlighting and Pygments-style
migration paths.

```python
from rosettes import highlight
Expand All @@ -38,7 +41,7 @@ html = highlight("def hello(): print('world')", "python")

---

## What's good about it
## Why Use Rosettes

:::{cards}
:columns: 2
Expand Down Expand Up @@ -66,6 +69,14 @@ Drop-in CSS class compatibility. Use your existing Pygments themes or Rosettes'

:::{/cards}

## Common Use Cases

- Highlighting code blocks for documentation sites and blogs
- Replacing or evaluating Pygments in Python applications
- Rendering untrusted code snippets in web applications
- Processing many code blocks in parallel with `highlight_many()`
- Keeping existing themes while moving to a Python-native highlighter

---

## Quick Example
Expand Down
15 changes: 10 additions & 5 deletions site/content/docs/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ cascade:
type: doc
variant: standard
category: documentation
description: Rosettes documentation
description: Documentation for the Rosettes Python syntax highlighter, including code highlighting, styling, and Pygments migration
keywords:
- documentation
- syntax highlighting
- python syntax highlighter
- code highlighting
- pygments alternative
- api
menu:
main:
Expand All @@ -25,7 +28,8 @@ icon: book-open

## Start Here

New to Rosettes? Install and highlight your first code block in under 2 minutes.
New to Rosettes? Start here to highlight code, style the HTML output, process many
blocks in parallel, and migrate from Pygments-compatible themes when needed.

:::{cards}
:columns: 2
Expand All @@ -47,7 +51,8 @@ New to Rosettes? Install and highlight your first code block in under 2 minutes.

## Use Rosettes

Learn how to highlight code, process blocks in parallel, and style your output.
Learn how to highlight code, process blocks in parallel, style the output, and extend
Rosettes for your workflows.

:::{cards}
:columns: 2
Expand All @@ -74,7 +79,7 @@ Learn how to highlight code, process blocks in parallel, and style your output.
:::{card} Tutorials
:icon: notepad
:link: ./tutorials/
:description: Step-by-step guides for common scenarios
:description: Step-by-step guides for common scenarios and migrations
:::{/card}

:::{/cards}
Expand All @@ -96,7 +101,7 @@ Technical specifications, supported languages, and architecture details.
:::{card} About
:icon: info
:link: ./about/
:description: Architecture, performance, and design philosophy
:description: Architecture, performance, comparisons, and design philosophy
:::{/card}

:::{/cards}
Expand Down
8 changes: 6 additions & 2 deletions site/content/docs/about/_index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: About
description: Architecture, design philosophy, and background
description: Architecture, comparisons, and design philosophy for the Rosettes Python syntax highlighter
draft: false
weight: 00
lang: en
Expand All @@ -14,12 +14,16 @@ keywords:
- about
- architecture
- philosophy
- python syntax highlighter
- pygments alternative
icon: info
---

# About Rosettes

Rosettes is a modern syntax highlighter designed for Python 3.14's free-threading era. Every design decision prioritizes safety, predictability, and performance.
Rosettes is a modern syntax highlighter designed for Python 3.14's free-threading era.
This section explains why it fits teams that care about safe highlighting,
predictable performance, and Pygments-compatible output.

## Core Principles

Expand Down
9 changes: 7 additions & 2 deletions site/content/docs/about/comparison.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Choosing Rosettes
description: When Rosettes fits and what it offers
description: When Rosettes fits, how it compares to Pygments-style highlighters, and when to choose alternatives
draft: false
weight: 40
lang: en
Expand All @@ -12,12 +12,15 @@ keywords:
- choosing
- features
- migration
- pygments alternative
- python syntax highlighter
icon: bar-chart
---

# Choosing Rosettes

Rosettes is a good fit when you need syntax highlighting with predictable performance and security.
Rosettes is a good fit when you need syntax highlighting with predictable performance,
security, and a straightforward path from Pygments-compatible themes.

## What Rosettes Offers

Expand All @@ -28,13 +31,15 @@ Rosettes is a good fit when you need syntax highlighting with predictable perfor
- **Parallel highlighting** — `highlight_many()` for multiple blocks
- **Zero dependencies** — Pure Python
- **Pygments CSS compatibility** — Use existing themes with `css_class_style="pygments"`
- **Python-native integration** — Easy to use from docs pipelines and web applications

## When Rosettes Fits

- Web applications highlighting user code or documentation
- Static site generators (e.g., Bengal)
- Python 3.14+ projects using free-threading
- Projects where security and predictable performance matter
- Teams that want a Pygments alternative without changing CSS themes

## Limitations

Expand Down
9 changes: 9 additions & 0 deletions site/content/docs/about/thread-safety.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ else:

---

## Code References

| Pattern | File |
|---------|------|
| PEP 703 declaration | [src/rosettes/__init__.py](https://github.com/lbliii/rosettes/blob/main/src/rosettes/__init__.py) |
| Token (immutable NamedTuple) | [src/rosettes/_types.py](https://github.com/lbliii/rosettes/blob/main/src/rosettes/_types.py) |
| Lexer registry (functools.cache) | [src/rosettes/_registry.py](https://github.com/lbliii/rosettes/blob/main/src/rosettes/_registry.py) |
| highlight_many (parallel) | [src/rosettes/_parallel.py](https://github.com/lbliii/rosettes/blob/main/src/rosettes/_parallel.py) |

## Next Steps

- [[docs/highlighting/parallel|Parallel Processing]] — Using `highlight_many()`
Expand Down
5 changes: 4 additions & 1 deletion site/content/docs/get-started/_index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Get Started
description: Install Rosettes and highlight your first code block
description: Install Rosettes and highlight your first code block with a Python syntax highlighter built for secure HTML output
draft: false
weight: 10
lang: en
Expand All @@ -12,6 +12,9 @@ keywords:
- getting started
- installation
- quickstart
- python syntax highlighter
- code highlighting
- pygments alternative
category: onboarding
cascade:
type: doc
Expand Down
4 changes: 3 additions & 1 deletion site/content/docs/highlighting/_index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Highlighting
description: Core highlighting APIs and patterns
description: Core APIs and patterns for code highlighting, tokenization, and parallel highlighting in Rosettes
draft: false
weight: 20
lang: en
Expand All @@ -14,6 +14,8 @@ keywords:
- highlight
- tokenize
- syntax
- code highlighting
- parallel highlighting
icon: code
---

Expand Down
4 changes: 3 additions & 1 deletion site/content/docs/reference/_index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Reference
description: Complete API documentation and specifications
description: Complete API documentation for Rosettes highlighting functions, token types, languages, and configuration
draft: false
weight: 50
lang: en
Expand All @@ -14,6 +14,8 @@ keywords:
- api
- reference
- documentation
- syntax highlighter api
- tokenization
menu:
main:
weight: 30
Expand Down
4 changes: 3 additions & 1 deletion site/content/docs/styling/_index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Styling
description: CSS classes, themes, and visual customization
description: CSS classes, themes, and visual customization for Rosettes and Pygments-compatible output
draft: false
weight: 30
lang: en
Expand All @@ -16,6 +16,8 @@ keywords:
- themes
- styling
- colors
- pygments themes
- syntax highlighting css
icon: palette
---

Expand Down
7 changes: 5 additions & 2 deletions site/content/docs/tutorials/_index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Tutorials
description: Step-by-step guides for common scenarios
description: Step-by-step guides for common Rosettes workflows, styling, and migration scenarios
draft: false
weight: 45
lang: en
Expand All @@ -13,12 +13,15 @@ keywords:
- tutorials
- guides
- learning
- pygments migration
- code highlighting
icon: notepad
---

# Tutorials

Step-by-step guides for common Rosettes use cases.
Step-by-step guides for common Rosettes use cases, migration paths, and highlighting
workflows.

## Available Tutorials

Expand Down
Loading
Loading