changeset 41:4480365c7aef

Add section numbers, and cosmetically indent <ul></ul> in "view source".
author Rob Landley <rob@landley.net>
date Thu, 13 Sep 2007 16:06:38 -0500
parents 17389c66eb02
children 86138d660041
files make/indexsections.py
diffstat 1 files changed, 11 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/make/indexsections.py	Tue Sep 11 17:12:19 2007 -0500
+++ b/make/indexsections.py	Thu Sep 13 16:06:38 2007 -0500
@@ -4,6 +4,7 @@
 
 args = sys.argv[1:]
 spans = []
+secnum = [0]
 depth = 0
 
 if args[0] == '-i': args = args[1:]
@@ -16,10 +17,10 @@
 def adjust_depth(newdepth):
   global depth
   while newdepth > depth:
-    sys.stdout.write("<ul>\n")
+    sys.stdout.write("%s<ul>\n" % ("  "*depth))
     depth += 1
   while newdepth < depth:
-    sys.stdout.write("</ul>\n")
+    sys.stdout.write("%s</ul>\n" % ("  "*depth))
     depth -= 1
 
 line = data[0].count("\n")
@@ -34,13 +35,18 @@
     tag = tag[1][3:]
     if tag[0]=='"' and tag[-1]=='"': tag=tag[1:-1]
     spans.append("_".join(tag.split()))
+    secnum[-1] += 1
+    secstr = ".".join(map(lambda a: str(a), secnum))
     if sys.argv[1] == "-i":
       adjust_depth(len(spans))
-      sys.stdout.write('%s<li><a href="#%s">%s</a></li>\n' % ("  "*len(spans),spans[-1],tag))
+      sys.stdout.write('%s<li><a href="#%s">%s %s</a></li>\n' % ("  "*len(spans),spans[-1],secstr,tag))
     else:
-      sys.stdout.write('<h2><a name="%s">%s</a></h2>\n' % (spans[-1],tag))
+      sys.stdout.write('<h2><a name="%s">%s %s</a></h2>\n' % (spans[-1],secstr,tag))
       sys.stdout.write('<%s>%s' % (i[0], i[1]))
-  elif tag[0] == "/span": spans.pop()
+    secnum.append(0)
+  elif tag[0] == "/span":
+    spans.pop()
+    secnum.pop()
   else:
     if sys.argv[1] != '-i': sys.stdout.write('<%s>%s' % (i[0], i[1]));
   line += i[1].count("\n")