code: public List<? extends IdElement> headingTree(String content) {
  
  		Element body = parseContent(content);
  
  		List<String> headIds = concat(HEADINGS, "[id]", true);
  
  		// select all headings that have an ID
  		List<Element> headings = body.select(StringUtil.join(headIds, ", "));
  
  		List<HeadingItem> headingItems = new ArrayList<HeadingItem>();
  		for (Element heading : headings) {
  			headingItems.add(new HeadingItem(heading.id(), heading.text(), headingIndex(heading)));
  		}
  
  		List<HeadingItem> topHeadings = new ArrayList<HeadingItem>();
  		Stack<HeadingItem> parentHeadings = new Stack<HeadingItem>();
  
  		for (HeadingItem heading : headingItems) {
  
  			while (!parentHeadings.isEmpty()
  					&& parentHeadings.peek().headingIndex >= heading.headingIndex) {
  				parentHeadings.pop();
  			}
  
  			if (parentHeadings.isEmpty()) {
  				// top level heading - no parents
  				topHeadings.add(heading);
  			} else {
  				// add to the children of topmost stack parent
  				parentHeadings.peek().children.add(heading);
  			}
  
  			// push the heading onto stack
  			parentHeadings.push(heading);
  		}
  
  		return topHeadings;
  	}
docs: Reads all headings in the given HTML content as a hierarchy. Subsequent smaller headings are
  nested within bigger ones, e.g. {@code <h2>} is nested under preceding {@code <h1>}.
  <p>
  Only headings with IDs are included in the hierarchy. The result elements contain ID and
  heading text for each heading. The hierarchy is useful to generate a Table of Contents for a
  page.
  </p>
  
  @param content
  HTML content to extract heading hierarchy from
  @return a list of top-level heading items (with id and text). The remaining headings are
  nested within these top-level items. Empty list if no headings are in the content.
  @since 1.0