def create_inline_toc(container, title=None):
 lang = get_book_language(container)
 default_title = u'Table of Contents'
 if lang:
  lang = (lang_as_iso639_1(lang) or lang)
  default_title = translate(lang, default_title)
 title = (title or default_title)
 toc = get_toc(container)
 if (len(toc) == 0):
  return None
 toc_name = find_inline_toc(container)
 name = toc_name
 html = toc_to_html(toc, container, name, title, lang)
 raw = serialize(html, u'text/html')
 if (name is None):
  (name, c) = (u'toc.xhtml', 0)
  while container.has_name(name):
   c += 1
   name = (u'toc%d.xhtml' % c)
  container.add_file(name, raw, spine_index=0)
 else:
  with container.open(name, u'wb') as f:
   f.write(raw)
 set_guide_item(container, u'toc', title, name, frag=u'calibre_generated_inline_toc')
 return name

def create_inline_toc ( container , title = None ) : lang = get_book_language ( container ) default_title = u'Table of Contents' if lang : lang = ( lang_as_iso639_1 ( lang ) or lang ) default_title = translate ( lang , default_title ) title = ( title or default_title ) toc = get_toc ( container ) if ( len ( toc ) == 0 ) : return None toc_name = find_inline_toc ( container ) name = toc_name html = toc_to_html ( toc , container , name , title , lang ) raw = serialize ( html , u'text/html' ) if ( name is None ) : ( name , c ) = ( u'toc.xhtml' , 0 ) while container . has_name ( name ) : c += 1 name = ( u'toc%d.xhtml' % c ) container . add_file ( name , raw , spine_index = 0 ) else : with container . open ( name , u'wb' ) as f : f . write ( raw ) set_guide_item ( container , u'toc' , title , name , frag = u'calibre_generated_inline_toc' ) return name
create an inline table of contents from an existing ncx table of contents .