def _parse_html_table_of_contents(html):
 lines = html.splitlines()[2:(-2)]
 parents = []
 ret = []
 for line in lines:
  parser = TOCParser()
  parser.feed(line)
  if parser.title:
   try:
    href = parser.attrs[u'href']
   except KeyError:
    continue
   title = parser.title
   nav = AnchorLink(title, href)
   if parents:
    parents[(-1)].children.append(nav)
   else:
    ret.append(nav)
   if line.endswith(u'<ul>'):
    parents.append(nav)
  elif line.startswith(u'</ul>'):
   if parents:
    parents.pop()
 if ret:
  ret[0].active = True
 return ret

def _parse_html_table_of_contents ( html ) : lines = html . splitlines ( ) [ 2 : ( - 2 ) ] parents = [ ] ret = [ ] for line in lines : parser = TOCParser ( ) parser . feed ( line ) if parser . title : try : href = parser . attrs [ u'href' ] except KeyError : continue title = parser . title nav = AnchorLink ( title , href ) if parents : parents [ ( - 1 ) ] . children . append ( nav ) else : ret . append ( nav ) if line . endswith ( u'<ul>' ) : parents . append ( nav ) elif line . startswith ( u'</ul>' ) : if parents : parents . pop ( ) if ret : ret [ 0 ] . active = True return ret
given a table of contents string that has been automatically generated by the markdown library .