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.
- Host: GitHub
- URL: https://github.com/pmcelhaney/textsnipper
- Owner: pmcelhaney
- Created: 2010-06-25T18:58:12.000Z (almost 15 years ago)
- Default Branch: master
- Last Pushed: 2010-06-25T18:58:33.000Z (almost 15 years ago)
- Last Synced: 2024-12-27T19:17:46.268Z (4 months ago)
- Language: ColdFusion
- Homepage:
- Size: 89.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.markdown
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()#`