unorphan

Obliterate text orphans

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
unorphan
8111.2.17 years ago8 years agoMinified + gzip package size for unorphan in KB

Readme

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 spacenbsp so the last 2 words stick together. Yes, it's smarttest and handles many edge cases.
<!-- before: --> <h1>Hello there world</h1>
<!--  after: --> <h1>Hello there world</h1>



Line breaks — You may also unorphan before line breaks by passing { br: true }.
unorphan('h1, p', { br: true })

<p>4 Privet Drive<br>
Little 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 (listcontributors).
ricostacruz.com  ·  GitHub @rstacruz  ·  Twitter @rstacruz