We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Provide length of TableOfContents
Currently, you can only iter over `TableOfContents`. I would like to know the length of it.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mkdocs/toc.py`
Content:
```
1 # coding: utf-8
2 
3 """
4 Deals with generating the per-page table of contents.
5 
6 For the sake of simplicity we use an existing markdown extension to generate
7 an HTML table of contents, and then parse that into the underlying data.
8 
9 The steps we take to generate a table of contents are:
10 
11 * Pre-process the markdown, injecting a [TOC] marker.
12 * Generate HTML from markdown.
13 * Post-process the HTML, spliting the content and the table of contents.
14 * Parse table of contents HTML into the underlying data structure.
15 """
16 
17 from __future__ import unicode_literals
18 
19 try:                                    # pragma: no cover
20     from html.parser import HTMLParser  # noqa
21 except ImportError:                     # pragma: no cover
22     from HTMLParser import HTMLParser   # noqa
23 
24 
25 class TableOfContents(object):
26     """
27     Represents the table of contents for a given page.
28     """
29     def __init__(self, html):
30         self.items = _parse_html_table_of_contents(html)
31 
32     def __iter__(self):
33         return iter(self.items)
34 
35     def __str__(self):
36         return ''.join([str(item) for item in self])
37 
38 
39 class AnchorLink(object):
40     """
41     A single entry in the table of contents.
42     """
43     def __init__(self, title, url):
44         self.title, self.url = title, url
45         self.children = []
46 
47     def __str__(self):
48         return self.indent_print()
49 
50     def indent_print(self, depth=0):
51         indent = '    ' * depth
52         ret = '%s%s - %s\n' % (indent, self.title, self.url)
53         for item in self.children:
54             ret += item.indent_print(depth + 1)
55         return ret
56 
57 
58 class TOCParser(HTMLParser):
59 
60     def __init__(self):
61         HTMLParser.__init__(self)
62         self.links = []
63 
64         self.in_anchor = False
65         self.attrs = None
66         self.title = ''
67 
68         # Prior to Python3.4 no convert_charrefs keyword existed.
69         # However, in Python3.5 the default was changed to True.
70         # We need the False behavior in all versions but can only
71         # set it if it exists.
72         if hasattr(self, 'convert_charrefs'):
73             self.convert_charrefs = False
74 
75     def handle_starttag(self, tag, attrs):
76 
77         if not self.in_anchor:
78             if tag == 'a':
79                 self.in_anchor = True
80                 self.attrs = dict(attrs)
81 
82     def handle_endtag(self, tag):
83         if tag == 'a':
84             self.in_anchor = False
85 
86     def handle_data(self, data):
87 
88         if self.in_anchor:
89             self.title += data
90 
91     def handle_charref(self, ref):
92         self.handle_entityref("#" + ref)
93 
94     def handle_entityref(self, ref):
95         self.handle_data("&%s;" % ref)
96 
97 
98 def _parse_html_table_of_contents(html):
99     """
100     Given a table of contents string that has been automatically generated by
101     the markdown library, parse it into a tree of AnchorLink instances.
102 
103     Returns a list of all the parent AnchorLink instances.
104     """
105     lines = html.splitlines()[2:-2]
106     parents = []
107     ret = []
108     for line in lines:
109         parser = TOCParser()
110         parser.feed(line)
111         if parser.title:
112             try:
113                 href = parser.attrs['href']
114             except KeyError:
115                 continue
116             title = parser.title
117             nav = AnchorLink(title, href)
118             # Add the item to its parent if required.  If it is a topmost
119             # item then instead append it to our return value.
120             if parents:
121                 parents[-1].children.append(nav)
122             else:
123                 ret.append(nav)
124             # If this item has children, store it as the current parent
125             if line.endswith('<ul>'):
126                 parents.append(nav)
127         elif line.startswith('</ul>'):
128             if parents:
129                 parents.pop()
130 
131     # For the table of contents, always mark the first element as active
132     if ret:
133         ret[0].active = True
134 
135     return ret
136
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/mkdocs/toc.py b/mkdocs/toc.py
--- a/mkdocs/toc.py
+++ b/mkdocs/toc.py
@@ -32,6 +32,9 @@
     def __iter__(self):
         return iter(self.items)
 
+    def __len__(self):
+        return len(self.items)
+
     def __str__(self):
         return ''.join([str(item) for item in self])

{"golden_diff": "diff --git a/mkdocs/toc.py b/mkdocs/toc.py\n--- a/mkdocs/toc.py\n+++ b/mkdocs/toc.py\n@@ -32,6 +32,9 @@\n     def __iter__(self):\n         return iter(self.items)\n \n+    def __len__(self):\n+        return len(self.items)\n+\n     def __str__(self):\n         return ''.join([str(item) for item in self])\n", "issue": "Provide length of TableOfContents\nCurrently, you can only iter over `TableOfContents`. I would like to know the length of it.\n", "before_files": [{"content": "# coding: utf-8\n\n\"\"\"\nDeals with generating the per-page table of contents.\n\nFor the sake of simplicity we use an existing markdown extension to generate\nan HTML table of contents, and then parse that into the underlying data.\n\nThe steps we take to generate a table of contents are:\n\n* Pre-process the markdown, injecting a [TOC] marker.\n* Generate HTML from markdown.\n* Post-process the HTML, spliting the content and the table of contents.\n* Parse table of contents HTML into the underlying data structure.\n\"\"\"\n\nfrom __future__ import unicode_literals\n\ntry:                                    # pragma: no cover\n    from html.parser import HTMLParser  # noqa\nexcept ImportError:                     # pragma: no cover\n    from HTMLParser import HTMLParser   # noqa\n\n\nclass TableOfContents(object):\n    \"\"\"\n    Represents the table of contents for a given page.\n    \"\"\"\n    def __init__(self, html):\n        self.items = _parse_html_table_of_contents(html)\n\n    def __iter__(self):\n        return iter(self.items)\n\n    def __str__(self):\n        return ''.join([str(item) for item in self])\n\n\nclass AnchorLink(object):\n    \"\"\"\n    A single entry in the table of contents.\n    \"\"\"\n    def __init__(self, title, url):\n        self.title, self.url = title, url\n        self.children = []\n\n    def __str__(self):\n        return self.indent_print()\n\n    def indent_print(self, depth=0):\n        indent = '    ' * depth\n        ret = '%s%s - %s\\n' % (indent, self.title, self.url)\n        for item in self.children:\n            ret += item.indent_print(depth + 1)\n        return ret\n\n\nclass TOCParser(HTMLParser):\n\n    def __init__(self):\n        HTMLParser.__init__(self)\n        self.links = []\n\n        self.in_anchor = False\n        self.attrs = None\n        self.title = ''\n\n        # Prior to Python3.4 no convert_charrefs keyword existed.\n        # However, in Python3.5 the default was changed to True.\n        # We need the False behavior in all versions but can only\n        # set it if it exists.\n        if hasattr(self, 'convert_charrefs'):\n            self.convert_charrefs = False\n\n    def handle_starttag(self, tag, attrs):\n\n        if not self.in_anchor:\n            if tag == 'a':\n                self.in_anchor = True\n                self.attrs = dict(attrs)\n\n    def handle_endtag(self, tag):\n        if tag == 'a':\n            self.in_anchor = False\n\n    def handle_data(self, data):\n\n        if self.in_anchor:\n            self.title += data\n\n    def handle_charref(self, ref):\n        self.handle_entityref(\"#\" + ref)\n\n    def handle_entityref(self, ref):\n        self.handle_data(\"&%s;\" % ref)\n\n\ndef _parse_html_table_of_contents(html):\n    \"\"\"\n    Given a table of contents string that has been automatically generated by\n    the markdown library, parse it into a tree of AnchorLink instances.\n\n    Returns a list of all the parent AnchorLink instances.\n    \"\"\"\n    lines = html.splitlines()[2:-2]\n    parents = []\n    ret = []\n    for line in lines:\n        parser = TOCParser()\n        parser.feed(line)\n        if parser.title:\n            try:\n                href = parser.attrs['href']\n            except KeyError:\n                continue\n            title = parser.title\n            nav = AnchorLink(title, href)\n            # Add the item to its parent if required.  If it is a topmost\n            # item then instead append it to our return value.\n            if parents:\n                parents[-1].children.append(nav)\n            else:\n                ret.append(nav)\n            # If this item has children, store it as the current parent\n            if line.endswith('<ul>'):\n                parents.append(nav)\n        elif line.startswith('</ul>'):\n            if parents:\n                parents.pop()\n\n    # For the table of contents, always mark the first element as active\n    if ret:\n        ret[0].active = True\n\n    return ret\n", "path": "mkdocs/toc.py"}], "after_files": [{"content": "# coding: utf-8\n\n\"\"\"\nDeals with generating the per-page table of contents.\n\nFor the sake of simplicity we use an existing markdown extension to generate\nan HTML table of contents, and then parse that into the underlying data.\n\nThe steps we take to generate a table of contents are:\n\n* Pre-process the markdown, injecting a [TOC] marker.\n* Generate HTML from markdown.\n* Post-process the HTML, spliting the content and the table of contents.\n* Parse table of contents HTML into the underlying data structure.\n\"\"\"\n\nfrom __future__ import unicode_literals\n\ntry:                                    # pragma: no cover\n    from html.parser import HTMLParser  # noqa\nexcept ImportError:                     # pragma: no cover\n    from HTMLParser import HTMLParser   # noqa\n\n\nclass TableOfContents(object):\n    \"\"\"\n    Represents the table of contents for a given page.\n    \"\"\"\n    def __init__(self, html):\n        self.items = _parse_html_table_of_contents(html)\n\n    def __iter__(self):\n        return iter(self.items)\n\n    def __len__(self):\n        return len(self.items)\n\n    def __str__(self):\n        return ''.join([str(item) for item in self])\n\n\nclass AnchorLink(object):\n    \"\"\"\n    A single entry in the table of contents.\n    \"\"\"\n    def __init__(self, title, url):\n        self.title, self.url = title, url\n        self.children = []\n\n    def __str__(self):\n        return self.indent_print()\n\n    def indent_print(self, depth=0):\n        indent = '    ' * depth\n        ret = '%s%s - %s\\n' % (indent, self.title, self.url)\n        for item in self.children:\n            ret += item.indent_print(depth + 1)\n        return ret\n\n\nclass TOCParser(HTMLParser):\n\n    def __init__(self):\n        HTMLParser.__init__(self)\n        self.links = []\n\n        self.in_anchor = False\n        self.attrs = None\n        self.title = ''\n\n        # Prior to Python3.4 no convert_charrefs keyword existed.\n        # However, in Python3.5 the default was changed to True.\n        # We need the False behavior in all versions but can only\n        # set it if it exists.\n        if hasattr(self, 'convert_charrefs'):\n            self.convert_charrefs = False\n\n    def handle_starttag(self, tag, attrs):\n\n        if not self.in_anchor:\n            if tag == 'a':\n                self.in_anchor = True\n                self.attrs = dict(attrs)\n\n    def handle_endtag(self, tag):\n        if tag == 'a':\n            self.in_anchor = False\n\n    def handle_data(self, data):\n\n        if self.in_anchor:\n            self.title += data\n\n    def handle_charref(self, ref):\n        self.handle_entityref(\"#\" + ref)\n\n    def handle_entityref(self, ref):\n        self.handle_data(\"&%s;\" % ref)\n\n\ndef _parse_html_table_of_contents(html):\n    \"\"\"\n    Given a table of contents string that has been automatically generated by\n    the markdown library, parse it into a tree of AnchorLink instances.\n\n    Returns a list of all the parent AnchorLink instances.\n    \"\"\"\n    lines = html.splitlines()[2:-2]\n    parents = []\n    ret = []\n    for line in lines:\n        parser = TOCParser()\n        parser.feed(line)\n        if parser.title:\n            try:\n                href = parser.attrs['href']\n            except KeyError:\n                continue\n            title = parser.title\n            nav = AnchorLink(title, href)\n            # Add the item to its parent if required.  If it is a topmost\n            # item then instead append it to our return value.\n            if parents:\n                parents[-1].children.append(nav)\n            else:\n                ret.append(nav)\n            # If this item has children, store it as the current parent\n            if line.endswith('<ul>'):\n                parents.append(nav)\n        elif line.startswith('</ul>'):\n            if parents:\n                parents.pop()\n\n    # For the table of contents, always mark the first element as active\n    if ret:\n        ret[0].active = True\n\n    return ret\n", "path": "mkdocs/toc.py"}]}