Rosettes provides two core functions:highlight()for HTML output andtokenize()for raw tokens.
Overview
| Function | Purpose | Returns |
|---|---|---|
highlight() |
Generate HTML with syntax highlighting | str(HTML) |
tokenize() |
Get raw tokens for custom processing | list[Token] |
highlight_many() |
Parallel highlighting for multiple blocks | list[str] |
tokenize_many() |
Parallel tokenization | list[list[Token]] |
Quick Example
from rosettes import highlight, tokenize
# Get HTML output
html = highlight("def foo(): pass", "python")
# Get raw tokens
tokens = tokenize("def foo(): pass", "python")
for token in tokens:
print(f"{token.type}: {token.value!r}")