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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 129 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 29 additions & 0 deletions
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

Lines changed: 37 additions & 0 deletions
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"/>

0 commit comments

Comments
 (0)