An open API service indexing awesome lists of open source software.

https://github.com/pmcelhaney/textsnipper

Utility for creating snippets of documents on a search results page.
https://github.com/pmcelhaney/textsnipper

Last synced: 3 months ago
JSON representation

Utility for creating snippets of documents on a search results page.

Awesome Lists containing this project

README

        

# TextSnipper.cfc

Utility for creating snippets of documents on a search results page.

Tell it how long you want your snippet to be (in characters) and what keywords
to find/highlight. Pass an HTML string to the `snip()` function and it will
return a relevant substring with keywords highlighted. It takes care of
little annoyances: stripping unwanted HTML, starting and stopping at word
boundaries, and adding ellipses where necessary.

## Example




#snipper.snip(articleBody)#

> … Lakers G Kobe Bryant in terms of popularity in
> the country. Rovell: “Kobe is clearly bigger than
> LeBron. I’d say he’s at least two times
> bigger, and the reason for that is that Chinese really do respect
> a champion.” Rhoads: “For LeBron and Team
> LeBron, the ultimate objective has to be to get those rings
> onto LeBron’s …

## Notes

* `setMaxLength()` is optional. The default maxLength is 250 characters.
* `setKeywords()` is optional. If no keywords are found, the first part of the text will be snipped.
* It's chainable: `#snipper.setMaxLength(300).setKeywords("foo,bar").snip()#`