unorphan
Obliterate text orphans
Last updated 5 years ago by rstacruz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install unorphan 
SYNC missed versions from official npm registry.

unorphan.js

Prevents text orphans.

orphan (n.) A word, part of a word, or very short line that appears by itself at the end of a paragraph. (via Wikipedia)

Status


Usage

Call unorphan() on some nodes.

unorphan('h1, p')

Or pass on a node, or a list of nodes:

// Node
unorphan(document.querySelector('#top-heading h1'))

// NodeList
unorphan(document.querySelectorAll('h1, p'))

// jQuery
unorphan($('h1, p'))

How does it work? — This changes last orphan space to a non-breaking space so the last 2 words stick together. Yes, it's smart and handles many edge cases.

<!-- before: --> <h1>Hello there world</h1>
<!--  after: --> <h1>Hello there&nbsp;world</h1>

Line breaks — You may also unorphan before line breaks by passing { br: true }.

unorphan('h1, p', { br: true })
<p>4 Privet&nbsp;Drive<br>
Little&nbsp;Whigging<br>
Surrey</p>

Download

npm install unorphan
bower install unorphan

npm version


Thanks

unorphan © 2015+, Rico Sta. Cruz. Released under the MIT License.
Authored and maintained by Rico Sta. Cruz with help from contributors (list).

ricostacruz.com  ·  GitHub @rstacruz  ·  Twitter @rstacruz

Current Tags

  • 1.2.1                                ...           latest (5 years ago)

5 Versions

  • 1.2.1                                ...           5 years ago
  • 1.2.0                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 0
Dependencies (0)
None
Dev Dependencies (8)

Copyright 2014 - 2016 © taobao.org |