Logic to correct invalid HTML