def tt2nav(toctree, klass=None, appendix=None, divider=False):
    """
    Injects ``has-dropdown`` and ``dropdown`` classes to HTML
    generated by the :func:`toctree` function.
    
    :param str toctree:
        HTML generated by the :func:`toctree` function.
    """
    
    tt = toctree
    divider = '<li class="divider"></li>' if divider else ''
    
    # Append anything just before the closing </ul>.
    if appendix:
        tt = re.sub(r'(</ul>$)', r'{}\1'.format(appendix), tt)
    
    # Add class attribute to all <ul> elements.
    tt = re.sub(r'<ul>', r'<ul class="">', tt)
    
    # Add class to first <ul> tag.
    if klass:
        tt = re.sub(r'(^<ul[\s\w-]+class=")', r'\1{} '.format(klass), tt)
    
    # Add class "active" to all <li> tags with "current" class.
#    tt = re.sub(r'(<li[\s\w-]+class="[^"]*current)([^"]*")', r'\1 active\2', tt)
    
    # Match each <li> that contains <ul>.
    pattern = r'(<li[\s\w-]+class=")([^>]*>[^<]*<a[^>]*>[^<]*</a>[^<]*<ul[\s\w]+class=")'
    
    # Inject the classes.
    replace = r'{}\1has-dropdown \2dropdown '.format(divider)
    
    # Do the replace and return.
    return re.sub(pattern, replace, tt)
def tt2nav ( toctree , klass = None , appendix = None , divider = False ) : tt = toctree divider = '<li class="divider"></li>' if divider else '' if appendix : tt = re . sub ( r'(</ul>$)' , r'{}\1' . format ( appendix ) , tt ) tt = re . sub ( r'<ul>' , r'<ul class="">' , tt ) if klass : tt = re . sub ( r'(^<ul[\s\w-]+class=")' , r'\1{} ' . format ( klass ) , tt ) pattern = r'(<li[\s\w-]+class=")([^>]*>[^<]*<a[^>]*>[^<]*</a>[^<]*<ul[\s\w]+class=")' replace = r'{}\1has-dropdown \2dropdown ' . format ( divider ) return re . sub ( pattern , replace , tt )
Injects ``has-dropdown`` and ``dropdown`` classes to HTML
    generated by the :func:`toctree` function.
    
    :param str toctree:
        HTML generated by the :func:`toctree` function.