parameters: (self, text_buffer, node_id, just_get_toc_list=False)
return_statement: return self.toc_list
docstring: Given the text_buffer, inserts the Table Of Contents
docstring_summary: Given the text_buffer, inserts the Table Of Contents
docstring_tokens: Given the text_buffer inserts the Table Of Contents
function: def toc_insert_one(self, text_buffer, node_id, just_get_toc_list=False):
          """Given the text_buffer, inserts the Table Of Contents"""
          self.curr_attributes = {}
          self.toc_counters = {cons.TAG_PROP_H1:0, cons.TAG_PROP_H2:0, cons.TAG_PROP_H3:0}
          self.toc_list = [] # 0: anchor name; 1: text in h1, h2 or h3; 2:node id
          for tag_property in cons.TAG_PROPERTIES: self.curr_attributes[tag_property] = ""
          start_iter = text_buffer.get_start_iter()
          end_iter = text_buffer.get_end_iter()
          curr_iter = start_iter.copy()
          self.rich_text_attributes_update(curr_iter, self.curr_attributes)
          tag_found = self.safe_forward_to_h_toggle(curr_iter)
          while tag_found:
              offsets = self.toc_insert_parser(text_buffer, start_iter, curr_iter, node_id)
              if offsets:
                  start_iter = text_buffer.get_iter_at_offset(offsets[0])
                  curr_iter = text_buffer.get_iter_at_offset(offsets[1])
                  end_iter = text_buffer.get_end_iter()
              if curr_iter.compare(end_iter) == 0: break
              else:
                  self.rich_text_attributes_update(curr_iter, self.curr_attributes)
                  offset_old = curr_iter.get_offset()
                  start_iter.set_offset(offset_old)
                  tag_found = self.safe_forward_to_h_toggle(curr_iter)
                  if curr_iter.get_offset() == offset_old: break
          else: self.toc_insert_parser(text_buffer, start_iter, curr_iter, node_id)
          if self.toc_list and not just_get_toc_list:
              tag_property = cons.TAG_LINK
              property_value = cons.LINK_TYPE_NODE + cons.CHAR_SPACE + str(node_id)
              curr_offset = 0
              text_buffer.insert(text_buffer.get_iter_at_offset(curr_offset), cons.CHAR_NEWLINE)
              curr_offset += 1
              for element in self.toc_list:
                  tag_names = []
                  tag_names.append(self.dad.apply_tag_exist_or_create(tag_property, property_value + cons.CHAR_SPACE + element[0]))
                  if element[0][:2] == cons.TAG_PROP_H1:
                      text_buffer.insert(text_buffer.get_iter_at_offset(curr_offset), self.dad.chars_toc[1] + cons.CHAR_SPACE)
                      curr_offset += 2
                  elif element[0][:2] == cons.TAG_PROP_H2:
                      text_buffer.insert(text_buffer.get_iter_at_offset(curr_offset), 2*cons.CHAR_SPACE + self.dad.chars_toc[2] + cons.CHAR_SPACE)
                      curr_offset += 4
                  else:
                      text_buffer.insert(text_buffer.get_iter_at_offset(curr_offset), 4*cons.CHAR_SPACE + self.dad.chars_toc[3] + cons.CHAR_SPACE)
                      curr_offset += 6
                  text_buffer.insert(text_buffer.get_iter_at_offset(curr_offset), cons.CHAR_NEWLINE)
                  text_buffer.insert_with_tags_by_name(text_buffer.get_iter_at_offset(curr_offset), element[1], *tag_names)
                  curr_offset += 1
                  while text_buffer.get_iter_at_offset(curr_offset).get_char() != cons.CHAR_NEWLINE:
                      curr_offset += 1
                  curr_offset += 1
              text_buffer.insert(text_buffer.get_iter_at_offset(curr_offset), cons.CHAR_NEWLINE)
          return self.toc_list
function_tokens: def toc_insert_one ( self , text_buffer , node_id , just_get_toc_list = False ) : self . curr_attributes = { } self . toc_counters = { cons . TAG_PROP_H1 : 0 , cons . TAG_PROP_H2 : 0 , cons . TAG_PROP_H3 : 0 } self . toc_list = [ ] # 0: anchor name; 1: text in h1, h2 or h3; 2:node id for tag_property in cons . TAG_PROPERTIES : self . curr_attributes [ tag_property ] = "" start_iter = text_buffer . get_start_iter ( ) end_iter = text_buffer . get_end_iter ( ) curr_iter = start_iter . copy ( ) self . rich_text_attributes_update ( curr_iter , self . curr_attributes ) tag_found = self . safe_forward_to_h_toggle ( curr_iter ) while tag_found : offsets = self . toc_insert_parser ( text_buffer , start_iter , curr_iter , node_id ) if offsets : start_iter = text_buffer . get_iter_at_offset ( offsets [ 0 ] ) curr_iter = text_buffer . get_iter_at_offset ( offsets [ 1 ] ) end_iter = text_buffer . get_end_iter ( ) if curr_iter . compare ( end_iter ) == 0 : break else : self . rich_text_attributes_update ( curr_iter , self . curr_attributes ) offset_old = curr_iter . get_offset ( ) start_iter . set_offset ( offset_old ) tag_found = self . safe_forward_to_h_toggle ( curr_iter ) if curr_iter . get_offset ( ) == offset_old : break else : self . toc_insert_parser ( text_buffer , start_iter , curr_iter , node_id ) if self . toc_list and not just_get_toc_list : tag_property = cons . TAG_LINK property_value = cons . LINK_TYPE_NODE + cons . CHAR_SPACE + str ( node_id ) curr_offset = 0 text_buffer . insert ( text_buffer . get_iter_at_offset ( curr_offset ) , cons . CHAR_NEWLINE ) curr_offset += 1 for element in self . toc_list : tag_names = [ ] tag_names . append ( self . dad . apply_tag_exist_or_create ( tag_property , property_value + cons . CHAR_SPACE + element [ 0 ] ) ) if element [ 0 ] [ : 2 ] == cons . TAG_PROP_H1 : text_buffer . insert ( text_buffer . get_iter_at_offset ( curr_offset ) , self . dad . chars_toc [ 1 ] + cons . CHAR_SPACE ) curr_offset += 2 elif element [ 0 ] [ : 2 ] == cons . TAG_PROP_H2 : text_buffer . insert ( text_buffer . get_iter_at_offset ( curr_offset ) , 2 * cons . CHAR_SPACE + self . dad . chars_toc [ 2 ] + cons . CHAR_SPACE ) curr_offset += 4 else : text_buffer . insert ( text_buffer . get_iter_at_offset ( curr_offset ) , 4 * cons . CHAR_SPACE + self . dad . chars_toc [ 3 ] + cons . CHAR_SPACE ) curr_offset += 6 text_buffer . insert ( text_buffer . get_iter_at_offset ( curr_offset ) , cons . CHAR_NEWLINE ) text_buffer . insert_with_tags_by_name ( text_buffer . get_iter_at_offset ( curr_offset ) , element [ 1 ] , * tag_names ) curr_offset += 1 while text_buffer . get_iter_at_offset ( curr_offset ) . get_char ( ) != cons . CHAR_NEWLINE : curr_offset += 1 curr_offset += 1 text_buffer . insert ( text_buffer . get_iter_at_offset ( curr_offset ) , cons . CHAR_NEWLINE ) return self . toc_list