Permalink
Browse files

[api] Added code highlighting.

[dist] Vendored highlight.js library
  • Loading branch information...
1 parent 857ccb6 commit d91950ff2e14c5b05cd58f950d30439de4ecd8e8 @Marak Marak committed Aug 26, 2011
Showing with 6,699 additions and 3 deletions.
  1. +6 −0 lib/generators/article.js
  2. +3 −1 theme/article.html
  3. BIN theme/{ → css}/fonts/AllerLt.ttf
  4. BIN theme/{ → css}/fonts/typewriter.ttf
  5. +129 −0 theme/css/highlight/github.css
  6. 0 theme/{ → css}/nodedocs.css
  7. +1 −1 theme/index.html
  8. +1 −1 theme/toc.html
  9. +29 −0 vendor/highlight/LICENSE
  10. +37 −0 vendor/highlight/README.md
  11. +25 −0 vendor/highlight/examples/test.js
  12. +33 −0 vendor/highlight/lib/highlight.js
  13. +45 −0 vendor/highlight/lib/vendor/highlight.js/AUTHORS.en.txt
  14. +45 −0 vendor/highlight/lib/vendor/highlight.js/AUTHORS.ru.txt
  15. +24 −0 vendor/highlight/lib/vendor/highlight.js/LICENSE
  16. +122 −0 vendor/highlight/lib/vendor/highlight.js/README.md
  17. +128 −0 vendor/highlight/lib/vendor/highlight.js/README.ru.md
  18. +437 −0 vendor/highlight/lib/vendor/highlight.js/classref.txt
  19. +87 −0 vendor/highlight/lib/vendor/highlight.js/export.html
  20. +618 −0 vendor/highlight/lib/vendor/highlight.js/highlight.js
  21. +1 −0 vendor/highlight/lib/vendor/highlight.js/highlight.pack.js
  22. +585 −0 vendor/highlight/lib/vendor/highlight.js/highlight_src.js
  23. +63 −0 vendor/highlight/lib/vendor/highlight.js/languages/bash.js
  24. +54 −0 vendor/highlight/lib/vendor/highlight.js/languages/javascript.js
  25. +205 −0 vendor/highlight/lib/vendor/highlight.js/languages/ruby.js
  26. +486 −0 vendor/highlight/lib/vendor/highlight.js/readme.eng.txt
  27. +494 −0 vendor/highlight/lib/vendor/highlight.js/readme.rus.txt
  28. +45 −0 vendor/highlight/lib/vendor/highlight.js/styles/ascetic.css
  29. +105 −0 vendor/highlight/lib/vendor/highlight.js/styles/brown_paper.css
  30. BIN vendor/highlight/lib/vendor/highlight.js/styles/brown_papersq.png
  31. +103 −0 vendor/highlight/lib/vendor/highlight.js/styles/dark.css
  32. +121 −0 vendor/highlight/lib/vendor/highlight.js/styles/default.css
  33. +118 −0 vendor/highlight/lib/vendor/highlight.js/styles/far.css
  34. +129 −0 vendor/highlight/lib/vendor/highlight.js/styles/github.css
  35. +118 −0 vendor/highlight/lib/vendor/highlight.js/styles/idea.css
  36. +103 −0 vendor/highlight/lib/vendor/highlight.js/styles/ir_black.css
  37. +118 −0 vendor/highlight/lib/vendor/highlight.js/styles/magula.css
  38. +111 −0 vendor/highlight/lib/vendor/highlight.js/styles/school_book.css
  39. BIN vendor/highlight/lib/vendor/highlight.js/styles/school_book.png
  40. +147 −0 vendor/highlight/lib/vendor/highlight.js/styles/sunburst.css
  41. +84 −0 vendor/highlight/lib/vendor/highlight.js/styles/vs.css
  42. +115 −0 vendor/highlight/lib/vendor/highlight.js/styles/zenburn.css
  43. +1,598 −0 vendor/highlight/lib/vendor/highlight.js/test.html
  44. +26 −0 vendor/highlight/package.json
@@ -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'),
@@ -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;
};
View
@@ -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>
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,129 @@
+/*
+
+github.com style (c) Vasily Polovnyov <vast@whiteants.net>
+
+*/
+
+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.
View
@@ -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>
View
@@ -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>
@@ -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.
@@ -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"/>
@@ -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);
@@ -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);
+}
@@ -0,0 +1,45 @@
+Syntax highlighting with language autodetection.
+
+URL: http://softwaremaniacs.org/soft/highlight/en/
+
+Original author and current maintainer:
+Ivan Sagalaev <Maniac@SoftwareManiacs.Org>
+
+Contributors:
+
+- Peter Leonov <gojpeg@gmail.com>
+- Victor Karamzin <Victor.Karamzin@enterra-inc.com>
+- Vsevolod Solovyov <vsevolod.solovyov@gmail.com>
+- Anton Kovalyov <anton@kovalyov.net>
+- Nikita Ledyaev <lenikita@yandex.ru>
+- Konstantin Evdokimenko <qewerty@gmail.com>
+- Dmitri Roudakov <dmitri@roudakov.ru>
+- Yuri Ivanov <ivanov@supersoft.ru>
+- Vladimir Ermakov <vooon341@mail.ru>
+- Vladimir Gubarkov <xonixx@gmail.com>
+- Brian Beck <exogen@gmail.com>
+- MajestiC <majestic2k@gmail.com>
+- Vasily Polovnyov <vast@whiteants.net>
+- Vladimir Epifanov <voldmar@voldmar.ru>
+- Alexander Makarov (http://rmcreative.ru/)
+- Vah <vahtenberg@gmail.com>
+- Shuen-Huei Guan <drake.guan@gmail.com>
+- Jason Diamond <jason@diamond.name>
+- Michal Gabrukiewicz <mgabru@gmail.com>
+- Ruslan Keba <rukeba@gmail.com>
+- Sergey Baranov <segyrn@yandex.ru>
+- Zaripov Yura <yur4ik7@ukr.net>
+- Oleg Volchkov <oleg@volchkov.net>
+- Vasily Mikhailitchenko <vaskas@programica.ru>
+- Jan Berkel <jan.berkel@gmail.com>
+- Vladimir Moskva <vladmos@gmail.com>
+- Loren Segal <lsegal@soen.ca>
+- Andrew Fedorov <dmmdrs@mail.ru>
+- Igor Kalnitsky <igor.kalnitsky@gmail.com>
+- Jeremy Hull <sourdrums@gmail.com>
+- Valerii Hiora <valerii.hiora@gmail.com>
+- Nikolay Zakharov <nikolay.desh@gmail.com>
+- Dmitry Kovega <arhibot@gmail.com>
+- Sergey Ignatov <sergey@ignatov.spb.su>
+- Antono Vasiljev <self@antono.info>
+- Stephan Kountso <steplg@gmail.com>
Oops, something went wrong. Retry.

0 comments on commit d91950f

Please sign in to comment.