Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rstacruz/unorphan
Removes text orphans
https://github.com/rstacruz/unorphan
Last synced: about 1 month ago
JSON representation
Removes text orphans
- Host: GitHub
- URL: https://github.com/rstacruz/unorphan
- Owner: rstacruz
- License: mit
- Created: 2015-03-05T08:19:01.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-11-17T00:57:00.000Z (about 9 years ago)
- Last Synced: 2025-01-01T04:49:17.013Z (about 1 month ago)
- Language: JavaScript
- Size: 88.9 KB
- Stars: 81
- Watchers: 6
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
- License: License.md
Awesome Lists containing this project
- awesome-github-repos - rstacruz/unorphan - Removes text orphans (JavaScript)
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](http://en.wikipedia.org/wiki/Widows_and_orphans))
![](http://ricostacruz.com/unorphan/screenshot.png)
[![Status](https://travis-ci.org/rstacruz/unorphan.svg?branch=master)](https://travis-ci.org/rstacruz/unorphan "See test builds")
## Usage
Call `unorphan()` on some nodes.
```js
unorphan('h1, p')
```Or pass on a node, or a list of nodes:
```js
// 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][nbsp] so the last 2 words stick together. Yes, it's [smart][test] and handles many edge cases.
```html
Hello there world
Hello there world
```[nbsp]: https://en.wikipedia.org/wiki/Non-breaking_space
[test]: https://github.com/rstacruz/unorphan/blob/master/test/index/cases_test.js
**Line breaks** — You may also unorphan before line breaks by passing `{ br: true }`.
```js
unorphan('h1, p', { br: true })
``````html
4 Privet Drive
Little Whigging
Surrey
```
## Download
```
npm install unorphan
bower install unorphan
```[![npm version](http://img.shields.io/npm/v/unorphan.svg)](https://npmjs.org/package/unorphan "View this project on npm")
## Thanks
**unorphan** © 2015+, Rico Sta. Cruz. Released under the [MIT] License.
Authored and maintained by Rico Sta. Cruz with help from contributors ([list][contributors]).> [ricostacruz.com](http://ricostacruz.com) ·
> GitHub [@rstacruz](https://github.com/rstacruz) ·
> Twitter [@rstacruz](https://twitter.com/rstacruz)[MIT]: http://mit-license.org/
[contributors]: http://github.com/rstacruz/unorphan/contributors