huang47 / nodejs-html-truncate

truncate html text and keep tag safe
77 stars 30 forks source link

Doesn't work with <img /> tags, somehow #5

Open rlipscombe opened 11 years ago

rlipscombe commented 11 years ago
var t = require('html-truncate');
t('<ul><li><img src="image-1" /><img src="image-2" /></li></ul>', 40);

...returns

<ul><li><img src="image-2" /><img src="image-2" />

...rather than anything sensible.

Moreover, increasing the requested length doesn't fix it (passing 1000 instead of 40) gives the same result.

rlipscombe commented 11 years ago

So, thinking it might be a problem with the <img />, rather than <img>, I tried the following:

t('<ul><li><img src="image-1"><img src="image-2"></li></ul>', 1000);

...which returns:

<ul><li><img src="image-2"></li></ul></li></ul>

...which is still wrong. Where did the first image go?

orourkedd commented 9 years ago

I had the same problem, but with <br> tags. The issue seems to be that its trying to close the tags. For example, this:

<br>test

becomes:

<br>tes</br>