Skip to content

Commit d91950f

Browse files
committed
[api] Added code highlighting.
[dist] Vendored highlight.js library
1 parent 857ccb6 commit d91950f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+6699
-3
lines changed

lib/generators/article.js

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var findit = require('findit'),
22
path = require('path'),
3+
hl = require('../../vendor/highlight/lib/highlight').Highlight,
34
markdown = require('markdown'),
45
mkdirp = require('mkdirp'),
56
fs = require('fs'),
@@ -51,7 +52,12 @@ article.weld = function(dom, articles) {
5152
return false;
5253
}
5354
});
55+
56+
// perform code highlighting
57+
// convert only inside <code/>
58+
dom.innerHTML = hl(dom.innerHTML, false, true);
5459
articles[i].content = dom.innerHTML;
60+
5561
});
5662
return dom;
5763
};

theme/article.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11

22
<!-- required content -->
33

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

68
<header>
79
<div class="title">docs.nodejitsu.com </div>
File renamed without changes.
File renamed without changes.

theme/css/highlight/github.css

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
3+
github.com style (c) Vasily Polovnyov <[email protected]>
4+
5+
*/
6+
7+
pre code {
8+
display: block; padding: 0.5em;
9+
color: #000;
10+
background: #f8f8ff
11+
}
12+
13+
pre .comment,
14+
pre .template_comment,
15+
pre .diff .header,
16+
pre .javadoc {
17+
color: #998;
18+
font-style: italic
19+
}
20+
21+
pre .keyword,
22+
pre .css .rule .keyword,
23+
pre .winutils,
24+
pre .javascript .title,
25+
pre .lisp .title,
26+
pre .subst {
27+
color: #000;
28+
font-weight: bold
29+
}
30+
31+
pre .number,
32+
pre .hexcolor {
33+
color: #40a070
34+
}
35+
36+
pre .string,
37+
pre .tag .value,
38+
pre .phpdoc,
39+
pre .tex .formula {
40+
color: #d14
41+
}
42+
43+
pre .title,
44+
pre .id {
45+
color: #900;
46+
font-weight: bold
47+
}
48+
49+
pre .javascript .title,
50+
pre .lisp .title,
51+
pre .subst {
52+
font-weight: normal
53+
}
54+
55+
pre .class .title,
56+
pre .haskell .label,
57+
pre .tex .command {
58+
color: #458;
59+
font-weight: bold
60+
}
61+
62+
pre .tag,
63+
pre .tag .title,
64+
pre .rules .property,
65+
pre .django .tag .keyword {
66+
color: #000080;
67+
font-weight: normal
68+
}
69+
70+
pre .attribute,
71+
pre .variable,
72+
pre .instancevar,
73+
pre .lisp .body {
74+
color: #008080
75+
}
76+
77+
pre .regexp {
78+
color: #009926
79+
}
80+
81+
pre .class {
82+
color: #458;
83+
font-weight: bold
84+
}
85+
86+
pre .symbol,
87+
pre .ruby .symbol .string,
88+
pre .ruby .symbol .keyword,
89+
pre .ruby .symbol .keymethods,
90+
pre .lisp .keyword,
91+
pre .tex .special,
92+
pre .input_number {
93+
color: #990073
94+
}
95+
96+
pre .builtin,
97+
pre .built_in,
98+
pre .lisp .title {
99+
color: #0086b3
100+
}
101+
102+
pre .preprocessor,
103+
pre .pi,
104+
pre .doctype,
105+
pre .shebang,
106+
pre .cdata {
107+
color: #999;
108+
font-weight: bold
109+
}
110+
111+
pre .deletion {
112+
background: #fdd
113+
}
114+
115+
pre .addition {
116+
background: #dfd
117+
}
118+
119+
pre .diff .change {
120+
background: #0086b3
121+
}
122+
123+
pre .chunk {
124+
color: #aaa
125+
}
126+
127+
pre .tex .formula {
128+
opacity: 0.5;
129+
}
File renamed without changes.

theme/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

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

66
<header>
77
<div class="title"><a href="http://docs.nodejitsu.com">docs.nodejitsu.com</a></div>

theme/toc.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
<!-- required content -->
33

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

66
<header>
77
<div class="title">docs.nodejitsu.com </div>

vendor/highlight/LICENSE

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Copyright (c) 2010, Andris Reinman
2+
<http://www.andrisreinman.com/>
3+
All rights reserved.
4+
5+
Original Highlight.js Copyright (c) 2006, Ivan Sagalaev
6+
All rights reserved.
7+
8+
Redistribution and use in source and binary forms, with or without
9+
modification, are permitted provided that the following conditions are met:
10+
11+
* Redistributions of source code must retain the above copyright
12+
notice, this list of conditions and the following disclaimer.
13+
* Redistributions in binary form must reproduce the above copyright
14+
notice, this list of conditions and the following disclaimer in the
15+
documentation and/or other materials provided with the distribution.
16+
* Neither the name of highlight.js nor the names of its contributors
17+
may be used to endorse or promote products derived from this software
18+
without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
21+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
24+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

vendor/highlight/README.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
highlight
2+
==============
3+
4+
**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.
5+
6+
Installation
7+
------------
8+
9+
Use `npm` package manager
10+
11+
npm install highlight
12+
13+
Usage
14+
-----
15+
16+
Include syntax highlighter
17+
18+
var hl = require("highlight").Highlight;
19+
20+
highlight code
21+
22+
html = hl("for(var i=0;i<10;i++)alert(i);");
23+
24+
use special tab replacing string (default is 4 spaces)
25+
26+
html = hl(code_string, "<span> </span>");
27+
28+
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.
29+
30+
html = hl("<p>PHP:</p><code><?php echo 'Hello world!';?></code>", false, true);
31+
32+
Styles
33+
------
34+
35+
**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.
36+
37+
<link rel="stylesheet" href="/path/to/styles/default.css"/>

vendor/highlight/examples/test.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
3+
var hl = require("../lib/highlight.js").Highlight,
4+
code_string = "<?php\n"+
5+
"\techo \"Hello world!\";\n"+
6+
"\tfor($i=0;$i<100;$i++){\n"+
7+
"\t\techo \"$i\";\n"+
8+
"\t}\n"+
9+
"?>",
10+
11+
code_block = "<p>PHP code:</p>\n"+
12+
"<code><?php\n"+
13+
"\techo \"Hello world!\";\n"+
14+
"\tfor($i=0;$i<100;$i++){\n"+
15+
"\t\techo \"$i\";\n"+
16+
"\t}\n"+
17+
"?></code>",
18+
19+
html1 = hl(code_string), // convert all
20+
html2 = hl(code_string,' '), // convert with special tab replacer
21+
html3 = hl(code_block, false, true); // convert only inside <code/>
22+
23+
console.log(html1);
24+
console.log(html2);
25+
console.log(html3);

vendor/highlight/lib/highlight.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* node-highlight is based on highlight.js (see vendor/highlight.js) */
2+
/* usage: html = require("highlight").Highlight(code_string); */
3+
/* NB! You also need to include a CSS file from vendor/highlight.js/styles */
4+
5+
// load syntax highlighter
6+
var hljs = require("./vendor/highlight.js/highlight").hljs;
7+
8+
// load langs
9+
require("./vendor/highlight.js/languages/bash")(hljs);
10+
require("./vendor/highlight.js/languages/javascript")(hljs);
11+
require("./vendor/highlight.js/languages/ruby")(hljs);
12+
13+
14+
15+
/**
16+
* highlight(text, tabReplace, useCodeBlocks) -> HTML
17+
* - text (String): text to be highlighted
18+
* - tabReplace (String): defaults to 4 spaces if none, replaces \t chars
19+
* - useCodeBlocks (Boolean): If TRUE use only text between <code> and </code>
20+
*
21+
* Highlights program code inside a string by setting appropriate CSS class
22+
* elements.
23+
**/
24+
this.Highlight = function(text, tabReplace, useCodeBlocks){
25+
tabReplace = tabReplace || ' ';
26+
if(!!useCodeBlocks){
27+
// JS regexpes have some multiline issues, so we temporarily remove them
28+
return text.replace(/\n/g,'\uffff').replace(/<code>(.*?)<\/code>/gm, function(original, source){
29+
return '<code>'+hljs.highlightText(source.replace(/\uffff/g,"\n"), tabReplace)+'</code>';
30+
}).replace(/&amp;(\w+;)/g,'&$1').replace(/\uffff/g,"\n");
31+
}else
32+
return hljs.highlightText(text, tabReplace);
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Syntax highlighting with language autodetection.
2+
3+
URL: http://softwaremaniacs.org/soft/highlight/en/
4+
5+
Original author and current maintainer:
6+
Ivan Sagalaev <[email protected]>
7+
8+
Contributors:
9+
10+
- Peter Leonov <[email protected]>
11+
- Victor Karamzin <[email protected]>
12+
- Vsevolod Solovyov <[email protected]>
13+
- Anton Kovalyov <[email protected]>
14+
- Nikita Ledyaev <[email protected]>
15+
- Konstantin Evdokimenko <[email protected]>
16+
- Dmitri Roudakov <[email protected]>
17+
- Yuri Ivanov <[email protected]>
18+
- Vladimir Ermakov <[email protected]>
19+
- Vladimir Gubarkov <[email protected]>
20+
- Brian Beck <[email protected]>
21+
- MajestiC <[email protected]>
22+
- Vasily Polovnyov <[email protected]>
23+
- Vladimir Epifanov <[email protected]>
24+
- Alexander Makarov (http://rmcreative.ru/)
25+
26+
- Shuen-Huei Guan <[email protected]>
27+
- Jason Diamond <[email protected]>
28+
- Michal Gabrukiewicz <[email protected]>
29+
- Ruslan Keba <[email protected]>
30+
- Sergey Baranov <[email protected]>
31+
- Zaripov Yura <[email protected]>
32+
- Oleg Volchkov <[email protected]>
33+
- Vasily Mikhailitchenko <[email protected]>
34+
- Jan Berkel <[email protected]>
35+
- Vladimir Moskva <[email protected]>
36+
- Loren Segal <[email protected]>
37+
- Andrew Fedorov <[email protected]>
38+
- Igor Kalnitsky <[email protected]>
39+
- Jeremy Hull <[email protected]>
40+
- Valerii Hiora <[email protected]>
41+
- Nikolay Zakharov <[email protected]>
42+
- Dmitry Kovega <[email protected]>
43+
- Sergey Ignatov <[email protected]>
44+
- Antono Vasiljev <[email protected]>
45+
- Stephan Kountso <[email protected]>

0 commit comments

Comments
 (0)