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

hljs-copy-button

v1.0.4

Published

A plugin for Highlight.js that adds a copy button to code blocks

Readme

Copy Button Plugin for Highlight.js

A customizable copy button plugin for Highlight.js, featuring default SVG icons, clipboard functionality, and optional callbacks. This plugin adds a copy button to code blocks, allowing users to easily copy code snippets with a click.

Features

  • Default SVG icons for copy and check states (customizable).
  • Utilizes the Clipboard API to copy text.
  • Custom callback function after copying.
  • CSS-styled button with smooth hover effects.

Installation

You can install the package via npm:

npm install hljs-copy-button

Usage

Step 1: Import the Plugin and Styles

In your JavaScript file, import the plugin and CSS:

import CopyButton from "hljs-copy-button";

Step 2: Initialize the Plugin

Once imported, you can initialize the plugin and configure it as needed:

const copyPlugin = new CopyButton({
  initialState: '<svg>Your custom SVG or text for the copy state</svg>',
  copiedState: '<svg>Your custom SVG or text for the copied state</svg>',
  callback: (text, button) => {
    console.log("Copied text:", text);
  }
});

hljs.addPlugin(copyPlugin);

Options

initialState: The HTML or SVG content to display in the button's initial state (before copying). copiedState: The HTML or SVG content to display after the text has been copied. callback: A function executed after the text is copied. It receives the copied text and the button element as parameters. includeStyling: A boolean value to include the default CSS styling. Defaults to true. customClasses: An object of custom classes to add to the button and wrapper elements. Defaults to: wrapper: "hljs-custom-copy-wrapper" button: "hljs-custom-copy-button"

Example

const copyPlugin = new CopyButton({
  initialState: '<span>Copy</span>',
  copiedState: '<span>Copied!</span>',
  callback: (text, button) => {
    console.log(`Copied text: ${text}`);
  },
  includeStyling: true,
  customClasses: {
    wrapper: "my-wrapper",
    button: "my-button"
  }
});

Default SVGs

The plugin provides default SVGs for the copy and check icons if no custom content is provided:

  • Copy SVG: A simple copy icon.
  • Check SVG: A checkmark icon that appears after copying.

Styling

The plugin includes a default CSS file with the following styles:

.hljs-custom-copy-wrapper {
    position: relative;
}

.hljs-custom-copy-button {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background-color: transparent !important;
    color: white;
    border: 1px solid #e1e1e1;
    padding: 2px 3px;
    cursor: pointer;
    border-radius: 4px;
    transition: box-shadow 0.3s ease;
}

.hljs-custom-copy-button:focus {
    outline: none;
    background-color: rgba(255, 255, 255, 0.3);
}

.hljs-custom-copy-button:hover {
    box-shadow: inset 0 0 0 10em rgba(255, 255, 255, 0.3);
}

License

MIT License