diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 264e27a..ca0966c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 + language: system + types: [python] + pass_filenames: false - id: ty name: ty type checker entry: uv run ty check src/rosettes/ diff --git a/README.md b/README.md index 2fdcd94..15552b0 100644 --- a/README.md +++ b/README.md @@ -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 @@ -17,9 +17,10 @@ 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 @@ -27,6 +28,14 @@ Rosettes is a syntax highlighter for Python 3.14t. Hand-written state machines, - **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 @@ -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/) | diff --git a/pyproject.toml b/pyproject.toml index b2c2c12..b505133 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" }] @@ -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" diff --git a/site/content/_index.md b/site/content/_index.md index b87c9c8..27da52f 100644 --- a/site/content/_index.md +++ b/site/content/_index.md @@ -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 @@ -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 @@ -38,7 +41,7 @@ html = highlight("def hello(): print('world')", "python") --- -## What's good about it +## Why Use Rosettes :::{cards} :columns: 2 @@ -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 diff --git a/site/content/docs/_index.md b/site/content/docs/_index.md index 0b28836..0981471 100644 --- a/site/content/docs/_index.md +++ b/site/content/docs/_index.md @@ -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: @@ -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 @@ -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 @@ -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} @@ -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} diff --git a/site/content/docs/about/_index.md b/site/content/docs/about/_index.md index 1970dac..c089cc3 100644 --- a/site/content/docs/about/_index.md +++ b/site/content/docs/about/_index.md @@ -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 @@ -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 diff --git a/site/content/docs/about/comparison.md b/site/content/docs/about/comparison.md index b0541d3..7ffbe35 100644 --- a/site/content/docs/about/comparison.md +++ b/site/content/docs/about/comparison.md @@ -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 @@ -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 @@ -28,6 +31,7 @@ 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 @@ -35,6 +39,7 @@ Rosettes is a good fit when you need syntax highlighting with predictable perfor - 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 diff --git a/site/content/docs/about/thread-safety.md b/site/content/docs/about/thread-safety.md index ea72d63..a29fbfd 100644 --- a/site/content/docs/about/thread-safety.md +++ b/site/content/docs/about/thread-safety.md @@ -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()` diff --git a/site/content/docs/get-started/_index.md b/site/content/docs/get-started/_index.md index 54bffcf..1640997 100644 --- a/site/content/docs/get-started/_index.md +++ b/site/content/docs/get-started/_index.md @@ -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 @@ -12,6 +12,9 @@ keywords: - getting started - installation - quickstart +- python syntax highlighter +- code highlighting +- pygments alternative category: onboarding cascade: type: doc diff --git a/site/content/docs/highlighting/_index.md b/site/content/docs/highlighting/_index.md index f840beb..a846f49 100644 --- a/site/content/docs/highlighting/_index.md +++ b/site/content/docs/highlighting/_index.md @@ -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 @@ -14,6 +14,8 @@ keywords: - highlight - tokenize - syntax +- code highlighting +- parallel highlighting icon: code --- diff --git a/site/content/docs/reference/_index.md b/site/content/docs/reference/_index.md index a935783..ada493a 100644 --- a/site/content/docs/reference/_index.md +++ b/site/content/docs/reference/_index.md @@ -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 @@ -14,6 +14,8 @@ keywords: - api - reference - documentation +- syntax highlighter api +- tokenization menu: main: weight: 30 diff --git a/site/content/docs/styling/_index.md b/site/content/docs/styling/_index.md index 6a1c76e..2071245 100644 --- a/site/content/docs/styling/_index.md +++ b/site/content/docs/styling/_index.md @@ -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 @@ -16,6 +16,8 @@ keywords: - themes - styling - colors +- pygments themes +- syntax highlighting css icon: palette --- diff --git a/site/content/docs/tutorials/_index.md b/site/content/docs/tutorials/_index.md index fc90f10..5d630db 100644 --- a/site/content/docs/tutorials/_index.md +++ b/site/content/docs/tutorials/_index.md @@ -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 @@ -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 diff --git a/src/rosettes.egg-info/PKG-INFO b/src/rosettes.egg-info/PKG-INFO index 5d018a7..3d83ebc 100644 --- a/src/rosettes.egg-info/PKG-INFO +++ b/src/rosettes.egg-info/PKG-INFO @@ -47,7 +47,7 @@ Rosettes is a syntax highlighter for Python 3.14t. Hand-written state machines, - **O(n) guaranteed** — Hand-written state machines, no regex backtracking - **Zero ReDoS** — No exploitable patterns, safe for untrusted input -- **Thread-safe** — Immutable state, optimized for Python 3.14t free-threading +- **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 @@ -252,7 +252,15 @@ On a 10,000-line Python file: - **Tokenize** — ~12ms - **Highlight** — ~18ms -- **Parallel (8 blocks)** — ~22ms (1.5–2x speedup on Python 3.14t free-threading) +- **Parallel highlighting** — Run `python benchmarks/benchmark_parallel.py` to see scaling on your machine. Example with 100 code blocks on 8-core: + + ``` + Threads Time Speedup + 1 0.04s 1.00x + 2 0.02s 1.61x + 4 0.02s 2.53x + 8 0.02s 2.10x + ``` --- @@ -279,6 +287,12 @@ uv sync --group dev pytest ``` +**Run parallel benchmark** (free-threading scaling demo): + +```bash +python benchmarks/benchmark_parallel.py +``` + --- ## The Bengal Ecosystem