npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

highlight-redux

v1.0.1

Published

A redux of highlight.js for the Browserify human

Downloads

504

Readme

Highlight.js

Highlight.js highlights syntax in code examples on blogs, forums and, in fact, on any web page. It's very easy to use because it works automatically: finds blocks of code, detects a language, highlights it.

Autodetection can be fine tuned when it fails by itself (see "Heuristics").

Basic usage

Link the library and a stylesheet from your page and hook highlighting to the page load event:

<link rel="stylesheet" href="styles/default.css">
<script src="highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>

This will highlight all code on the page marked up as <pre><code> .. </code></pre>. If you use different markup or need to apply highlighting dynamically, read "Custom initialization" below.

  • You can download your own customized version of "highlight.pack.js" or use the hosted one as described on the download page: http://highlightjs.org/download/

  • Style themes are available in the download package or as hosted files. To create a custom style for your site see the class reference in the file CSS classes reference from the downloaded package.

node.js

Highlight.js can be used under node.js. The package with all supported languages is installable from NPM:

npm install highlight.js

Alternatively, you can build it from the source with only languages you need:

python3 tools/build.py -tnode lang1 lang2 ..

Using the library:

var hljs = require('highlight.js');

// If you know the language
hljs.highlight(lang, code).value;

// Automatic language detection
hljs.highlightAuto(code).value;

AMD

Highlight.js can be used with an AMD loader. You will need to build it from source in order to do so:

$ python3 tools/build.py -tamd lang1 lang2 ..

Which will generate a build/highlight.pack.js which will load as an AMD module with support for the built languages and can be used like so:

require(["highlight.js/build/highlight.pack"], function(hljs){

  // If you know the language
  hljs.highlight(lang, code).value;

  // Automatic language detection
  hljs.highlightAuto(code).value;
});

Tab replacement

You can replace TAB ('\x09') characters used for indentation in your code with some fixed number of spaces or with a <span> to give them special styling:

<script type="text/javascript">
  hljs.configure({tabReplace: '    '}); // 4 spaces
  // ... or
  hljs.configure({tabReplace: '<span class="indent">\t</span>'});

  hljs.initHighlightingOnLoad();
</script>

Custom initialization

If you use different markup for code blocks you can initialize them manually with highlightBlock(code) function. It takes a DOM element containing the code to highlight and optionally a string with which to replace TAB characters.

Initialization using, for example, jQuery might look like this:

$(document).ready(function() {
  $('pre code').each(function(i, e) {hljs.highlightBlock(e)});
});

You can use highlightBlock to highlight blocks dynamically inserted into the page. Just make sure you don't do it twice for already highlighted blocks.

If your code container relies on <br> tags instead of line breaks (i.e. if it's not <pre>) set the useBR option to true:

hljs.configure({useBR: true});
$('div.code').each(function(i, e) {hljs.highlightBlock(e)});

Heuristics

Autodetection of a code's language is done using a simple heuristic: the program tries to highlight a fragment with all available languages and counts all syntactic structures that it finds along the way. The language with greatest count wins.

This means that in short fragments the probability of an error is high (and it really happens sometimes). In this cases you can set the fragment's language explicitly by assigning a class to the <code> element:

<pre><code class="html">...</code></pre>

You can use class names recommended in HTML5: "language-html", "language-php". Classes also can be assigned to the <pre> element.

To disable highlighting of a fragment altogether use "no-highlight" class:

<pre><code class="no-highlight">...</code></pre>

Export

File export.html contains a little program that allows you to paste in a code snippet and then copy and paste the resulting HTML code generated by the highlighter. This is useful in situations when you can't use the script itself on a site.

Meta

  • Version: 8.0
  • URL: http://highlightjs.org/

For the license terms see LICENSE files. For authors and contributors see AUTHORS.en.txt file.