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

@rgglez/rehype-hyphenate

v0.1.0

Published

rehype plugin that inserts soft hyphens at build time with TeX (Liang) hyphenation patterns, following each element's lang attribute.

Downloads

272

Readme

rehype-hyphenate

License

rehype-hyphenate is a rehype plugin that inserts soft hyphens (U+00AD) into the text at build time, using the TeX hyphenation patterns (Franklin Liang's algorithm) from hyphen. The patterns follow each element's lang attribute, so a German word inside a Spanish paragraph is hyphenated as German.

The plugin only marks where a word may break. The browser still decides where each line ends and shows a hyphen only at a line break, so the result stays responsive. Nothing runs on the client.

Install

npm install @rgglez/rehype-hyphenate

Usage

unified

import { unified } from "unified";
import rehypeParse from "rehype-parse";
import rehypeStringify from "rehype-stringify";
import rehypeHyphenate from "@rgglez/rehype-hyphenate";

const html = await unified()
  .use(rehypeParse, { fragment: true })
  .use(rehypeHyphenate, { lang: "es" })
  .use(rehypeStringify)
  .process("<p>La separación silábica funciona correctamente.</p>");
// <p>La se·pa·ra·ción si·lá·bi·ca fun·cio·na co·rrec·ta·men·te.</p>
// (· stands for the invisible U+00AD)

Astro

// astro.config.mjs
import { defineConfig } from "astro/config";
import rehypeHyphenate from "@rgglez/rehype-hyphenate";

export default defineConfig({
  markdown: {
    rehypePlugins: [
      // Language from each file's frontmatter (`lang: es`).
      [rehypeHyphenate, { lang: file => file.data.astro?.frontmatter?.lang }],
    ],
  },
});

lang can also come from the file path, for example file => file.path?.match(/\/(es|en|fr)\//)?.[1] for content stored in language folders.

  • MDX: mdx({ extendMarkdownConfig: true }) (the default) applies the same plugins to .mdx files.
  • Astro 7: Markdown uses Sätteri by default, and markdown.rehypePlugins needs the unified processor. Install it with npm install @astrojs/markdown-remark. Astro 6 and earlier include it.

CSS

Soft hyphens work with the default hyphens: manual. Justified text with text-wrap: pretty gets the closest result to TeX that browsers offer today:

article p,
article li {
  text-align: justify;
  hyphens: manual;
  text-wrap: pretty;
}

hyphens: none disables the soft hyphens. hyphens: auto adds the browser's own hyphenation on top of them.

Options

| Option | Default | Description | | :----- | :------ | :---------- | | lang | none | Document language: a BCP 47 tag or (file) => tag. Without it, only text inside a lang attribute is hyphenated | | minWordLength | 6 | Shorter words are left alone | | hyphenChar | U+00AD | Inserted at each break point (soft hyphen) | | exceptions | none | Fixed break points per language: { en: ["ta-ble"] } | | ignoreTags | see below | Elements skipped with their subtree. Replaces the default | | ignoreClassNames | [/^katex/, "expressive-code"] | Class names (string or RegExp) skipped with their subtree |

defaultIgnoreTags and defaultIgnoreClassNames are exported, so you can extend them:

import rehypeHyphenate, { defaultIgnoreTags } from "@rgglez/rehype-hyphenate";

[rehypeHyphenate, { lang: "en", ignoreTags: [...defaultIgnoreTags, "figcaption"] }];

Languages

The nearest lang attribute wins; the lang option is the fallback for text with no lang ancestor. A tag tries its exact hyphen module first and then its primary subtag: es-MX uses es, de-1996 uses de-1996. Patterns load on first use, once per process.

These are left unhyphenated:

  • Tags without patterns in hyphen, and lang="" (unknown language).
  • Chinese, Japanese and Korean (zh, ja, ko). The zh module in hyphen is for pinyin; ask for it explicitly with zh-Latn-pinyin.
  • Malformed tags. The tag becomes part of an import path, so only [a-z]{2,3}(-[a-z0-9]{1,8})* is accepted.

What is skipped

  • Headings (h1–h6). Heading-id plugins derive the id from the heading text, and a soft hyphen would end up inside the anchor.
  • Code and preformatted text (code, pre, kbd, samp, var), head, script, style, template, textarea, svg and math.
  • KaTeX output and Expressive Code frames.
  • Any element with a data-nohyphenate attribute.
  • Words that contain :// or @, or start with www.. A soft hyphen in a URL or an e-mail address would be copied with it.

Search engines and copy-paste

Static search indexes read the hyphenated HTML. With Pagefind 1.5, searching for a word finds it even though the index stores it with soft hyphens, and the result excerpts keep them (they are invisible). Test other search engines before relying on them.

Most applications drop soft hyphens on paste. Some plain-text editors keep them as an invisible character.

Development

npm install
npm test
npm run build

Makefile

| Target | What it does | | :----- | :----------- | | make tags | Lists the existing git tags, newest first. | | make test | Runs the tests (npm test). | | make patch | Bumps the patch number in package.json (0.1.0 → 0.1.1), commits, tags v0.1.1, and pushes the branch and the tag to origin. | | make publish | Runs make test, then npm publish --access public. npm runs prepublishOnly (tsc) first, so dist/ is rebuilt before upload. |

make patch only bumps the patch number. For a minor or major release, edit version in package.json, then commit, tag and push by hand.

To publish a release:

  1. In package.json, change the scope in name (@rgglez) to an npm scope you have publish rights on, and log in with npm login.

  2. Bump the version, tag it and push:

    make patch
  3. Test and publish:

    make publish

Live example

The plugin can be viewed live here.

You can run it locally from the example directory.

License

Copyright (c) 2026 Rodolfo González González.

Licensed under the Apache-2.0 license. Read the LICENSE file.