Ruby 3.1+ · Rouge 5
Highlight the edit. Keep the rest.
Antares gives Rouge line-oriented, edit-aware syntax highlighting. Restore measured lexer state, scan until output converges, and reuse the untouched suffix.
# checkpoint restored at line 64
+ status = :ready
highlighter.edit(
from_line: 128, removed: 1, inserted: 1
)
# state converged — cached suffix reused
checkpoint 64
edit 128
converged 131
- Lexers measured
- 234
- Incremental
- 110
- Bounded window
- 124
- Runtime dependency
- 1
Work follows the edit
Each request does only the lexical work needed to prove the current lines are correct.
- 1Restore
Resume from the nearest reusable lexer-state checkpoint.
- 2Scan
Tokenize forward from the changed line under explicit limits.
- 3Converge
Stop when lexer state and tokens match the cached document.
- 4Reuse
Keep the proven, untouched suffix instead of highlighting it again.
Add it to your editor
Keep document storage and colors in your application. Antares returns frozen Rouge token rows.
Full documentation
Gemfile
gem "antares"
Ruby
highlighter = Antares::Highlighter.new(
lexer: Rouge::Lexers::Python.new,
lines: ->(index) { lines[index] },
line_count: -> { lines.length }
)
highlighter.tokens_in(0..20)