Structured headers

Similar to the existing headers method but returns a nested structure.

This is for use in the Content API so that it can construct a nested
view of all the headings contained in a document for display in the
side bar.