Issues/1119 smarter next prev links

:warning: not ready for merge, PR is to solicit comments.

Closes #1119

Specifically I'm not really happy with the code in 38fc482664e944b36f1d9bf3f7b85df0738402ae which does exactly what #1119 wants, but seems overly convoluted and very inefficient (even after the caching that could be added).

However aside from navigating the section hierarchy as this does I can think of a better way to do it. Perhaps something involving tags?