<commit_before># 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")

<br>

## Usage

Call `unorphan()` on some nodes. This changes last orphan space to an `&nbsp;` so the last 2 words stick together.

```js
unorphan('h1, p')
// '<h1>Hello there world</h1>' => '<h1>Hello there&nbsp;world</h1>'
```

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

```js
// Node
unorphan(document.querySelector('#top-heading h1'))<commit_msg>Link to explanation on nbsp's<commit_after># 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")

<br>

## Usage

Call `unorphan()` on some nodes. This changes last orphan space to a [non-breaking space][nbsp] so the last 2 words stick together.

[nbsp]: https://en.wikipedia.org/wiki/Non-breaking_space

```js
unorphan('h1, p')
// '<h1>Hello there world</h1>' => '<h1>Hello there&nbsp;world</h1>'
```

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

```js
// Node
unorphan(document.querySelector('#top-heading h1'))
{'fraction_non_alphanumeric': 0.16780185758513932, 'fraction_numerical': 0.0086687306501548, 'mean_word_length': 4.750889679715303, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2576604', 'n_tokens_mistral': 612, 'n_tokens_neox': 584, 'n_words': 162}