Fixing a bug when truncating a string and the last space is within a tag