crystal-rouge

Pure Crystal syntax highlighter, port of the Rouge Ruby gem. Tokenization engine with RegexLexer, HTML formatter, and CSS themes.

= crystal-rouge :toc: left :toclevels: 2

Pure Crystal syntax highlighter, port of the https://github.com/rouge-ruby/rouge[Rouge] Ruby gem. Compatible with Pygments token types and Rouge CSS classes.

link:README.fr.adoc[Version française]

== Features

  • Tokenization engine (RegexLexer) with stack-based state machine
  • 233 language lexers (full coverage of Rouge 4.7.0)
  • HTML formatter with CSS class names compatible with Rouge/Pygments
  • GitHub CSS theme included
  • Single-function API: Rouge.highlight(code, "language")

== Supported Languages

[cols="2,2"] |=== | Language | Tag(s)

| C | c | Crystal | crystal | CSS | css | Dart | dart | Diff | diff, patch | Dockerfile | dockerfile, docker | Elixir | elixir, ex | Go | go, golang | GraphQL | graphql | Haskell | haskell, hs | HTML | html | INI | ini, cfg, properties | Java | java | JavaScript | javascript, js | JSON | json | Kotlin | kotlin, kt | Lua | lua | Makefile | makefile, make | Markdown | markdown, md | Nginx | nginx | Perl | perl, pl | PHP | php | PowerShell | powershell, posh, ps1 | Protobuf | protobuf, proto | Python | python, py | R | r, R, rlang | Ruby | ruby, rb | Rust | rust, rs | Scala | scala | SCSS | scss, sass | Shell/Bash | shell, bash, sh, zsh | SQL | sql | Swift | swift | Terraform | terraform, tf, hcl | TOML | toml | TypeScript | typescript, ts | XML | xml | YAML | yaml, yml | Zig | zig |===

== Installation

[source,yaml]

dependencies: crystal-rouge: github: aloli-crystal/crystal-rouge version: "~> 0.1"

== Usage

[source,crystal]

require "rouge"

Highlight code to HTML

html = Rouge.highlight("SELECT * FROM users", "sql")

Or step by step

lexer = Rouge::RegexLexer.find("crystal").not_nil! tokens = lexer.lex("puts "Hello, World!"") html = Rouge::Formatters::HTML.new.format_wrapped(tokens)

Get CSS for the GitHub theme

css = Rouge::Themes::Github.render(scope: ".highlight")

== Tests

[source,bash]

crystal spec

792 examples, 0 failures.

== License

MIT

Repository

crystal-rouge

Owner
Statistic
  • 1
  • 0
  • 0
  • 5
  • 1
  • 5 days ago
  • April 12, 2026
License

MIT License

Links
Synced at

Mon, 13 Apr 2026 17:13:07 GMT

Languages