0.1.1 • Published 3 years ago

rehype-widont v0.1.1

Weekly downloads
10
License
MIT
Repository
github
Last release
3 years ago

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.