except StopIteration:
pass
-def _tree2html(tree, level=0):
+def _tree2html(tree, path='', level=0):
subparts = []
indent = " " * (level + 1)
for title, subtree in tree:
+ subpath = "%s/%s" % (path, title)
+ if subpath.startswith('/'):
+ subpath = subpath[1:]
+ href = '<a href="%s/">%s</a>' % (subpath, title)
if subtree:
- subparts.append(indent + "<li>%s" % title)
- subparts.append(_tree2html(subtree, level+2))
+ subparts.append(indent + "<li>%s" % href)
+ subparts.append(_tree2html(subtree, subpath, level+2))
subparts.append(indent + "</li>")
else:
- subparts.append(indent + "<li>%s</li>" % title)
+ subparts.append(indent + "<li>%s</li>" % href)
s = "\n".join(subparts)
parts = []