GithubHelp home page GithubHelp logo

kaytie / rainbow Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ccampbell/rainbow

0.0 2.0 0.0 954 KB

Simple syntax highlighting library written in javascript

Home Page: http://craig.is/making/rainbows

License: Apache License 2.0

rainbow's Introduction

Rainbow

Rainbow is a code syntax highlighting library written in Javascript.

It was designed to be lightweight (1.4kb), easy to use, and extendable.

It is completely themable via CSS.

If you would like to donate to help support Rainbow development use Gittip.

Quick Start

  1. Include some markup for code you want to be highlighted:

    <pre><code data-language="python">def openFile(path):
        file = open(path, "r")
        content = file.read()
        file.close()
        return content</code></pre>
  2. Include a CSS theme file in the <head>:

    <link href="/assets/css/theme.css" rel="stylesheet" type="text/css">
  3. Include rainbow.js and whatever languages you want before the closing </body>:

    <script src="/assets/js/rainbow.min.js"></script>
    <script src="/assets/js/language/generic.js"></script>
    <script src="/assets/js/language/python.js"></script>

Extending Rainbow

If you have a language specific pattern that you want highlighted, but it does not exist in the language syntax rules you can add a rule on your page.

Let's say for example you want to reference PHP's apc functions. You can include the php language then in the markup on your page add:

<script>
    Rainbow.extend('php', [
        {
            'matches': {
                1: 'support.function'
            },
            'pattern': /\b(apc_(store|fetch|add|inc))(?=\()/g
        }
    ]);
</script>

Supported Languages

Currently supported languages are:

  • C
  • C#
  • Coffeescript
  • CSS
  • D
  • Go
  • Haskell
  • HTML
  • Java
  • Javascript
  • Lua
  • PHP
  • Python
  • R
  • Ruby
  • Scheme
  • Shell
  • Smalltalk

Building

Rainbow gets minified with the closure compiler. You can install it on OS X via Homebrew:

brew install closure-compiler

To build a minified version of your changes, you can run the compile script:

./util/compile.py --core

In case the compiler cannot be found (which is the case if you installed via Homebrew), you will have to specify the path to the compiler.jar (see brew info closure-compiler) - here's an example:

CLOSURE_COMPILER=/usr/local/Cellar/closure-compiler/20120710/libexec/build/compiler.jar util/compile.py --core

If you want to build a custom version, list the languages you would like to include as command line arguments:

util/compile.py ruby javascript

Tests

Unit tests run via mocha.

Running in browser

Download the repo and go to tests/rainbow.html in your browser.

Running with Grunt and PhantomJS

  1. Install grunt-cli

    npm install -g grunt-cli
  2. Install npm packages

    cd /path/to/repo
    npm install
  3. Run tests

    grunt mocha

More Info

If you are looking for line number support you can try one of the following:

You can check out additional documentation and build custom packages at rainbowco.de.

rainbow's People

Contributors

actsasflinn avatar asandroq avatar bbqsrc avatar ccampbell avatar chuckharmston avatar colinwren avatar davidlitmark avatar eikimart avatar fasani avatar firien avatar frankshearar avatar geertdd avatar idleberg avatar javaguirre avatar jfarmer avatar loopj avatar mking avatar okcoker avatar orangeduck avatar rachelbaker avatar sjp avatar workhorsy avatar yonjah avatar

Watchers

 avatar  avatar

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.