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

@trevixal/extension-code-highlight

v1.0.5

Published

Code-block syntax highlighting for the Trevixal editor behind an injectable Highlighter interface.

Readme

@trevixal/extension-code-highlight

CI npm types license

Documentation · Live editor · Changelog · Issues

The Trevixal editor

Features

  • Syntax highlighting behind an injectable Highlighter interface
  • 6.1 kB minified and gzipped, with TypeScript types in the package

Syntax highlighting for code blocks, rendered as decorations. The document itself stays plain text, so copy, paste and export are all unaffected by how the code happens to be coloured.

npm install @trevixal/extension-code-highlight

Usage

import { codeHighlight, createHighlighter } from '@trevixal/extension-code-highlight'

const dispose = codeHighlight(editor, createHighlighter())

Each code block reads its language from its own language attribute:

editor.commands.setBlockAttrs({ language: 'python' })

A block with no language renders unhighlighted. Pass a fallback if your documents never set one:

createHighlighter({ fallback: 'javascript' })

Bundled languages

JavaScript, TypeScript, Python, HTML, CSS, JSON, SQL, shell, Go, Rust, Java and Markdown, with the usual aliases (js, ts, py, sh, rs, md, golang, jsx, tsx, scss, xml, vue…). Resolution is case-insensitive.

These are rule sets rather than grammars: enough to colour code correctly in an editor, with no parser in the bundle.

Token classes

Every language emits the same class names, so a theme is a dozen colours:

| Class | Covers | | --- | --- | | tvx-tok-keyword | Language keywords | | tvx-tok-builtin | Built-in types, constants and globals | | tvx-tok-string | String and template literals | | tvx-tok-number | Numeric and colour literals | | tvx-tok-comment | Line and block comments | | tvx-tok-function | Call targets, decorators, macros | | tvx-tok-operator | Operators and punctuation | | tvx-tok-variable | Shell variables, lifetimes | | tvx-tok-tag | HTML/XML tags | | tvx-tok-attribute | Attributes, object keys, CSS properties | | tvx-tok-selector | CSS selectors and at-rules |

Your own languages

createHighlighter({
  languages: [
    {
      name: 'toml',
      rules: [
        { pattern: /#[^\n]*/y, className: 'tvx-tok-comment' },
        { pattern: /\[[^\]\n]+\]/y, className: 'tvx-tok-selector' },
        { pattern: /[A-Za-z_][\w-]*(?=\s*=)/y, className: 'tvx-tok-attribute' },
      ],
    },
  ],
})

Rules are tried in order at each position, so specific ones (comments, strings) must come before general ones (identifiers). Every pattern must be sticky (y).

A different engine

createHighlighter is one implementation of the Highlighter interface, which is all codeHighlight requires:

interface Highlighter {
  highlight(code: string, language: string | null): readonly HighlightToken[]
}

Wrap Shiki, Prism or highlight.js behind it, offsets in, offsets out, and nothing else in the editor changes.