--- TableOfContents.py.old	2009-03-14 14:22:44.000000000 +0100
+++ TableOfContents.py	2009-03-27 03:19:59.000000000 +0100
@@ -162,7 +162,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),
@@ -184,6 +184,13 @@
     # headings are 1-based, lastlvl needs to be one less so that one is closed
     lastlvl -= 1
 
+    # variables needed to provide with nice, leveled prefixes
+    # (part of the hierarhical TOC prefix code) 
+    levelnumbers = None
+    levelnumbers = {}
+    counter = 1
+    lowest_lvl = None
+
     for lvl, id, txt in macro.request._tocfm_collected_headings:
         if txt is None:
             incl_id = id
@@ -191,6 +198,27 @@
         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.include_id = incl_id
 
@@ -198,12 +226,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
@@ -215,13 +243,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()
