Comparing version
@@ -0,1 +1,6 @@ | ||
## v0.3.0 - July 30, 2014 | ||
* Automatically page the output if the file is long. | ||
* Throw less-verbose error messages. | ||
## v0.2.3 - July 30, 2014 | ||
@@ -2,0 +7,0 @@ |
26
index.js
@@ -68,3 +68,3 @@ var hljs = require('highlight.js'); | ||
function: '1', /* css function, like rgba() */ | ||
'function': '1', /* css function, like rgba() */ | ||
strong: 'function', /* markdown strong */ | ||
@@ -125,3 +125,3 @@ link_label: 'strong', /* markdown links */ | ||
/** | ||
* html2ansi : html2ansi(str) | ||
* html2ansi() : html2ansi(str) | ||
* (private) Converts hljs-style spans from a given HTML `str` into ANSI | ||
@@ -138,4 +138,4 @@ * color codes. | ||
var code = color(token); | ||
if (process.env.HICAT_DEBUG) s = s + "\033[30m[" + token + "]\033[0m"; | ||
return code ? ("\033[" + code + "m" + s + "\033[0m") : s; | ||
if (process.env.HICAT_DEBUG) s = s + "\033[0;30m[" + token + "]\033[0m"; | ||
return colorize(s, code); | ||
}) | ||
@@ -149,2 +149,20 @@ .replace(/<span class="([^"]*)">/g, '') | ||
/** | ||
* colorize() : colorize(str, color) | ||
* Applies the color `color` to the string `str`. | ||
* | ||
* colorize("hello", 32) | ||
* => "\033[32mhello\033[0m" | ||
*/ | ||
function colorize (s, color) { | ||
if (!color) return s; | ||
var reset = "\033[0m", | ||
code = "\033[" + color + "m"; | ||
if (~s.indexOf("\n")) s = s.replace(/\n/g, "\n"+code); | ||
return code + s + reset; | ||
} | ||
module.exports = Hicat; |
@@ -9,17 +9,20 @@ var fs = require('fs'); | ||
exports.from = function (files, fn) { | ||
var err; | ||
var out = {}; | ||
// from stdin | ||
if (!files || files.length === 0) { | ||
exports.stdin(function (err, data) { | ||
if (err) throw err; | ||
out['-'] = data; | ||
fn(err, out); | ||
fn(err, { '-': data }); | ||
}); | ||
} else { | ||
files.forEach(function (fname) { | ||
out[fname] = fs.readFileSync(fname, 'utf-8'); | ||
}); | ||
fn(err, out); | ||
} | ||
// from files | ||
else { | ||
var out = {}; | ||
try { | ||
files.forEach(function (fname) { | ||
out[fname] = fs.readFileSync(fname, 'utf-8'); | ||
}); | ||
} catch (err) { | ||
return fn(err); | ||
} | ||
fn(null, out); | ||
} | ||
}; | ||
@@ -26,0 +29,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "0.2.3", | ||
"version": "0.3.0", | ||
"description": "Command-line syntax highlighter.", | ||
@@ -8,0 +8,0 @@ "main": "index.js", |
@@ -5,12 +5,12 @@ # hicat :cat: | ||
`cat` with syntax highlighting. Auto-detects the language via the file | ||
extension, or tries to infer it automatically. | ||
`cat` with syntax highlighting. The language is auto-detected through the file | ||
extension. | ||
hicat index.js | ||
Pipe something to `hicat`. It will figure out what language it is in. | ||
Pipe something to `hicat`. The language will be inferred from the contents. | ||
curl http://site.com | hicat | ||
If hicat fails to detect a language, explicitly pass it `-l LANG`. | ||
If hicat fails to detect a language, specify it using `-l LANG`. | ||
@@ -40,2 +40,14 @@ curl http://site.com | hicat -l xml | ||
Tips and tricks | ||
--------------- | ||
Add an alias to your `~/.bashrc` to save a few keystrokes. | ||
alias hi=hicat | ||
Btw | ||
--- | ||
[highlight.js] powers the syntax highlighter engine. | ||
Thanks | ||
@@ -53,1 +65,2 @@ ------ | ||
[contributors]: http://github.com/rstacruz/hicat/contributors | ||
[highlight.js]: http://highlightjs.org |
Sorry, the diff of this file is not supported yet
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
12178
18.86%11
10%296
23.33%64
25.49%2
Infinity%