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

@khaister/expressive-code-word-wrap

v1.0.0

Published

An Expressive Code plugin that adds a button to manually toggle word wrap on individual code blocks.

Readme

expressive-code-word-wrap

An Expressive Code plugin that adds a button to every code block, letting readers manually toggle word wrap on and off — similar to the built-in "Copy to clipboard" button.

Expressive Code already supports word wrap, but only as a static, build-time setting (wrap: true in a code fence's meta string, or as a defaultProps config). This plugin adds a client-side toggle on top of that, so wrap can be turned on or off per code block at read time, regardless of how (or whether) wrap was configured for that block.

Installation

npm install @khaister/expressive-code-word-wrap

Usage

Import the plugin's initialization function and add it to your Expressive Code configuration's plugins array.

Astro (astro-expressive-code)

// astro.config.mjs
import { defineConfig } from 'astro/config';
import astroExpressiveCode from 'astro-expressive-code';
import { pluginWordWrap } from '@khaister/expressive-code-word-wrap';

export default defineConfig({
  integrations: [
    astroExpressiveCode({
      plugins: [pluginWordWrap()],
    }),
  ],
});

Starlight

// astro.config.mjs
import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';
import { pluginWordWrap } from '@khaister/expressive-code-word-wrap';

export default defineConfig({
  integrations: [
    starlight({
      title: 'My Docs',
      expressiveCode: {
        plugins: [pluginWordWrap()],
      },
    }),
  ],
});

Plain Expressive Code (e.g. Next.js via remark-expressive-code)

import { pluginWordWrap } from '@khaister/expressive-code-word-wrap';

const config = {
  plugins: [pluginWordWrap()],
};

It composes with @expressive-code/plugin-frames — if you use both, the button joins the same button group as "Copy to clipboard", matching its size, spacing, and hover auto-hide behavior exactly. Plugin order in the plugins array doesn't matter.

Options

pluginWordWrap({
  // Set to `false` to hide the button and only compute the CSS
  // variables word wrap needs (useful if you want to build your own UI)
  // Default: true
  showButton: true,

  // Keep wrapped lines aligned with their original indentation level,
  // matching the built-in `preserveIndent` option
  // Default: true
  preserveIndent: true,
});

Styling

This plugin registers a wordWrap style setting namespace that can be customized via Expressive Code's styleOverrides config option, the same way you'd customize any other plugin's styles:

astroExpressiveCode({
  plugins: [pluginWordWrap()],
  styleOverrides: {
    wordWrap: {
      // icon: createInlineSvgUrl([...]),
    },
  },
});

How it works

Expressive Code's built-in word wrap is a CSS class flip: a wrap class on the code block's <pre> element switches white-space from pre to pre-wrap. This plugin:

  1. Always computes the --ecMaxLine and (optionally) --ecIndent CSS variables that Expressive Code's wrap styles rely on, even for blocks that weren't statically configured with wrap: true.
  2. Renders a toggle button into each code block via the postprocessRenderedBlock hook.
  3. Ships a small client-side script (jsModules) that toggles the wrap class on the nearest <pre> when the button is clicked, and re-initializes buttons after client-side navigation (including Astro view transitions).

Credits

The default button icon is the text-wrap icon from Lucide, used under Lucide's ISC License.