Html tag completion algorithm