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

highlighted-code

v0.3.7

Published

A textarea builtin extend to automatically provide code highlights based on one of the languages available via highlight.js

Downloads

158

Readme

highlighted-code

A textarea builtin extend to automatically provide code highlights based on one of the languages available via highlight.js.

Live demo

<!doctype html>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<style>
textarea[is="highlighted-code"] { padding: 8px; }
</style>
<script type="module">
(async ({chrome, netscape}) => {

  // add Safari polyfill if needed
  if (!chrome && !netscape)
    await import('https://unpkg.com/@ungap/custom-elements');

  const {default: HighlightedCode} =
    await import('https://unpkg.com/highlighted-code');

  // bootstrap a theme through one of these names
  // https://github.com/highlightjs/highlight.js/tree/main/src/styles
  HighlightedCode.useTheme('github-dark');
})(self);
</script>
<textarea is="highlighted-code"
          cols="80" rows="12"
          language="javascript" tab-size="2" auto-height>
(async ({chrome, netscape}) => {

  // add Safari polyfill if needed
  if (!chrome && !netscape)
    await import('https://unpkg.com/@ungap/custom-elements');

  const {default: HighlightedCode} = await import('https://unpkg.com/highlighted-code');

  // bootstrap a theme through one of these names
  // https://github.com/highlightjs/highlight.js/tree/main/src/styles
  HighlightedCode.useTheme('github-dark');
})(self);
</textarea>

API

The component is literally a textarea so everything that works or applies for this kind of element works and applies for this custom element too.

The only extras attributes this component offer are:

  • language, reflected as area.language to define which kind of language should be highlighted. See the list of supported languages here (see those that don't require extra packages).
  • tab-size, reflected as area.tabSize, to determine the amount of virtual spaces covered by tabs. Because we live in a Mobile world, the default is 2.
  • auto-height, reflected as area.autoHeight, to render the textarea as if it was a regular element. See the test page as example, or set autoHeight = true in the live demo and see the area growing while typing.

The exported HighlightedCode default class exposes these public methods/accessors:

  • HighlightedCode.useTheme(name:string) to bootstrap any valid CSS theme by name. This can also be a fully qualified URL to avoid CDN when desired.
  • HighlightedCode.insertText(text:string) to programmatically insert some text where the selection is.
  • HighlightedCode.library:hljs a getter to retrieve the imported hljs library, usable to register missing PLs or do something else.

Exports

The main export uses all default languages included in highlight.js, but there are other variants:

  • highlighted-code/web, which includes only Markdown, JS, TS, JSON, CSS, and HTML or XML
  • highlighted-code/sql, which includes only SQL

These variants are much lighter than default module.

F.A.Q.

You can either textarea.disabled = true or:

<textarea is="highlighted-code" language="css" disabled>
textarea[is="highlighted-code"]::before {
  content: "it's that simple!";
}
</textarea>

You can either textarea.spellcheck = false or:

<textarea is="highlighted-code" language="css" spellcheck="false">
textarea[is="highlighted-code"]::before {
  content: "it's that simple!";
}
</textarea>
<textarea is="highlighted-code" language="css" cols="40" rows="12">
textarea[is="highlighted-code"]::before {
  content: "it's that simple!";
}
</textarea>
<textarea is="highlighted-code" language="css"
          placeholder="write css..."></textarea>

Look, this is a custom element builtin extend.

If you know how and when to use a textarea, you're 90% done with this module.

Now you need just the is attribute with value highlighted-code, a language attribute with a supported language from highlight.js library, optionally a tab-size attribute to have tabs wider than 2, and a theme, where default would work too, as long as HighlightedCode.useTheme('default') is invoked.