bug fix: Because _do_links is not applied to the text in text flow order, footnotes are not generated in proper order, we have to sort them before _add_footnotes.