Syntax highlights JavaScript code with ANSI colors to be printed to the terminal.
npm install cardinal
car·di·nal (kärdn-l, kärdnl) - crested thick-billed North American finch having bright red plumage in the male.
- highlights JavaScript code with ANSI colors to improve terminal output
- theming support, see custom color themes
- optionally print line numbers
- API and command line interface (cdl)
- .cardinalrc config to customize settings
- supports UNIX pipes
*
Table of Contents generated with DocToc
- Installation
- As library
- As Commandline Tool
- Commandline
- Highlight a file
- As part of a UNIX pipe
- Theme
- API
- [highlight(code[, opts])](#highlightcode-opts)
- [highlightFileSync(fullPath[, opts])](#highlightfilesyncfullpath-opts)
- [highlightFile(fullPath[, opts], callback)](#highlightfilefullpath-opts-callback)
- opts
- Examples ([browse)](#examples-[browse]https://githubcom/thlorenz/cardinal/tree/master/examples)
npm install cardinal
[sudo] npm install -g cardinal
Note:
When installed globally, cardinal exposes itself as the cdl command.
cdl
options:
- --nonum: turns off line number printing (relevant if it is turned on inside ~/.cardinalrc
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.
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:
``json`
{
"theme": "hide-semicolons",
"linenos": true|false
}
- theme can be the name of any of the built-in themes or the
full path to a custom theme anywhere on your computer.
- linenos toggles line number printing
- returns the highlighted version of the passed code ({String}) or throws an error if it was not able to parse it
- opts (see below)
- returns the highlighted version of the file whose fullPath ({String}) was passed or throws an error if it was not able
to parse it
- opts (see below)
- 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
- opts (see below)
- callback ({Function}) has the following signature: function (err, highlighted) { .. }
opts is an {Object} with the following properties:
- theme {Object} is used to optionally override the theme used to highlightlinenos
- {Boolean} if true line numbers are included in the highlighted codefirstline
- {Integer} sets line number of the first line when line numbers are printedjsx
- {Boolean} if true _JSX_ syntax is supported, otherwise cardinal will raise an errorfalse
when encountering _JSX_ (default: )
Note The json` option is obsoleted and not necessary anymore as cardinal properly understands both JSON and JavaScript.
- sample .cardinalrc
- highlighting a code snippet via
highlight()
- file that highlights itself via
highlightFile() including line numbers
- file that highlights itself hiding all
semicolons via
highlightFileSync()