Only add closing tag for standard HTML tags that are not self-closing
Opened this issue · 2 comments
When clipping HTML, would it be possible to not add a closing tag for strings that aren't actually HTML tags?
So if I do something like this:
clip('<p>The quick brown <fox> jumps over the lazy dog', 30, { html: true })
Since <fox>
isn't actually a valid HTML tag, I'm hoping to get:
<p>The quick brown <fox> jumps over …</p>
instead of:
<p>The quick brown <fox> jumps over …</fox></p>
There's currently no option for that, but it would be relatively simple to create this. Right now the library already has a built-in list of "void elements" such as <br> that should never be closed. I think the easiest approach (if you know which tags you might encounter in your situation) is to allow extending that list, and I'd happily accept a PR for that.
If it could be any tag, it would be a little more involved, because then the behavior would need to be reversed and it would need to rely on a "non-void elements" list, which it currently does not have.
I could also possibly offer a workaround, because if I'm not mistaken, if you passed <fox/>
instead of <fox>
it should already be recognized as self-closing and you'd get the desired behavior. So if this is possible for you, a little preprocessing might do the trick then.