cgiffard/Downsize — pull request #22 by remy (2014-09-01 15:16:54+00:00)
Title: Add support for rounding to end of sentence

Use:

```js
downsize("

My super long sentence that I don't want chomped.

But I would like around 75 characters on the page, but I don't want to cut halfway through a sentence.

", {
characters: 75,
round: true
}); // result: original two

tags
```

Also includes initial tests (all passing) (could do with more?)

If options.round is used, then as the text is parsed, if it hits the character limit, it also checks to see if it's at the edge of a closing sentence tag . If not, it'll continue to scoop up the text.

If the parser reaches a `PARSER_TAG_COMMENCED` character (`<`), then it peeks at the upcoming HTML, and checks if that tag would suggest the end of a sentence, i.e. a `

`, `

`, `
`, etc.

Note: I also tested that it works correctly with unclosed `

` tags, which it does, but the current version of Downsize tries to close all tracked open tags (so if there's more than one automatic closing `

` tag), they're all slapped on the end of the string, resulting in: `

foo

bar

` - this is a completely separate bug which may or may not be worth dealing with.