Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Oct 30, 2022. It is now read-only.

mishushakov/syntaxer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

11 Commits

Repository files navigation

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

About

Multi-backend syntax highlighter for Crystal

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

AltStyle によって変換されたページ (->オリジナル) /