https://github.com/martinheidegger/excerpt-html
Parses a given html text for a good excerpt.
https://github.com/martinheidegger/excerpt-html
excerpt html parse
Last synced: 3 months ago
JSON representation
Parses a given html text for a good excerpt.
- Host: GitHub
- URL: https://github.com/martinheidegger/excerpt-html
- Owner: martinheidegger
- License: mit
- Created: 2015-05-12T09:16:10.000Z (about 11 years ago)
- Default Branch: main
- Last Pushed: 2021-04-16T14:08:47.000Z (about 5 years ago)
- Last Synced: 2024-12-22T18:37:47.511Z (over 1 year ago)
- Topics: excerpt, html, parse
- Language: JavaScript
- Size: 68.4 KB
- Stars: 11
- Watchers: 3
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/martinheidegger/excerpt-html)
[](http://standardjs.com/)
[](https://codeclimate.com/github/martinheidegger/excerpt-html/maintainability)
[](https://codeclimate.com/github/martinheidegger/excerpt-html/test_coverage)
# excerpt-html
parses a given html text for a good excerpt.
# Install
```
$ npm i excerpt-html --save
```
# API usage
```JavaScript
var htmlCode = '
Hello world
';
var excerptHtml = require('excerpt-html');
var excerpt = excerptHtml(htmlCode);
```
It will either use the first found paragraph or everything up to a
``
# Options
You can specify a few options that modify the way the excerpt is parsed:
``` JavaScript
excerptHtml(htmlCode, {
moreRegExp: /\s*/i, // Search for the slug
stripTags: true, // Set to false to get html code
pruneLength: 140, // Amount of characters that the excerpt should contain
pruneString: '…', // Character that will be added to the pruned string
pruneSeparator: ' ', // Separator to be used to separate words
})
```
Note: `pruneLength` and `prunestring` only work when `stripTags` is set to `true` (default).
# History
To make this project we detached the code of [metalsmith-better-excerpts](https://github.com/simbo/metalsmith-better-excerpts) from `metalsmith`.