--- TableOfContents.py.dist	2010-06-26 23:46:42.000000000 +0200
+++ TableOfContents.py	2010-09-01 18:57:24.000000000 +0200
@@ -167,7 +167,7 @@
     _ = macro.request.getText
 
     result = [
-        macro.formatter.div(1, css_class="table-of-contents"),
+        macro.formatter.div(1, css_class="table-of-contents", id="toc"),
         macro.formatter.paragraph(1, css_class="table-of-contents-heading"),
         macro.formatter.text(_('Contents')),
         macro.formatter.paragraph(0),
@@ -181,21 +181,48 @@
         if txt is None:
             incl_id = id
             continue
-        if lvl < mindepth or lvl > maxdepth or id is None:
+        if lvl > maxdepth or id is None:
             continue
         if lvl < lastlvl:
             lastlvl = lvl
 
     # headings are 1-based, lastlvl needs to be one less so that one is closed
+    # variables needed to provide with nice, leveled prefixes
+    # (part of the hierarhical TOC prefix code) 
+    levelnumbers = None
+    levelnumbers = {}
+    counter = 1
+    lowest_lvl = None
     lastlvl -= 1
 
     for lvl, id, txt in macro.request._tocfm_collected_headings:
         if txt is None:
             incl_id = id
             continue
-        if lvl < mindepth or lvl > maxdepth or id is None:
+        if lvl > maxdepth or id is None:
             continue
 
+
+        # determine the lowest level available 
+        # (part of the hierarhical TOC prefix)
+        if lowest_lvl is None or lowest_lvl > lvl:
+                lowest_lvl = lvl
+
+        # determine number prefix for the TOC line 
+        # (part of the hierarhical TOC prefix) 
+        if lvl > lastlvl:
+                levelnumbers[lastlvl] = counter
+                counter = 0
+        elif lvl < lastlvl:
+                counter = levelnumbers[lvl]
+        counter = counter + 1
+        levelnumbers[lvl] = counter
+   
+        line_number = ""
+        for i in range(lowest_lvl, lvl):
+                line_number = line_number + str(levelnumbers[i]) + "."
+        line_number = line_number + str(counter) + "."
+
         # will be reset by pop_unique_ids below
         macro.request.uid_generator.include_id = incl_id
 
@@ -203,12 +230,12 @@
         while lastlvl > lvl:
             result.extend([
                 macro.formatter.listitem(0),
-                macro.formatter.number_list(0),
+                macro.formatter.bullet_list(0),
             ])
             lastlvl -= 1
         while lastlvl < lvl:
             result.extend([
-                macro.formatter.number_list(1),
+                macro.formatter.bullet_list(1, type="none"),
                 macro.formatter.listitem(1),
             ])
             lastlvl += 1
@@ -220,13 +247,13 @@
         result.extend([
             '\n',
             macro.formatter.anchorlink(1, id),
-            macro.formatter.text(txt),
+            macro.formatter.text(line_number + " " + txt),
             macro.formatter.anchorlink(0),
         ])
 
     while lastlvl > 0:
         result.append(macro.formatter.listitem(0))
-        result.append(macro.formatter.number_list(0))
+        result.append(macro.formatter.bullet_list(0))
         lastlvl -= 1
 
     macro.request.uid_generator.pop()
