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 🙏

© 2024 – Pkg Stats / Ryan Hefner

highlights

v3.1.6

Published

Syntax highlighter

Downloads

1,369

Readme

Reads in code, writes out HTML with CSS classes based on the tokens in the code.

Build Status

See it in action here.

Installing

npm install highlights

Using

Run highlights -h for full details about the supported options.

To convert a source file to tokenized HTML run the following:

highlights file.coffee -o file.html

Now you have a file.html file that has a big <pre> tag with a <div> for each line with <span> elements for each token.

Then you can compile an existing Atom theme into a stylesheet with the following:

git clone https://github.com/atom/atom-dark-syntax
cd atom-dark-syntax
npm install -g less
lessc --include-path=styles index.less atom-dark-syntax.css

Now you have an atom-dark-syntax.css stylesheet that be combined with the file.html file to generate some nice looking code.

Check out the examples to see it in action.

Check out atom.io to find more themes.

Some popular themes:

Using in code

Highlights = require 'highlights'
highlighter = new Highlights()
html = highlighter.highlightSync
  fileContents: 'var hello = "world";'
  scopeName: 'source.js'

console.log html

Outputs:

<pre class="editor editor-colors">
  <div class="line">
    <span class="source js">
      <span class="storage modifier js"><span>var</span></span>
      <span>&nbsp;hello&nbsp;</span>
      <span class="keyword operator js"><span>=</span></span>
      <span>&nbsp;</span>
      <span class="string quoted double js">
        <span class="punctuation definition string begin js"><span>&quot;</span></span>
        <span>world</span>
        <span class="punctuation definition string end js"><span>&quot;</span></span>
      </span>
      <span class="punctuation terminator statement js"><span>;</span></span>
    </span>
  </div>
</pre>

Loading Grammars From Modules

highlights exposes the method requireGrammarsSync, for loading grammars from npm modules. The usage is as follows:

npm install atom-language-clojure
Highlights = require 'highlights'
highlighter = new Highlights()
highlighter.requireGrammarsSync
  modulePath: require.resolve('atom-language-clojure/package.json')

Developing

  • Clone this repository git clone https://github.com/atom/highlights
  • Update the submodules by running git submodule update --init --recursive
  • Run npm install to install the dependencies, compile the CoffeeScript, and build the grammars
  • Run npm test to run the specs

:green_heart: Pull requests are greatly appreciated and welcomed.