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

gh-highlight

v0.1.3

Published

Highlight code like github

Downloads

17

Readme

gh-highlight

Highlight code like github.

This project is the synthesis of a couple of other projects:

  • github/linguist has information on language detection, has scripts for collecting all of the grammars used for highlighting.
  • atom/highlights is a syntax highlighter that can use TextMate's grammar format to highlight code.

Usage

The API was designed for highlighting fenced code blocks in markdown. For a list of names that are usable, check out aliases.json. The keys are the names you can use, the values are the scope name of the grammar that will be used to highlight.

Two functions are exposed; highlight and highlight.sync. They both take the code-to-be-highlighted as the first paramater and the language-infront-of-the-code-block as the second. For the top level version, the last parameter needs to be a callback.

If the language doesn't point to any grammar, no error will be reported.

const highlight = require('gh-highlight');

const html = highlight.sync('var hello = "world";', '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>

Themes

For now I'm just going to defer to atom/highlights, as the process for creating a css file from an atom theme should be exactly the same. You can download these prebuilt css files if you don't want to bother generating them from scratch.

Development

Development is not very user friendly at this point, but this is the initial commit chill out. Here's roughly how to build linguist's grammars on a fresh xenial box.

sudo apt-get update
sudo apt-get install git subversion ruby ruby-dev ruby-bundler curl nodejs npm cmake pkg-config libicu-dev
sudo ln -s "$(which nodejs)" /usr/bin/node
git clone https://github.com/github/linguist.git
cd linguist
./script/bootstrap
./script/convert-grammars

Roadmap

  • [x] Complete basic functionality.
  • [x] Add basic tests.
  • [x] Finish packaging for npm and publish.
  • [ ] Load grammars lazily.
  • [ ] Minify the grammars so that the package's download size is smaller. Should remove unnecessary keys, comments, disabled rules, unused rules, whitespace.
  • [ ] Compile code to support older node versions.
  • [ ] Make development process more user friendly, add more documentation.
  • [ ] Add pre-built common themes to this package.
  • [ ] Add playground and visual examples.
  • [ ] Continuous integration.
  • [ ] Consider including a tool for generating themes.
  • [ ] Consider convention-based extension method for adding grammars.