Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only add closing tag for standard HTML tags that are not self-closing #15

Open
luigiv12 opened this issue May 18, 2021 · 2 comments
Open

Comments

@luigiv12
Copy link

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>
@arendjr
Copy link
Owner

arendjr commented May 20, 2021

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.

@arendjr
Copy link
Owner

arendjr commented May 20, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants