echo variable containing html and the_permalink();

You need to use get_permalink(), which will return the URL as opposed to echo’ing it.