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

metalsmith-highlightjs

v0.0.1

Published

A Metalsmith plugin to syntax highlight code blocks.

Readme

metalsmith-highlightjs

npm: version npm: downloads

Snyk: vulnerabilities codecov: coverage license

A Metalsmith plugin to highlight code blocks with highlight.js.

This plugin replaces every fenced code block in Markdown files with highlighted HTML, optionally with line numbers. It should run before Markdown is rendered to HTML, e.g. before @metalsmith/markdown.

Installation

npm install --save metalsmith-highlightjs

JavaScript Usage

import Metalsmith from 'metalsmith';
import highlightjs from 'metalsmith-highlightjs';
import markdown from '@metalsmith/markdown';

Metalsmith(__dirname)
    .use(highlightjs({
        // options here
    }))
    .use(markdown())
    .build((err) => {
        if (err) {
            throw err;
        }
    });

Options

markdown (optional)

Type: string | string[] Default: "**/*.md"

A micromatch glob pattern, or array of patterns, to find Markdown files. Negated patterns can be used to exclude files.

highlightjs (optional)

Type: object Default: {}

highlight.js configuration options, passed to hljs.configure(). For example, languages limits which languages auto-detection will choose from:

highlightjs({
    highlightjs: {
        languages: ['javascript', 'typescript', 'bash'],
    },
})

aliases (optional)

Type: Record<string, string | string[]> Default: {}

Extra fence languages to register as aliases of a highlight.js language, using hljs.registerAliases(). The keys are highlight.js language names, and the values are one or more aliases:

highlightjs({
    aliases: {
        bash: ['myshell'],
    },
})

The build fails if a key isn't a registered highlight.js language.

lineNumbers (optional)

Type: boolean | { includeLanguages?: string[], excludeLanguages?: string[] } Default: false

Whether to add line numbers to code blocks:

  • false: no code block gets line numbers
  • true: every code block gets line numbers
  • an object: a code block gets line numbers if its language is in includeLanguages (or includeLanguages is unset), and it isn't in excludeLanguages

Languages are matched case-insensitively, either as written on the fence or by highlight.js's name for them, so bash also matches sh code blocks. A code block with no language never matches includeLanguages, so it only gets line numbers when includeLanguages is unset.

For example, to number every code block except for terminal sessions:

highlightjs({
    lineNumbers: {
        excludeLanguages: ['shell', 'console', 'dos', 'bat', 'cmd', 'powershell', 'ps', 'ps1'],
    },
})

lineWrap (optional)

Type: boolean Default: false

Whether to wrap long lines instead of scrolling sideways. Words that are too long for a line (e.g. URLs) are broken as well.

theme (optional)

Type: { name: string, filename: string } Default: none

A highlight.js theme CSS to add to the build:

  • name: the theme's name (e.g. github, github-dark, or base16/dracula)
  • filename: where to put the theme's minified CSS in the build
highlightjs({
    theme: {
        name: 'github',
        filename: 'css/highlight.css',
    },
})

The build fails if the theme doesn't exist, or if a file already exists at filename. HTML pages will need to link the CSS file, e.g. <link rel="stylesheet" href="/css/highlight.css">.

Changelog

Changelog