This repository has been archived by the owner. It is now read-only.
syntaxer
syntaxer
Multi-backend syntax highlighter for Crystal
Installation
-
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
Usage
require "syntaxer"
Syntaxer::SourceHighlight
Options
def self.highlight(code : String, lang : String, theme : String = "default.css", format : String = "html", params : Array(String) = [] of String)
Example
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>
Syntaxer::Highlight
Options
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)
Example
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>
Syntaxer::Pygments
Options
def self.highlight(code : String, lang : String, theme : String = "default", inline_style : Bool = true, format : String = "html", wrap : Bool = true, params : String = "")
Example
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>
Syntaxer::Syntect
Options
def self.highlight(code : String, lang : String, theme : String = "base16-ocean.dark")
Example
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>
Development
TODO: Write development instructions here
Contributing
- 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
Contributors
- Mish Ushakov - creator and maintainer
Repository
syntaxer
Owner
Statistic
- 13
- 1
- 0
- 0
- 0
- about 3 years ago
- October 20, 2021
License
MIT License
Links
Synced at
Sun, 22 Dec 2024 18:32:11 GMT
Languages