Have a look at this Dataview snippet to create a table of contents. It could be modified to add margin notes into it: