excerpt-html
Get the Excerpt from a markdown file (like in jekyll or *smith)
Last updated 8 years ago by leichtgewicht .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ npm install excerpt-html 
SYNC missed versions from official npm registry.

Build Status js-standard-style Maintainability Test Coverage

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.

Current Tags

  • 1.2.2                                ...           latest (4 years ago)

7 Versions

  • 1.2.2                                ...           4 years ago
  • 1.2.1                                ...           6 years ago
  • 1.2.0                                ...           8 years ago
  • 1.1.1                                ...           8 years ago
  • 1.1.0                                ...           8 years ago
  • 1.0.1                                ...           9 years ago
  • 1.0.0                                ...           10 years ago
Maintainers (1)
Downloads
Total 2
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (2)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE