Skip to content

hatefulcrawdad/rainbow

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
  • Go
  • HTML
  • Java
  • Javascript
  • Lua
  • PHP
  • Python
  • R
  • Ruby
  • Scheme
  • Shell
  • Smalltalk

More Info

If you are looking for line number support you can try https://github.com/Sjeiti/rainbow.linenumbers

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

About

Simple syntax highlighting library written in javascript

Resources

License

Stars

Watchers

Forks

Packages

No packages published