vanGogh Syntax Highlighter

by secretgspot

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.4;
    padding: 20px 30px;
}

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

JavaScript

$(function() {
    // default
    $("#c").vanGogh();
    
    // without numbers/gutter and horizontal scrolling
    $("pre:eq(1), pre:eq(2)").vanGogh({ numbers: false });
    
    // inline highlighting
    $("code.inline").vanGogh();
    
    // remote source
    $("#r").vanGogh({ source: "/mekwall/pMZge/show/", maxLines: 20 });
});