Multi-backend syntax highlighter for Crystal
-
Add the dependency to your
shard.yml
:dependencies: syntaxer: github: mishushakov/syntaxer
-
Run
shards install
-
Install highlighting backend(s)
SourceHighlight
requires source-highlightHighlight
requires highlightPygments
requires pygmentsSyntect
requires syntect-cli
require "syntaxer"
def self.highlight(code : String, lang : String, theme : String = "default.css", format : String = "html", params : Array(String) = [] of String)
Syntaxer::SourceHighlight.highlight(code: "print 'hello world'", lang: "python")
Output
<pre><tt><font color="#ffff60">print</font><font color="#C7C7C7"> </font><font color="#ffa0a0">'hello world'</font></tt></pre>
def self.highlight(code : String, lang : String, theme : String = "base16/monokai", inline_style : Bool = true, format : String = "html", wrap : Bool = true, params : Array(String) = [] of String)
Syntaxer::Highlight.highlight(code: "print 'hello world'", lang: "python")
Output
<pre style="color:#f8f8f2; background-color:#272822; font-size:10pt; font-family:'Courier New',monospace;white-space: pre-wrap;"><span style="color:#ae81ff; font-weight:bold">print</span> <span style="color:#a6e22e">'hello world'</span>
</pre>
def self.highlight(code : String, lang : String, theme : String = "default", inline_style : Bool = true, format : String = "html", wrap : Bool = true, params : String = "")
Syntaxer::Pygments.highlight(code: "print 'hello world'", lang: "python")
Output
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000">print</span> <span style="color: #BA2121">'hello world'</span>
</pre></div>
def self.highlight(code : String, lang : String, theme : String = "base16-ocean.dark")
Syntaxer::Syntect.highlight(code: "print 'hello world'", lang: "py")
Output
<pre style="background-color:#2b303b;">
<span style="color:#b48ead;">print </span><span style="color:#c0c5ce;">'</span><span style="color:#a3be8c;">hello world</span><span style="color:#c0c5ce;">'</span></pre>
TODO: Write development instructions here
- Fork it (https://github.com/mishushakov/syntaxer/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Mish Ushakov - creator and maintainer