peacock

1.0.0 • Public • Published

peacock build status

become a patron

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

Peacock (Pavo cristasus)

Installation

npm install peacock

Included demo

npm exlore peacock npm run demo

Features and limitations

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

API

peacock.defaultTheme

Returns Object the default peacock theme used to highlight code

peacock.spans

Returns Object the default peacock spans used to wrap code tokens

peacock.classes

Returns Object the default peacock classes used to highlight code

peacock.highlight

Highlights the proviced code or throws an error if it was not able to parse it.

Parameters

  • code String to highlight
  • $0 Object options
    • $0.theme (Object | String)? to use when highlighting empty sample (optional, default peacock.defaultTheme)
    • $0.linenos Boolean? if true line numbers will be included (optional, default false)
    • $0.jsx Boolean? if true peacock will support jsx syntax (which makes highlighting a tad bit slower) (optional, default true)

Returns String the HTML with containing the highlighted code

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://cdnjs.cloudflare.com/ajax/libs/esprima/2.7.2/esprima.min.js"></script>
<script type="text/javascript" src="https://rawgit.com/thlorenz/redeyed/master/redeyed.js"></script>
<script type="text/javascript" src="https://rawgit.com/thlorenz/peacock/master/peacock-browser.js"></script>

Examples (browse)

Alternatives

/peacock/

    Package Sidebar

    Install

    npm i peacock

    Weekly Downloads

    12

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    140 kB

    Total Files

    51

    Last publish

    Collaborators

    • thlorenz