Issues/1119 smarter next prev links

Closes #1119

Below comments now resolved with new code

~~Specifically I'm not really happy with the code in 57a62fd3efcf16005849243f98400c6d287fba14 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?~~