thlorenz / cardinal

Syntax highlights JavaScript code with ANSI colors to be printed to the terminal.
MIT License
175 stars 19 forks source link

cardinal Build Status

become a patron

NPM

car·di·nal (kärdn-l, kärdnl) - crested thick-billed North American finch having bright red plumage in the male.

screenshot

Features


Table of Contents generated with DocToc

Installation

As library

npm install cardinal

As Commandline Tool

[sudo] npm install -g cardinal

Note:

When installed globally, cardinal exposes itself as the cdl command.

Commandline

Highlight a file

cdl <file.js> [options]

options:

As part of a UNIX pipe

cat file.js | grep console | cdl

Note:

Not all code lines may be parsable JavaScript. In these cases the line is printed to the terminal without highlighting it.

Theme

The default theme will be used for highlighting.

To use a different theme, include a .cardinalrc file in your HOME directory.

This is a JSON file of the following form:

{
  "theme": "hide-semicolons",
  "linenos": true|false
}

API

highlight(code[, opts])

highlightFileSync(fullPath[, opts])

highlightFile(fullPath[, opts], callback)

opts

opts is an {Object} with the following properties:

Note The json option is obsoleted and not necessary anymore as cardinal properly understands both JSON and JavaScript.

Examples (browse)