Git Product home page Git Product logo

highlight's Introduction

Highlight

Build Status

Highlight is a simple syntax highlighting gem for Ruby and Rails. It's basically a wrapper around the popular http://pygments.org highlighter that's written in Python and supports an impressive number of languages.

If pygments is installed on the machine and in the PATH, that binary is used, otherwise the plugin falls back to the web API at http://pygments.simplabs.com/, created by Trevor Turk.

See the API docs at http://rdoc.info/projects/simplabs/highlight.

Usage

Highlight can either be used standalone via

require 'simplabs/highlight'
Simplabs::Highlight.highlight(:ruby, 'class Test; end')

or in Rails where it adds the highlight_code helper:

highlight_code(language, code = nil, &block)

language may be either a Symbol or a String (see supported languages below). The code can be passed either as a string or inside a block, e.g.:

highlight_code(:ruby, 'class Test; end')

or

highlight_code(:ruby) do
  klass = 'class'
  name  = 'Test'
  _end  = 'end'
  "#{klass} #{name}; #{_end}"
end

Since highlighting the code takes a while, all highlighted source code should be cached, e.g.:

<%- code = 'class Test; end' -%>
<%- cache Digest::SHA1.hexdigest(code) do -%>
  <%= highlight_code(:ruby, code) -%>
<%- end -%>

Supported Languages

The following languages are supported (there are probably more that are supported by pygments). All of the paranthesized identifiers may be used as parameters for highlight to denote the language the source code to highlight is written in (use either Symbols or Strings).

  • Actionscript (as, as3, actionscript)
  • Applescript (applescript)
  • bash (bash, sh)
  • C (c, h)
  • Clojure (clojure)
  • C++ (c++, cpp, hpp)
  • C# (c#, csharp, cs)
  • CSS (css)
  • diff (diff)
  • Dylan (dylan)
  • Erlang (erlang, erl, er)
  • HTML (html, htm)
  • Java (java)
  • JavaScript (javascript, js, jscript)
  • JSP (jsp)
  • Make (make, basemake, makefile)
  • Objective-C (objective-c)
  • OCaml (ocaml)
  • Perl (perl, pl)
  • PHP (php)
  • Python (python, py)
  • RHTML (erb, rhtml)
  • Ruby (ruby, rb)
  • Scala (scala)
  • Scheme (scheme)
  • Smalltalk (smalltalk)
  • Smarty (smarty)
  • SQL (sql)
  • XML (xml, xsd)
  • XSLT (xslt)
  • YAML (yaml, yml)

Installation

Installation is as easy as

gem install highlight

To use highlight in Rails apps, you have to define the dependency in the Gemfile:

gem 'highlight', :require => 'simplabs/highlight'

Highlight also comes with a default CSS file that defines styles for the highlighted code. This CSS file can be copied to your application's public/stylesheets directory via

./bin/rails generate highlight_styles

If you don't have python and pygments installed, you will need that too. For instructions on installing pygments, refer to http://pygments.org/docs/installation/.

Author

Copyright (c) 2008-2010 Marco Otte-Witte (http://simplabs.com), released under the MIT license

Acknowledgements

The actual highlighting is done by Pygments (http://pygments.org).

highlight's People

Contributors

jarias avatar kilobyte22 avatar l8d avatar marcoow avatar mk avatar mysteriouspants avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

highlight's Issues

Generator highlight_styles cannot be found

$ gem install highlight
Successfully installed highlight-1.1.2
1 gem installed
Installing ri documentation for highlight-1.1.2...
Installing RDoc documentation for highlight-1.1.2...

$ rails generate highlight_styles
Could not find generator highlight_styles.

I tried this in a Rails 3.0.5 app and installed highlight also via bundler.

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can image, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post aobut this project for more information.

gem has bad permissions

It took me a while to track this down, but all the .rb files it the 1.1.2 version of the gem have 0600 as the permissions. This basically means the gem cannot be installed site-wide because if it's owned by a user with privilege's to install site-wide, it's not readable by anyone else. I can't think of any compelling reason to not at least make the permissions 0644, but if there are any, please let me know.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.