The Null Formatter yields raw, unformatted text.
Usage
Use the"null"or"none"alias:
from rosettes import highlight
code = "def hello(): pass"
raw = highlight(code, "python", formatter="null")
print(raw == code) # True
Why use a Null Formatter?
While it may seem counter-intuitive for a syntax highlighter, the Null Formatter is useful for:
- Benchmarking: Measure the performance of lexers alone, excluding the overhead of HTML or ANSI formatting.
- Analysis: Process code through the tokenization pipeline without generating a styled output.
- Fallback: Provide a safe fallback when no highlighting is desired but you still want to use the
highlight()API. - Integration Testing: Verify that the tokenization process doesn't lose or alter any characters from the source code.
Performance
The Null Formatter uses the Fast Path exclusively, simply joining token values together. It is the fastest possible "formatting" path in Rosettes.
Next Steps
- Terminal Formatter — ANSI colors for consoles
- HTML Formatter — Optimized HTML output