Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Syntax highlights JavaScript code with ANSI colors to be printed to the terminal.
JavaScript
tag: v0.1.2

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
assets
bin
examples
test
themes
.gitignore
.npmignore
.travis.yml
LICENSE
README.md
cardinal.js
package.json
settings.js
utl.js

README.md

cardinal Build Status

car·di·nal (kärdn-l, kärdnl) - A North American finch (Cardinalis cardinalis) having a crested head, a short thick bill, and bright red plumage

var cardinal = require('cardinal');

function highlight () {
  cardinal.highlightFile(__filename, function (err, res) {
    if (err) return console.error(err);
    console.log(res);
  });
}

highlight();

screenshot

Features

  • highlights JavaScript code with ANSI colors to improve terminal output
  • theming support, see custom color themes
  • API and command line interface (cdl)
  • .cardinalrc config to customize settings
  • supports UNIX pipes

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

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"
}

theme can be the name of any of the built-in themes or the full path to a custom theme anywhere on your computer.

API

highlight(code[, theme])

  • returns the highlighted version of the passed code ({String}) or throws an error if it was not able to parse it
  • theme ({Object}) is used to optionally override the theme used to highlight

highlightFileSync(fullPath[, theme])

  • returns the highlighted version of the file whose fullPath ({String}) was passed or throws an error if it was not able to parse it
  • theme ({Object}) is used to optionally override the theme used to highlight

highlightFile(fullPath[, theme], callback)

  • calls back with the highlighted version of the file whose fullPath ({String}) was passed or with an error if it was not able to parse it
  • theme ({Object}) is used to optionally override the theme used to highlight
  • callback ({Function}) has the following signature: function (err, highlighted) { .. }

Examples (browse)

Something went wrong with that request. Please try again.