Fix documentation rendering edge-cases [Fixes #795]

Also added some notably absent tests