nodejs-html-truncate icon indicating copy to clipboard operation
nodejs-html-truncate copied to clipboard

Library does not truncate text of links

Open damianwojakowski opened this issue 8 years ago • 5 comments

Hi there!

I started using this library some time ago and I've noticed that it is not truncating links.

If I have a link, e.g.

<a href="someUrl">SomeLongTextOfALinkEvenLongerThanThis</a>

then this library is always going to display the whole text (I mean the "SomeLongTextOfALinkEvenLongerThanThis"), it does not truncate it.

Another thing - If you have a clickable block of text from a source that you don't control (e.g. RSS channel), then there's no way to simply truncate it with this library - you need to do additional work.

Please, have a look at this problem.

Regards,

  • Damian Wojakowski.

damianwojakowski avatar Jul 01 '16 10:07 damianwojakowski

Do you have an example? I just tried this, and it worked:

~/code/js/html-trunc >node
> var truncate = require('html-truncate');
undefined
> truncate('<a href="someUrl">SomeLongTextOfALinkEvenLongerThanThis</a>', 4)
'<a href="someUrl">Some...</a>'
> truncate('<p><div><a href="someUrl">SomeLongTextOfALinkEvenLongerThanThis</a>hello world</div></p>', 4)
'<p><div><a href="someUrl">Some...</a></div></p>'

sshaw avatar Jul 22 '16 15:07 sshaw

Hi,

I gave you just a simple example (not real) to describe what's the problem.

This library has problems with links. I used it at work (for a project similar to facebook), we had ton's of links there and some business rules for truncating links on many "components" (e.g. profiles, chatbox), this library had problems with truncating quite a lot of links.

Finally we replaced it with another lib that handled the problems.

I don't remember what kind of liks were they and I don't have time to test it now. Just try a few possibilities.

Maybe when there's a link in tag (instead of text), or maybe when the words in tag are separated. It definatelly did not work for long links (like I described it above, e.g. when you got a lot of text from RSS source and you wanted to make it clickable.

Regards, Damian Wojakowski.

damianwojakowski avatar Jul 25 '16 06:07 damianwojakowski

Have you seen/tried this?

sshaw avatar Jul 25 '16 13:07 sshaw

No, I haven't. I tried other libarary.

damianwojakowski avatar Jul 25 '16 17:07 damianwojakowski

I encountered a similar issue where the library fails to function properly with hyperlinks. In my experience, this resulted in unexpected behavior, including triggering an infinite loop that caused browser hang-ups.

Noushad-web avatar Mar 07 '24 06:03 Noushad-web