@canner/excerpt-html

1.2.0 • Public • Published

Build Status Coverage Status js-standard-style

excerpt-html

parses a given html text for a good excerpt.

Install

$ npm i excerpt-html --save

API usage

var htmlCode = '<p>Hello world</p>';
var excerptHtml = require('excerpt-html');
var excerpt = excerptHtml(htmlCode);

It will either use the first found paragraph or everything up to a

<!-- more -->

Options

You can specify a few options that modify the way the excerpt is parsed:

excerptHtml(htmlCode, {
    moreRegExp:  /\s*<!--\s*more\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 from metalsmith.

Package Sidebar

Install

npm i @canner/excerpt-html

Weekly Downloads

2

Version

1.2.0

License

ISC

Unpacked Size

7.66 kB

Total Files

6

Last publish

Collaborators

  • wwwy3y3
  • cannerbot