vanGogh Syntax Highlighter

Original: http://jsfiddle.net/mekwall/pMZge/

by Jens Grochtdreis

HTML

<script src="https://raw.github.com/mekwall/jquery-vangogh/master/src/jquery.vangogh.min.js"></script>
<h1>vanGogh - express your code in color</h1>

<h2>default functionality</h2>

<p>This is the default look and behavior of vanGogh. You can highlight individual lines by clicking its line number, and even multiple lines by ctrl or shift clicking. Double-clicking the code container will (if supported by the browser) select all code for easy copying.</p>

<pre id="c"><code class="language-javascript">// Van Gogh; express your code in color
var setArray = function(elems) {
    this.length = 0; // This is a comment
    push.apply(this, elems);
    return this;
}

var aString = "Hello world!";</code></pre>

<br>

<h2>without gutter</h2>

<pre><code class="javascript">// Van Gogh; express your code in color
var setArray = function(elems) {
    this.length = 0; // This is a comment
    push.apply(this, elems);
    return this;
}

var foo = "Hello world!";</code></pre>

<br />

<h2>inline highlighting</h2>

<p>You can easily highlight inline code as well, like this: <code class="inline javascript">var foo = "Hello world!";</code></p>

<h2>horizontal scrolling</h2>

<pre style="width: 200px;"><code class="language-javascript">var foo = "This is a very long line that will allow you to horizontally scroll the container";</code></pre>

<br />

<h2>remote source file</h2>

<pre id="r"><code></code></pre>

<br />

CSS

body, html {
    font: 13.34px helvetica,arial,freesans,clean,sans-serif;
}
 
body * {
    line-height: 1.4em;
}
 
p { margin: 1em 0; font-size: 1.1em; }
 
h1 {
    margin-bottom: 0;
    font-size: 30px;
    height: 54px;
    line-height: 54px;
    font-weight: bold;
    letter-spacing: -1px;
    text-shadow: 1px 1px 0 white;
    color: #495961;
}
 
h2 {
    color: #4183C4;
    font-size: 1.9em;
    height: 2em;
    line-height: 2em;
    font-weight: bold;
}

/* here thy artist beginst hast work */
.vg-container {
    position: relative;
    overflow: auto;
}
 
.vg-container,
.vg-code {
    border: 0;
    margin: 0;
}
 
.vg-container .vg-line,
.vg-container .vg-number {
    display: block;
    height: 1.5em;
    line-height: 1.5em !important;
}
 
.vg-gutter {
    float: left;
    min-width: 20px;
    width: auto;
    -o-user-select: none;
    -webkit-user-select: none;
    -moz-user-select: -moz-none;
    -khtml-user-select: none;
    -ms-user-select: none;
    user-select: none;
}
 
.vg-number {
    cursor: pointer;
}
 
/*
github.com style (c) Vasily Polovnyov <[email protected]>
extended and modified for vanGogh by Marcus Ekwall <[email protected]>
*/
 
.vg-container {
    font-family: 'Bitstream Vera Sans Mono', 'Courier New', monospace;
    font-size: 12px;
    border: 1px solid #ddd;
}
 
.vg-gutter {
    background-color: #ececec;
    border-right: 1px solid #ddd;
    text-align: right;
    color: #aaa;
    padding: 1em .5em;
    margin-right: .5em;
}

.vg-code *::-moz-selection,
.vg-code *::-webkit-selection,
.vg-code *::selection,
.vg-line.vg-highlight {
    background-color: #ffc;
}
 
.vg-line span.vg-highlight {
    color: blue;
    font-weight: bold;
    text-decoration: underline;
}
 
.vg-container .vg-code {
    display: block;
    padding: 1em .5em;
    background: #fff;
}
 
.vg-code {
    color: #000;
    background: #f8f8ff;
    border: 0;
    padding: .4em;
}
 
.vg-code .comment,
.vg-code .template_comment,
.vg-code .diff .header,
.vg-code...

JavaScript

(function($, window, hljs){
    // one can become many
    var painters = 1,
        waitForLoad = false,
        waitForSource = false;
    
    // tool to parse/manipulate hash
    var hashTool = {
        get: function(id) {
            var hash = window.location.hash;
            if (hash.length > 0) {
                var match = hash.match(new RegExp(id+":{([a-zA-Z0-9,-]*)}"));
                if (match) {
                    return match[1].split(",");
                }
            }
            return [];
        },
        set: function(id, hl) {
            var hash = window.location.hash,
                newHash, addHash = id+":{"+hl.join(",")+"}",
                match = hash.indexOf(id+":{");
            
            if (hl.length === 0) {
                return this.remove(id);
            }
            if (match !== -1) {
                newHash = hash.replace(
                    new RegExp("("+id+":{[a-zA-Z0-9,-]*})"),
                    addHash
                );
            } else {
                newHash = (hash.length > 0) ? hash+","+addHash : addHash;
            }
            window.location.hash = newHash;
        },
        remove: function(id) {
            window.location.hash = window.location.hash.replace(
                new RegExp("([,]?"+id+":{[a-zA-Z0-9,-]*}[,]?)"),
                ""
            );
        }
    };

    // hey vincent!
    $.fn.vanGogh = function(options){
        var defaults = {
            language: "auto",
            firstLine: 1,
            maxLines: 0,
            numbers: true,
            highlight: null,
            animateGutter: true,
            autoload: "http://softwaremaniacs.org/media/soft/highlight/highlight.pack.js",
            tab: "    "
        };
        // merge defaults and passed options
        options = $.extend({}, defaults, options);
        
        // scope vars
        var elems = this,
            run = 0,
            remoteData;
        
        // cross-browser compatible...