def generate_page_toc(soup):
 found_depth_counts = collections.defaultdict(int)
 for tag in soup.find_all(_heading_re):
  if (tag.get(u'id') or tag.get(u'name')):
   found_depth_counts[hdepth(tag)] += 1
 depth_list = [i for i in range(100) if (1 < found_depth_counts[i])]
 depth_list = depth_list[:4]
 toc = []
 for tag in soup.find_all(_heading_re):
  depth = hdepth(tag)
  if (depth in depth_list):
   toc.append(dict(depth=(depth_list.index(depth) + 1), link=(tag.get(u'id') or tag.get(u'name')), text=tag.text))
 return toc

def generate_page_toc ( soup ) : found_depth_counts = collections . defaultdict ( int ) for tag in soup . find_all ( _heading_re ) : if ( tag . get ( u'id' ) or tag . get ( u'name' ) ) : found_depth_counts [ hdepth ( tag ) ] += 1 depth_list = [ i for i in range ( 100 ) if ( 1 < found_depth_counts [ i ] ) ] depth_list = depth_list [ : 4 ] toc = [ ] for tag in soup . find_all ( _heading_re ) : depth = hdepth ( tag ) if ( depth in depth_list ) : toc . append ( dict ( depth = ( depth_list . index ( depth ) + 1 ) , link = ( tag . get ( u'id' ) or tag . get ( u'name' ) ) , text = tag . text ) ) return toc
return page-level toc template data for soup .