martinheidegger / excerpt-html

Parses a given html text for a good excerpt.
MIT License
11 stars 5 forks source link

Option to ignore H1-H6 headings #5

Open zeke opened 7 years ago

zeke commented 7 years ago

Say I have some HTML like this:

<h1>Title</h1>
<p>Hello, world</p>
<p>Hello again, world</p>
<hr>
<p>This is where the content really gets going, world</p>

I want to use <hr> as the excerpt cutoff, like so:

excerpt(myString, {moreRegExp: /<hr>/i})

Unfortunately the excerpt also includes the <h1> content. Would you be open to adding an option to omit h1-h6 tags from the excerpt?

A real-world example of this can be found on the Electron blog, where Jekyll's excerpt creation ignores headings by default:

screen shot 2017-06-26 at 2 44 55 pm
martinheidegger commented 7 years ago

I guess it is perfectly possible to add that ^_^ any PR welcome!