Index: /trac/trunk/wiki-macros/TracNav.py
===================================================================
--- /trac/trunk/wiki-macros/TracNav.py	(revision 3052)
+++ /trac/trunk/wiki-macros/TracNav.py	(revision 3053)
@@ -1,3 +1,3 @@
-# -*- coding: iso8859-1 -*-
+# -*- coding: utf-8 -*-
 """
 = TracNav: The navigation bar for Trac =
@@ -89,6 +89,5 @@
 
 
-def parseToc(tocText):
-    stack = []
+def getTocEntry(tocText):
     nextPos = 0
     while 1:
@@ -96,5 +95,5 @@
         if not match:
             # env.log.debug("No more matches")
-            break
+            return
 
         indent = len(match.group('indent'))
@@ -110,4 +109,12 @@
         # else:
         #     env.log.debug(label + ": " + link)
+    
+        yield indent, link, label
+        nextPos = match.end()
+
+
+def parseToc(tocText):
+    stack = []
+    for indent, link, label in getTocEntry(tocText):
 
 	if len(stack) == 0:
@@ -130,6 +137,4 @@
             list.append((link, label, None))
                 
-        nextPos = match.end()
-
     while len(stack) > 1:
         (_, list) = stack.pop()
