def _fix_global_ids(html):
 html = re.sub('id="\\d+"', 'id="###"', html)
 global_id = 1
 while (len(re.findall('id="###"', html)) > 0):
  html = re.sub('id="###"', ('id="%s"' % global_id), html, count=1)
  global_id += 1
 return html

def _fix_global_ids ( html ) : html = re . sub ( 'id="\\d+"' , 'id="###"' , html ) global_id = 1 while ( len ( re . findall ( 'id="###"' , html ) ) > 0 ) : html = re . sub ( 'id="###"' , ( 'id="%s"' % global_id ) , html , count = 1 ) global_id += 1 return html
fix the global_ids after reordering in _render_toc() .