added new highlight js

This commit is contained in:
Walker Waylon Scott 2017-07-23 13:41:35 -05:00
parent 3ca00dbac8
commit a2cc24dff7
13 changed files with 495 additions and 0 deletions

29
src/static/node_modules/highlight/LICENSE generated vendored Normal file
View file

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

44
src/static/node_modules/highlight/README.md generated vendored Normal file
View file

@ -0,0 +1,44 @@
DEPRECATION NOTICE
==================
This project is deprecated in favor of [isagalaev/highlight.js](https://github.com/isagalaev/highlight.js). I never created the parser myself, the module was created in the early days of node as a wrapper for an existing browser based parser [highlight.js](http://softwaremaniacs.org/soft/highlight/en/) so if you are using this module and have problems with the parsing logic, I can't help you much as I'm not familiar with the inner details.
Pull requests are still welcomed - if you find a bug and fix it, then I'll pull the change in but I won't be fixing the bugs myself. Sorry for that.
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"/>

113
src/static/node_modules/highlight/bin/highlight-cli.js generated vendored Normal file
View file

@ -0,0 +1,113 @@
#!/usr/bin/env node
(function () {
"use strict";
var fs = require('fs')
, Highlight = require('highlight')
//, Highlight = require('../lib/highlight')
, filename = process.argv[2]
, langArgIndex = 4
, langArg
, langs
;
if (filename.match(/--languages(=)?/)) {
langArg = filename;
langArgIndex = 3;
filename = null;
}
langArg = process.argv[langArgIndex - 1] || '';
if (langArg = langArg.match(/--languages(=(.*))?/)) {
langs = (process.argv[langArgIndex]||'').split(/\s*,\s*/g);
if (langArg[2]) {
langs = langArg[2].split(/,/);
}
}
function printUsage() {
console.warn("Usages:");
console.warn("highlight site/docs/index.html > highlighted.html");
console.warn("cat site/docs/index.html | highlight > highlighted.html");
}
function handleInput(err, text) {
var hlBlock
, wrappedInHtml
;
if (err) {
printUsage();
return;
}
wrappedInHtml = !!text.match(/<.*?code.*?>/i);
// TODO test if filename extension reveals code type
Highlight.init(function (err) {
if (err) {
console.error('[highlight-cli]', err.message);
//console.error(err.stack);
return;
}
hlBlock = Highlight.highlight(text, ' ', wrappedInHtml);
console.info(hlBlock);
}, langs);
}
readInput(handleInput, filename);
//
// this could (and probably should) be its own module
//
function readInput(cb, filename) {
function readFile() {
fs.readFile(filename, 'utf8', function (err, text) {
if (err) {
console.error("[ERROR] couldn't read from '" + filename + "':");
console.error(err.message);
return;
}
cb(err, text);
});
}
function readStdin() {
var text = ''
, timeoutToken
, stdin = process.stdin
;
stdin.resume();
// how to tell piping vs waiting for user input?
timeoutToken = setTimeout(function () {
cb(new Error('no stdin data'));
stdin.pause();
}, 1000);
stdin.on('data', function (chunk) {
clearTimeout(timeoutToken);
text += chunk;
});
stdin.on('end', function () {
cb(null, text);
});
}
if (filename) {
readFile();
}
else {
readStdin();
}
}
}());

34
src/static/node_modules/highlight/bin/package.json generated vendored Normal file
View file

@ -0,0 +1,34 @@
{
"name" : "highlight-cli",
"description" : "cli for the highlight module",
"version" : "1.1.0",
"author" : "AJ ONeal",
"homepage": "https://github.com/andris9/highlight",
"maintainers":[
{
"name":"andris",
"email":"andris@node.ee"
}
],
"engines": {
"node": "*"
},
"repository" : {
"type" : "git",
"url" : "http://github.com/andris9/highlight.git"
},
"bin": {
"highlight": "./highlight-cli.js"
},
"main": "./highlight-cli",
"dependencies": {
"highlight": "*"
},
"licenses" : [
{
"type": "BSD",
"url": "http://github.com/andris9/highlight/blob/master/LICENSE"
}
],
"preferGlobal": true
}

View file

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>Foo</title>
</head>
<body>
Bar
<br/>
Baz
<p>Quux</p>
<ul>
<li>Qux</li>
<li>Grault</li>
</ul>
</body>
</html>

View file

@ -0,0 +1,5 @@
(function () {
"use strict";
console.log('Hello World!');
}();

View file

@ -0,0 +1,5 @@
<pre><code>(function () {
"use strict";
console.log('Hello World!');
}();</code></pre>

View file

@ -0,0 +1,29 @@
(function () {
"use strict";
var Highlight = require("../lib/highlight.js")
, assert = require('assert')
, fs = require('fs')
, reHasAnnotations = /\sclass="tag"/
;
function runTest(err) {
assert.ok(!err, err && err.message);
assert.strictEqual(1, Highlight.loadedLanguages.length, 'more than one language is loaded: ' + Highlight.loadedLanguages);
assert.strictEqual('xml', Highlight.loadedLanguages[0], 'xml isn\'t the language');
fs.readFile('./example.html', 'utf8', function (err, text) {
var annotated
;
assert.ok(!err, 'threw error reading example.html');
annotated = Highlight.highlight(text, ' ');
assert.ok(annotated.match(reHasAnnotations));
//console.log(annotated);
console.info('[PASS] source is annotated');
});
}
Highlight.init(runTest, ['xml']);
}());

View file

@ -0,0 +1,41 @@
(function () {
"use strict";
var Highlight = require("../lib/highlight.js")
, assert = require('assert')
, fs = require('fs')
, reHasAnnotations = /\sclass="[\w-]+"/
;
function runTest(err) {
//console.log(Highlight.loadedLanguages);
assert.ok(!err, err && err.message);
assert.strictEqual(Highlight.languages.length, Highlight.loadedLanguages.length
, 'not all languages were loaded: '
+ Highlight.languages.length
+ " "
+ Highlight.loadedLanguages.length
);
assert.deepEqual(Highlight.languages, Highlight.loadedLanguages
, 'not all languages were loaded: '
+ JSON.stringify(Highlight.languages, null, ' ')
+ "\n"
+ JSON.stringify(Highlight.loadedLanguages, null, ' ')
);
// It's okay that these run out-of-order / in-parallel
fs.readFile('./example.js', 'utf8', function (err, text) {
var annotated
;
assert.ok(!err, 'threw error reading example.js');
annotated = Highlight.highlight(text, ' ');
assert.ok(annotated.match(reHasAnnotations));
//console.log(annotated);
console.info('[PASS] annotated source (perhaps incorrectly) with all modules loaded');
});
}
Highlight.init(runTest);
}());

View file

@ -0,0 +1,29 @@
(function () {
"use strict";
var Highlight = require("../lib/highlight.js")
, assert = require('assert')
, fs = require('fs')
, reHasAnnotations = /\sclass="[\w-]+"/
;
function runTest(err) {
assert.ok(!err, err && err.message);
assert.strictEqual(1, Highlight.loadedLanguages.length, 'more than one language is loaded: ' + Highlight.loadedLanguages);
assert.strictEqual('javascript', Highlight.loadedLanguages[0], 'javascript is the language');
fs.readFile('./example.js.html', 'utf8', function (err, text) {
var annotated
;
assert.ok(!err, 'threw error reading example.js.html');
annotated = Highlight.highlight(text, ' ', true);
assert.ok(annotated.match(reHasAnnotations));
//console.log(annotated);
console.info('[PASS] source is annotated');
});
}
Highlight.init(runTest, ['javascript']);
}());

View file

@ -0,0 +1,36 @@
(function () {
"use strict";
var Highlight = require("../lib/highlight.js")
, assert = require('assert')
, fs = require('fs')
, reHasMarkup = /<.*class=["']?[\w-]+["'?]/
, reHasAnnotations = /\sclass="[\w-]+"/
;
function runTest(err) {
//console.log(Highlight.loadedLanguages);
assert.ok(!err, err && err.message);
assert.strictEqual(0, Highlight.loadedLanguages.length
, 'some languages were loaded: '
+ Highlight.languages.length
+ " "
+ Highlight.loadedLanguages.length
);
// It's okay that these run out-of-order / in-parallel
fs.readFile('./example.js', 'utf8', function (err, text) {
var annotated
;
assert.ok(!err, 'threw error reading example.js');
annotated = Highlight.highlight(text, ' ');
assert.ok(!annotated.match(reHasAnnotations));
//console.log(annotated);
console.info('[PASS] source is not annotated');
});
}
Highlight.init(runTest, []);
}());

25
src/static/node_modules/highlight/examples/test.js generated vendored Normal file
View file

@ -0,0 +1,25 @@
var hl = require("../lib/highlight.js").Highlight,
code_string = "<?php\r\n"+
"\techo \"Hello world!\";\r\n"+
"\tfor($i=0;$i<100;$i++){\r\n"+
"\t\techo \"$i\";\r\n"+
"\t}\r\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);

89
src/static/node_modules/highlight/package.json generated vendored Normal file
View file

@ -0,0 +1,89 @@
{
"_args": [
[
{
"raw": "highlight",
"scope": null,
"escapedName": "highlight",
"name": "highlight",
"rawSpec": "",
"spec": "latest",
"type": "tag"
},
"C:\\Box Sync\\pyDataVizDay\\src\\static"
]
],
"_from": "highlight@latest",
"_id": "highlight@0.2.4",
"_inCache": true,
"_location": "/highlight",
"_nodeVersion": "0.12.7",
"_npmUser": {
"name": "andris",
"email": "andris@kreata.ee"
},
"_npmVersion": "2.11.3",
"_phantomChildren": {},
"_requested": {
"raw": "highlight",
"scope": null,
"escapedName": "highlight",
"name": "highlight",
"rawSpec": "",
"spec": "latest",
"type": "tag"
},
"_requiredBy": [
"#USER"
],
"_resolved": "https://registry.npmjs.org/highlight/-/highlight-0.2.4.tgz",
"_shasum": "8ac02875b03f5935e0675852b76cfe1fd58e0dff",
"_shrinkwrap": null,
"_spec": "highlight",
"_where": "C:\\Box Sync\\pyDataVizDay\\src\\static",
"author": {
"name": "Andris Reinman"
},
"bugs": {
"url": "https://github.com/andris9/highlight/issues"
},
"dependencies": {},
"deprecated": "Not maintained anymore",
"description": "Highlight code syntax with node.js",
"devDependencies": {},
"directories": {
"lib": "./lib"
},
"dist": {
"shasum": "8ac02875b03f5935e0675852b76cfe1fd58e0dff",
"tarball": "https://registry.npmjs.org/highlight/-/highlight-0.2.4.tgz"
},
"gitHead": "a955fd043e73a5d304e0987515641f1075bb88b2",
"homepage": "https://github.com/andris9/highlight#readme",
"licenses": [
{
"type": "BSD",
"url": "http://github.com/andris9/highlight/blob/master/LICENSE"
}
],
"main": "./lib/highlight",
"maintainers": [
{
"name": "andris",
"email": "andris@node.ee"
},
{
"name": "guileen",
"email": "guileen@gmail.com"
}
],
"name": "highlight",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/andris9/highlight.git"
},
"scripts": {},
"version": "0.2.4"
}