Skip to content

dtao/console-highlight

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

console-highlight

Get syntax highlighting in the console.

Usage

var highlight = require('console-highlight');

console.log(highlight('javascript to highlight', {
  // optional options
  language: 'javascript', // will auto-detect if omitted
  theme: 'default' // a highlight.js theme
}));

Example output (using the 'monokai' theme):

Example - Monokai

Another example (using the 'solarized_dark' theme):

Example - Solarized Dark

How it works

This library uses highlight.js to do the heavy lifting. It then takes the resulting HTML and uses htmlout to convert it to styled console output.

Does this already exist?

Not that I'm aware of. The closest things I could find were ansi-highlight and cardinal, both of which only support JavaScript and appear to implement the lexing and highlighting logic all themselves (or using esprima, in cardinal's case).

By leveraging highlight.js for the actual highlighting logic, this library gains quite a lot: support for 71 languages and 44 styles. Even better, whatever improvements are made to highlight.js in the future will automatically benefit the console-highlight library.

Questions?

Please!

About

Syntax highlighting in the console

Resources

Stars

Watchers

Forks

Packages

No packages published