I'm just going to skip reviewing this until we figure out what it should actually do. There will definitely need to be some sort of user interaction. It might actually be the case that the best fix is just a set of CSS styles that highlight invalid headers with red backgrounds and some help text, or maybe something that just moves the user's selection to the next invalid header.