peacock

JavaScript syntax highlighter that generates pygments compatible html and therefore supports pygments styles.

npm install peacock
1 downloads in the last day
28 downloads in the last week
99 downloads in the last month

peacock build status

JavaScript syntax highlighter that generates pygments compatible html and therefore supports pygments styles.

peacock

Peacock (Pavo cristasus)

Installation

npm install peacock

Try it

Online

peacock github page

Included demo

npm exlore peacock npm run demo

Features and limitations

  • works server side via nodejs
  • works in the browser via AMD, if available, or as global window object
  • only highlights JavaScript - if that is a dealbreaker look into some alternatives

API

peacock.highlight(code[, opts])

Returns the highlighted version of the code that was passed or throws an error if it was not able to parse it.

opts:

{   
    theme: {String}|{Object}
  , linenos: true|false 
}

theme:

  • ({Object} or {String}) that is used to optionally override the theme used to highlight
  • if it is {Object} it has to be of this form
  • it can also be a {String}, if used server side - either the name of a built-in theme or the full path to a theme anywhere on your computer

linenos:

  • if true the generated html includes line numbers
  • default is false

Browser support

AMD

Ensure to include redeyed and esprima as your dependencies

define(['peacock'], function (peacock) {
 [ .. ]
});

Attached to global window object

peacock will be exposed as window.peacock which allows calling peacock.highlight from anywhere.

<script type="text/javascript" src="https://raw.github.com/ariya/esprima/master/esprima.js"></script>
<script type="text/javascript" src="https://raw.github.com/thlorenz/redeyed/master/redeyed.js"></script>
<script type="text/javascript" src="https://github.com/thlorenz/peacock/raw/master/peacock-browser.js"></script>

Examples (browse)

Alternatives

npm loves you