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 🙏

© 2025 – Pkg Stats / Ryan Hefner

gatsby-remark-tree-sitter

v1.0.0

Published

Highlight code in Markdown files using tree-sitter

Downloads

16

Readme

gatsby-remark-tree-sitter

Highlight code in Markdown files using tree-sitter, powered by remark-tree-sitter.

Install

npm install --save gatsby-remark-tree-sitter

How it works

This plugin uses the same mechanism and data as Atom for syntax highlighting, So to highlight a particular language, you need to either:

  • Install the APM (Atom) package for that language and tell remark-tree-sitter to import it, using the grammarPackages option.
  • Provide the tree-sitter grammar and scopeMappings manually, using the using the grammars option.

For more information on how this mechanism works, check out the documentation for tree-sitter-hast.

Any code blocks that are encountered for which there is not a matching language will be ignored.

How to use

Add gatsby-remark-tree-sitter to the list of plugins for gatsby-transformer-remark, and list the grammars you want to use in your gatsby-config.js file:

Example:

npm install --save @atom-languages/language-typescript
plugins: [
  {
    resolve: `gatsby-transformer-remark`,
    options: {
      plugins: [
        {
          resolve: "gatsby-remark-tree-sitter",
          options: {
            grammarPackages: ['@atom-languages/language-typescript']
          },
        },
      ],
    },
  },
]

This would then render the following markdown:

```typescript
function foo() {
  return 1;
}
```

As this HTML:

<pre><code class="tree-sitter language-typescript"><span class="source ts"><span class="storage type function">function</span> <span class="entity name function">foo</span><span class="punctuation definition parameters begin bracket round">(</span><span class="punctuation definition parameters end bracket round">)</span> <span class="punctuation definition function body begin bracket curly">{</span>
  <span class="keyword control">return</span> <span class="constant numeric">1</span><span class="punctuation terminator statement semicolon">;</span>
<span class="punctuation definition function body end bracket curly">}</span></span></code></pre>

Note that either grammarPackages or grammars must be specified in the options.

For a list of language packages that you can use in grammarPackages, please see Atom language packages.

Whitelisting classes

Sometimes including the full list of classes applied can be too much, and you'd like to only include those that you have stylesheets for.

To do this, you can pass in a whitelist of classes that you actually care about.

Example: The following configuration...

plugins: [
  {
    resolve: `gatsby-transformer-remark`,
    options: {
      plugins: [
        {
          resolve: "gatsby-remark-tree-sitter",
          options: {
            grammarPackages: ['@atom-languages/language-typescript'],
            classWhitelist: ['storage', 'numeric']
          },
        },
      ],
    },
  },
]

...will convert this markdown...

```typescript
function foo() {
  return 1;
}
```

...to this:

<pre><code class="tree-sitter language-typescript"><span><span class="storage">function</span> foo() {
  return <span class="numeric">1</span>;
}</span></code></pre>

Full Documentation

For for full documentation on the options you can use, please see the documentation for remark-tree-sitter, as options are passed directly to that plugin.