nodejs-html-truncate
nodejs-html-truncate copied to clipboard
Doesn't work with <img /> tags, somehow
trafficstars
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.
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?
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>