peacock

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

peacock

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

Peacock (Pavo cristasus)

npm install peacock

peacock github page

npm exlore peacock npm run demo

  • 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

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

{   
    theme: {String}|{Object}
  , linenos: true|false 
}
  • ({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
  • if true the generated html includes line numbers
  • default is false

Ensure to include redeyed and esprima as your dependencies

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

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)