This repository has been archived by the owner. It is now read-only.

syntaxer

Multi-backend syntax highlighter for Crystal

syntaxer

Multi-backend syntax highlighter for Crystal

syntaxer Demo

Themes demo

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      syntaxer:
        github: mishushakov/syntaxer
    
  2. Run shards install

  3. Install highlighting backend(s)

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">&#39;hello world&#39;</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">&#39;hello world&#39;</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;">&#39;</span><span style="color:#a3be8c;">hello world</span><span style="color:#c0c5ce;">&#39;</span></pre>

Development

TODO: Write development instructions here

Contributing

  1. Fork it (https://github.com/mishushakov/syntaxer/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Repository

syntaxer

Owner
Statistic
  • 13
  • 1
  • 0
  • 0
  • 0
  • over 2 years ago
  • October 20, 2021
License

MIT License

Links
Synced at

Sat, 04 May 2024 03:31:53 GMT

Languages