Ruby wrapper for javascript code highlighting libraries
HLJS allows to use javascript code highlighting libraries from ruby. Cool, huh?
It’s cooler than Pygments-based solution because it doesn’t need python. It’s cooler
than client-side highlighting because… I have no idea why, actually.
But anyways.
HLJS requires Ruby 1.9+ mainly because I’m too lazy porting it to 1.8. Also, I don’t even remember
when was the last time I used 1.8 for something other than running specs. Feel free to send
pull-request if you need 1.8 support.
Add this line to your application’s Gemfile:
gem 'hljs'
And then execute:
$ bundle
Or install it yourself as:
$ gem install hljs
For now only two adapters are supported: highlight.js
and SyntaxHighlighter.
HLJS.highlight source, language # => highlighted source
HLJS.supported_syntaxes # => the list of all supported syntaxes
Swithing adapters is quite straightforward:
>> HLJS.adapter = :highlightjs
=> #<HLJS::Adapters::HighlightJS:0x007ffb5a0a0a48 Version 7.3, 54 syntaxes supported>
>> HLJS.adapter = :syntaxhighlighter
=> #<HLJS::Adapters::SyntaxHighlighter:0x007fb35448a990 Version 3.0.83, 25 syntaxes supported>
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)