This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

rehype-widont
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

rehype-widont

This Rehype plugin prevents what is commonly called "widows" in typesetting lingo, i.e., lines of text made of only one word. This is achieved by replacing whitespace before the last word with a non-breaking space (U+00A0), which makes that word and the preceding one stick together.

Although rehype-widont uses a different approach, it borrows the name of Shaun Inman's WordPress plugin.

Installation

npm install rehype-widont

# or, if using Yarn:
yarn add rehype-widont

Usage

NOTE: rehype-widont inserts an actual non-breaking space character instead of  , but the entity is used in the following example for clarity's sake.

var rehype = require("rehype");
var widont = require("rehype-widont");

var processor = rehype()
  .data("settings", { fragment: true })
  .use(widont);

processor.processSync("<p>This shall be just fine.</p>");
// returns "<p>This shall be just&nbsp;fine.</p>"

processor.processSync("<p>It can handle <em>nested tags</em>.</p>");
// returns "<p>It can handle <em>nested&nbsp;tags</em>.</p>"

processor.processSync("<p>See? This <em>is</em> awesome.</p>");
// returns "<p>See? This <em>is</em>&nbsp;awesome.</p>"

Options

selector

Which tags to look inside and prevent widows (string, default: "p, h1, h2, h3, h4, h5, h6, li, dt, dd"). Accepts any value that hast-util-select does.

License

MIT.

Readme

Keywords

none

Package Sidebar

Install

npm i rehype-widont

Weekly Downloads

13

Version

0.1.1

License

MIT

Unpacked Size

7.64 kB

Total Files

7

Last publish

Collaborators

  • odnamrataizem