def _build_list_items(self, matches):
        """Returns the HTML list items for the next matches that have a larger (or equal) header
        compared to the first header's level.

        This method mutatively removes elements from the front of matches as it processes each
        element. This method assumes matches contains at least one match.

        PARAMETERS:
        matches -- list of tuples; each tuple corresponds to the groups matched by the header_regex.

        RETURNS:
        list of str; the table of contents as a list of lines.
        """
        assert len(matches) > 0, "Should be at least one match, by assumption"

        lines = []
        current_level = matches[0][0]
        while matches and current_level <= matches[0][0]:
            level, _, tag_id, title = matches[0]
            if current_level < level:
                lines.extend(self._build_list(matches, level))
                continue

            if tag_id:
                lines.append('<li><a href="#{0}">{1}</a></li>'.format(tag_id, title))
            else:
                lines.append('<li>{0}</li>'.format(title))
            matches.pop(0)
        return lines
def _build_list_items ( self , matches ) : assert len ( matches ) > 0 , "Should be at least one match, by assumption" lines = [ ] current_level = matches [ 0 ] [ 0 ] while matches and current_level <= matches [ 0 ] [ 0 ] : level , _ , tag_id , title = matches [ 0 ] if current_level < level : lines . extend ( self . _build_list ( matches , level ) ) continue if tag_id : lines . append ( '<li><a href="#{0}">{1}</a></li>' . format ( tag_id , title ) ) else : lines . append ( '<li>{0}</li>' . format ( title ) ) matches . pop ( 0 ) return lines
Returns the HTML list items for the next matches that have a larger (or equal) header
        compared to the first header's level.

        This method mutatively removes elements from the front of matches as it processes each
        element. This method assumes matches contains at least one match.

        PARAMETERS:
        matches -- list of tuples; each tuple corresponds to the groups matched by the header_regex.

        RETURNS:
        list of str; the table of contents as a list of lines.