peacock
JavaScript syntax highlighter that generates pygments compatible html and therefore supports pygments styles.
Last updated 2 years ago by thlorenz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install peacock 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.0.0                                ...           latest (2 years ago)

7 Versions

  • 1.0.0                                ...           2 years ago
  • 0.3.1                                ...           4 years ago
  • 0.3.0                                ...           4 years ago
  • 0.2.0                                ...           8 years ago
  • 0.1.2                                ...           8 years ago
  • 0.1.1                                ...           8 years ago
  • 0.1.0                                ...           8 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (3)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |