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

Count the HTML tags in maxLength #6

Open
nolate opened this issue Jul 1, 2019 · 1 comment
Open

Count the HTML tags in maxLength #6

nolate opened this issue Jul 1, 2019 · 1 comment

Comments

@nolate
Copy link

nolate commented Jul 1, 2019

I'd like to suggest to have the option to count the length of HTML tags in maxLength. I need an email template that can't exceed 255 chars but if template.length - tagsInTemplate.length < 255 than the clipper will return my original template which is longer than 255 with the tags.

@arendjr
Copy link
Owner

arendjr commented Jul 25, 2019

This is an interesting request. Almost all logic in text-clipper is aimed towards counting characters and lines, which you don't need if you care more about the template size than the actual character count.

I also suspect there is another important difference there: I suspect your maximum template length would be a byte-count, or maybe a count of UTF16 codepoints, whereas text-clipper counts Unicode characters in order to prevent breaking up Unicode surrogate pairs (note this can still break up compound emojis into the individual emoji characters, but at least individual emojis won't be broken up into invalid Unicode characters).

All that logic isn't relevant when you care primarily about raw length of the HTML, it seems the only logic that you would be interested in is finding a suitable position for breaking up the HTML string. I suppose a solution like that could be created using some of the logic inside text-clipper, but for me personally it's too far out of scope to implement myself.

If someone would create a PR that implements this suggestion, without harming the performance and complexity of the already existing clippers, I'd be willing to accept that. But that probably means implementing a separate (simpler) clipRawHtml() function next to the already existing clipHtml() implementation.

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