cgiffard / Downsize

Tag safe text truncation for HTML and XML!
BSD 3-Clause "New" or "Revised" License
41 stars 13 forks source link

trailing tags in character mode. #14

Closed adam-zethraeus closed 10 years ago

adam-zethraeus commented 10 years ago
it("should not have trailing empty tags", function () {
downsize("<p>characters</p><i>what</i>", {characters: 10})
.should.equal("<p>characters</p>");
});

This fails with an extra <i></i> just as words mode did before https://github.com/zethraeus/Downsize/commit/5568bfe68d050e3073168daaf18da77a43cb8d9b

i have not further researched why.

cgiffard commented 10 years ago

I'll try look into this on the weekend (but I'm not doing a very good job keeping my promises on this!)

I'm adding you as a collab. now. Just keep my jshint and whitespace the same, and ping me when you want this thing pushed to npm. :)

adam-zethraeus commented 10 years ago

Thanks! Will do. :)

As far as the above issue: it looks like it's related to the way counting works and when it is performed. When counting characters the 'over the limit' count happens before a character that is never added (as opposed to after a character that is). As a result in this example <p>characters</p><i>what</i> the limit is hit at w when </p><i> has already been added to the buffer.

having a count check at the end of tags that doesn't actually increment the counter in the char case might be a reasonable fix.