1.0.0 • Published 6 years ago

peacock v1.0.0

Weekly downloads
9
License
MIT
Repository
github
Last release
6 years ago

peacock build status

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

1.0.0

6 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.0

12 years ago

0.1.2

12 years ago

0.1.1

12 years ago

0.1.0

12 years ago