Skip to content

Commit

Permalink
[api] Added code highlighting.
Browse files Browse the repository at this point in the history
[dist] Vendored highlight.js library
  • Loading branch information
Marak committed Aug 26, 2011
1 parent 857ccb6 commit d91950f
Show file tree
Hide file tree
Showing 44 changed files with 6,699 additions and 3 deletions.
6 changes: 6 additions & 0 deletions lib/generators/article.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var findit = require('findit'),
path = require('path'),
hl = require('../../vendor/highlight/lib/highlight').Highlight,
markdown = require('markdown'),
mkdirp = require('mkdirp'),
fs = require('fs'),
Expand Down Expand Up @@ -51,7 +52,12 @@ article.weld = function(dom, articles) {
return false;
}
});

// perform code highlighting
// convert only inside <code/>
dom.innerHTML = hl(dom.innerHTML, false, true);
articles[i].content = dom.innerHTML;

});
return dom;
};
Expand Down
4 changes: 3 additions & 1 deletion theme/article.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

<!-- required content -->

<link rel="stylesheet" href="/nodedocs.css" type="text/css" media="screen" title="no title" charset="utf-8">
<link rel="stylesheet" href="/css/nodedocs.css" type="text/css" media="screen" title="no title" charset="utf-8">
<link rel="stylesheet" href="/css/highlight/github.css" type="text/css" media="screen" title="no title" charset="utf-8">


<header>
<div class="title">docs.nodejitsu.com </div>
Expand Down
File renamed without changes.
File renamed without changes.
129 changes: 129 additions & 0 deletions theme/css/highlight/github.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
github.com style (c) Vasily Polovnyov <[email protected]>
*/

pre code {
display: block; padding: 0.5em;
color: #000;
background: #f8f8ff
}

pre .comment,
pre .template_comment,
pre .diff .header,
pre .javadoc {
color: #998;
font-style: italic
}

pre .keyword,
pre .css .rule .keyword,
pre .winutils,
pre .javascript .title,
pre .lisp .title,
pre .subst {
color: #000;
font-weight: bold
}

pre .number,
pre .hexcolor {
color: #40a070
}

pre .string,
pre .tag .value,
pre .phpdoc,
pre .tex .formula {
color: #d14
}

pre .title,
pre .id {
color: #900;
font-weight: bold
}

pre .javascript .title,
pre .lisp .title,
pre .subst {
font-weight: normal
}

pre .class .title,
pre .haskell .label,
pre .tex .command {
color: #458;
font-weight: bold
}

pre .tag,
pre .tag .title,
pre .rules .property,
pre .django .tag .keyword {
color: #000080;
font-weight: normal
}

pre .attribute,
pre .variable,
pre .instancevar,
pre .lisp .body {
color: #008080
}

pre .regexp {
color: #009926
}

pre .class {
color: #458;
font-weight: bold
}

pre .symbol,
pre .ruby .symbol .string,
pre .ruby .symbol .keyword,
pre .ruby .symbol .keymethods,
pre .lisp .keyword,
pre .tex .special,
pre .input_number {
color: #990073
}

pre .builtin,
pre .built_in,
pre .lisp .title {
color: #0086b3
}

pre .preprocessor,
pre .pi,
pre .doctype,
pre .shebang,
pre .cdata {
color: #999;
font-weight: bold
}

pre .deletion {
background: #fdd
}

pre .addition {
background: #dfd
}

pre .diff .change {
background: #0086b3
}

pre .chunk {
color: #aaa
}

pre .tex .formula {
opacity: 0.5;
}
File renamed without changes.
2 changes: 1 addition & 1 deletion theme/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<!-- required content -->
<html>
<link rel="stylesheet" href="nodedocs.css" type="text/css" media="screen" title="no title" charset="utf-8">
<link rel="stylesheet" href="css/nodedocs.css" type="text/css" media="screen" title="no title" charset="utf-8">

<header>
<div class="title"><a href="http://docs.nodejitsu.com">docs.nodejitsu.com</a></div>
Expand Down
2 changes: 1 addition & 1 deletion theme/toc.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<!-- required content -->

<link rel="stylesheet" href="nodedocs.css" type="text/css" media="screen" title="no title" charset="utf-8">
<link rel="stylesheet" href="css/nodedocs.css" type="text/css" media="screen" title="no title" charset="utf-8">

<header>
<div class="title">docs.nodejitsu.com </div>
Expand Down
29 changes: 29 additions & 0 deletions vendor/highlight/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Copyright (c) 2010, Andris Reinman
<http://www.andrisreinman.com/>
All rights reserved.

Original Highlight.js Copyright (c) 2006, Ivan Sagalaev
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of highlight.js nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 changes: 37 additions & 0 deletions vendor/highlight/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
highlight
==============

**highlight** for node.js is based on [highlight.js](http://softwaremaniacs.org/soft/highlight/en/) parser and is meant to highlight code syntax in languages that are not known beforehand (*highlight.js* detects the used language automatically). This is especially important for pages in Markdown format - there's no easy way to know which language is actually used.

Installation
------------

Use `npm` package manager

npm install highlight

Usage
-----

Include syntax highlighter

var hl = require("highlight").Highlight;

highlight code

html = hl("for(var i=0;i<10;i++)alert(i);");

use special tab replacing string (default is 4 spaces)

html = hl(code_string, "<span> </span>");

convert code only between &lt;code&gt; blocks (leaves everything else as is) - especially useful if used together with converted [Markdown](/andris9/node-markdown) syntax that includes &lt;code&gt; blocks.

html = hl("<p>PHP:</p><code><?php echo 'Hello world!';?></code>", false, true);

Styles
------

**highlight** outputs HTML code with predefined CSS class names for different elements. This doesn't make a lot of sense by default (it's just a bunch of SPAN's) so you need to use a CSS file that sets the used color set for the highlighting. There's some sample CSS files in /lib/vendor/highlight.js/styles that can be used with no modification - just include one of the files in the page you are showing the highlighted code.

<link rel="stylesheet" href="/path/to/styles/default.css"/>
25 changes: 25 additions & 0 deletions vendor/highlight/examples/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


var hl = require("../lib/highlight.js").Highlight,
code_string = "<?php\n"+
"\techo \"Hello world!\";\n"+
"\tfor($i=0;$i<100;$i++){\n"+
"\t\techo \"$i\";\n"+
"\t}\n"+
"?>",

code_block = "<p>PHP code:</p>\n"+
"<code><?php\n"+
"\techo \"Hello world!\";\n"+
"\tfor($i=0;$i<100;$i++){\n"+
"\t\techo \"$i\";\n"+
"\t}\n"+
"?></code>",

html1 = hl(code_string), // convert all
html2 = hl(code_string,' '), // convert with special tab replacer
html3 = hl(code_block, false, true); // convert only inside <code/>

console.log(html1);
console.log(html2);
console.log(html3);
33 changes: 33 additions & 0 deletions vendor/highlight/lib/highlight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* node-highlight is based on highlight.js (see vendor/highlight.js) */
/* usage: html = require("highlight").Highlight(code_string); */
/* NB! You also need to include a CSS file from vendor/highlight.js/styles */

// load syntax highlighter
var hljs = require("./vendor/highlight.js/highlight").hljs;

// load langs
require("./vendor/highlight.js/languages/bash")(hljs);
require("./vendor/highlight.js/languages/javascript")(hljs);
require("./vendor/highlight.js/languages/ruby")(hljs);



/**
* highlight(text, tabReplace, useCodeBlocks) -> HTML
* - text (String): text to be highlighted
* - tabReplace (String): defaults to 4 spaces if none, replaces \t chars
* - useCodeBlocks (Boolean): If TRUE use only text between <code> and </code>
*
* Highlights program code inside a string by setting appropriate CSS class
* elements.
**/
this.Highlight = function(text, tabReplace, useCodeBlocks){
tabReplace = tabReplace || ' ';
if(!!useCodeBlocks){
// JS regexpes have some multiline issues, so we temporarily remove them
return text.replace(/\n/g,'\uffff').replace(/<code>(.*?)<\/code>/gm, function(original, source){
return '<code>'+hljs.highlightText(source.replace(/\uffff/g,"\n"), tabReplace)+'</code>';
}).replace(/&amp;(\w+;)/g,'&$1').replace(/\uffff/g,"\n");
}else
return hljs.highlightText(text, tabReplace);
}
45 changes: 45 additions & 0 deletions vendor/highlight/lib/vendor/highlight.js/AUTHORS.en.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Syntax highlighting with language autodetection.

URL: http://softwaremaniacs.org/soft/highlight/en/

Original author and current maintainer:
Ivan Sagalaev <[email protected]>

Contributors:

- Peter Leonov <[email protected]>
- Victor Karamzin <[email protected]>
- Vsevolod Solovyov <[email protected]>
- Anton Kovalyov <[email protected]>
- Nikita Ledyaev <[email protected]>
- Konstantin Evdokimenko <[email protected]>
- Dmitri Roudakov <[email protected]>
- Yuri Ivanov <[email protected]>
- Vladimir Ermakov <[email protected]>
- Vladimir Gubarkov <[email protected]>
- Brian Beck <[email protected]>
- MajestiC <[email protected]>
- Vasily Polovnyov <[email protected]>
- Vladimir Epifanov <[email protected]>
- Alexander Makarov (http://rmcreative.ru/)
- Vah <[email protected]>
- Shuen-Huei Guan <[email protected]>
- Jason Diamond <[email protected]>
- Michal Gabrukiewicz <[email protected]>
- Ruslan Keba <[email protected]>
- Sergey Baranov <[email protected]>
- Zaripov Yura <[email protected]>
- Oleg Volchkov <[email protected]>
- Vasily Mikhailitchenko <[email protected]>
- Jan Berkel <[email protected]>
- Vladimir Moskva <[email protected]>
- Loren Segal <[email protected]>
- Andrew Fedorov <[email protected]>
- Igor Kalnitsky <[email protected]>
- Jeremy Hull <[email protected]>
- Valerii Hiora <[email protected]>
- Nikolay Zakharov <[email protected]>
- Dmitry Kovega <[email protected]>
- Sergey Ignatov <[email protected]>
- Antono Vasiljev <[email protected]>
- Stephan Kountso <[email protected]>
Loading

0 comments on commit d91950f

Please sign in to comment.