Sort the headers before making ToC.

If there are headers of underlined and hashed kind, then make sure they get sorted in line order before building the ToC.

Sorry, I didn't spot this until just now, otherwise I'd have put it into the previous PR.