arendjr / text-clipper

Fast and correct clip functions for HTML and plain text
MIT License
133 stars 13 forks source link

Invalid HTML error if the content contains special characters (<3) #24

Closed mrdeeds88 closed 9 months ago

mrdeeds88 commented 9 months ago

Hi there, I tested with the content that contains the heart icon using "<3" It shows error: text-clipper.js?v=44260d94:173 Uncaught Error: Invalid HTML: the text <3 <3

0h9zieA

Do you have any idea for fixing this?

Thanks!

mrdeeds88 commented 9 months ago

I was fixed this by pre-format the content before parse it to clipper.

arendjr commented 9 months ago

Yeah, I would say this is by design, since "<3" should be encoded as &lt;3 to be valid HTML. I suppose things could be made a bit more resilient by implementing the fallbacks that HTML5 specifies for invalid HTML, but I'm afraid that would add a huge amount of complexity to the library.

So I'm closing since you found a workaround. Thanks for the report, it's indeed something to be aware of!