Add ancestry to TOC anchors (take 3)

Fixes gollum/gollum#678.

OK take 3; merging into the `rc` branch now.  Fixed syntax errors from #108.  I already did a test merge on my machine and there is a conflict.