• This repository has been archived on 06/May/2019
  • Stars
    star
    131
  • Rank 275,867 (Top 6 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 14 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Syntax Higlighting plugin for Ruby on Rails

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).

More Repositories

1

100-exercises-to-learn-rust

A self-paced course to learn Rust, one exercise at a time.
Rust
3,527
star
2

ember-simple-auth

A library for implementing authentication/authorization in Ember.js applications.
JavaScript
1,926
star
3

ember-test-selectors

Enabling better element selectors in Ember.js tests
JavaScript
262
star
4

rust-telemetry-workshop

Build a comprehensive toolkit to detect, troubleshoot and resolve issues with Rust applications.
Rust
224
star
5

qunit-dom

High Level DOM Assertions for QUnit
TypeScript
178
star
6

excellent

Source Code analysis gem for Ruby and Rails
Ruby
156
star
7

rails_api_auth

Lightweight Rails Engine that implements the "Resource Owner Password Credentials Grant" OAuth 2.0 flow as well as Facebook authentication
Ruby
139
star
8

cargo-autoinherit

(Auto)DRY for your Rust dependencies
Rust
124
star
9

ember-cookies

Cookies abstraction for Ember.js that works both in the browser as well as with Fastboot on the server
JavaScript
115
star
10

rust-advanced-testing-workshop

A course to move beyond the built-in Rust testing toolkit.
Rust
95
star
11

ast-workshop

"Abstract Syntax Forestry" workshop for EmberConf 2020
JavaScript
86
star
12

breethe-client

Air Quality Data for Locations around the World
JavaScript
75
star
13

ember-cli-simple-auth

Ember CLI Adon for the Ember Simple Auth library
JavaScript
54
star
14

ember-intl-analyzer

Find missing or unused translations in your Ember.js projects
JavaScript
48
star
15

ember-hbs-minifier

Stripping whitespace out of your Handlebars templates
JavaScript
48
star
16

ember-validated-form-buffer

A validated form buffer that wraps Ember Data models for use in forms.
JavaScript
47
star
17

continue-on-error-comment

GitHub action to add comment when a continue-on-error job fails
JavaScript
41
star
18

breethe-server

Air Quality Data for Locations around the World
Elixir
40
star
19

rust-python-interoperability

A self-paced course to write Python extensions in Rust, one exercise at a time.
Rust
32
star
20

ember-promise-modals

The easy solution for rendering and handling modals in Ember.js apps. Promised.
JavaScript
31
star
21

ember-simple-auth-example

Example project showing how to use Ember Simple Auth with Ember CLI
JavaScript
30
star
22

svelte-promise-modals

Modals in Svelte made easy. Promised.🤞
Svelte
26
star
23

qunit-console-grouper

QUnit plugin that groups console messages by test
JavaScript
22
star
24

ember-cli-simple-auth-devise

Ember CLI Addon for the Ember Simple Auth Devise package
JavaScript
22
star
25

ember-asset-size-action

Comment with the diff for the asset sizes on Pull Request
JavaScript
22
star
26

ember-cli-simple-auth-oauth2

Ember CLI Addon for the Ember Simple Auth OAuth 2.0 package
JavaScript
20
star
27

ember-cli-deploy-webhooks

Ember CLI Deploy plugin for calling webhooks during deployments
JavaScript
19
star
28

rust-workshop-runner

A CLI tool to drive test-driven Rust workshops
Rust
17
star
29

ember-classy-computed

An Ember addon for Class based Computed Properties
JavaScript
16
star
30

mainmatter.com

The source code for https://mainmatter.com
Nunjucks
16
star
31

qunit-dom-codemod

Basic codemod to automatically convert your assertions to qunit-dom assertions
JavaScript
14
star
32

eslint-plugin-ember-concurrency

ESLint plugin for ember-concurrency users
JavaScript
13
star
33

playbook

A book describing the patterns and practices that Mainmatter uses to build lasting products, systematically.
HTML
13
star
34

ember-workshop

The example apps for simplabs' Ember.js Workshop
12
star
35

ember-cli-pixijs

An Ember CLI Addon that wraps pixi.js
JavaScript
12
star
36

emblem-migrator

Migrate Emblem.js to pretty Handlebars files
JavaScript
9
star
37

ember-cli-simple-auth-testing

Ember CLI Addon for the Ember Simple Auth Testing package
JavaScript
9
star
38

ember-cli-simple-auth-cookie-store

Ember CLI Addon for the Ember Simple Auth Cookie Store package
JavaScript
8
star
39

testem-gitlab-reporter

GitLab/JUnit reporter for testem
JavaScript
8
star
40

rails_api_auth-demo

Demo project using the rails_api_auth engine
Ruby
7
star
41

ember-auto-computed

JavaScript
7
star
42

ember-cli-simple-auth-torii

Ember CLI Addon for the Ember Simple Auth Torii package
JavaScript
7
star
43

ember-template-lint-plugin-css-modules

ember-template-lint plugin for ember-css-modules
JavaScript
7
star
44

ember-api-actions

Ember.js addon allowing you to easily implement non-CRUD actions for your Ember Data models
JavaScript
6
star
45

ember-error-route

JavaScript
6
star
46

mainmatter-website-mailer

Mailer for the contact form on mainmatter.com – Cloudflare worker written in Rust
Rust
5
star
47

ember-hotspots

Create interactive prototypes from scratch and design mockups using little code but the full power of the Ember.js ecosystem.
JavaScript
5
star
48

ember-scroll

A sensible default implementation of scrolling for Ember apps, aiming to mimic static site behaviour.
JavaScript
4
star
49

asset-size-reporter

Generic asset size comparison and reporting tool
JavaScript
4
star
50

mocha-diff

Mocha's diff algorithm extracted for anyone to use 🎉
JavaScript
4
star
51

svelte-workshop-music-player

JavaScript
4
star
52

ember-simple-auth-component

Bower repository for Ember Simple Auth
JavaScript
4
star
53

sheepdog

Sheepdog...herd you async task!
MDX
3
star
54

eslint-plugin-qunit-dom

An ESLint plugin for qunit-dom that automatically fixes the most common issues.
JavaScript
2
star
55

compare-fixture

JavaScript
1
star
56

ember-cli-list-addons

JavaScript
1
star
57

git-workshop

1
star
58

eslint-config-simplabs

ESLint config for all simplabs projects
JavaScript
1
star
59

auto-reveal

JavaScript
1
star
60

auto-reveal-theme-mainmatter

CSS
1
star
61

sveltekit-super-rentals

JavaScript
1
star
62

who-ran-me

Small utillity to check if script was run with npm or yarn
JavaScript
1
star