Use abridged headings for anchors
authorBernardo Innocenti <bernie@codewiz.org>
Tue, 12 Feb 2008 07:54:07 +0000 (17:54 +1000)
committerBernardo Innocenti <bernie@codewiz.org>
Tue, 12 Feb 2008 07:54:07 +0000 (17:54 +1000)
geekigeeki.py

index a6158a3122b41b184930bf0255664a428851858d..0a441bf5658c4de1ba72199673651ad1d7af0590 100755 (executable)
@@ -339,7 +339,7 @@ class PageFormatter:
         self.in_pre = self.in_table = False
         self.in_header = True
         self.list_indents = []
-        self.tr_cnt = self.h_cnt = 0
+        self.tr_cnt = 0
         self.styles = {
             #wiki   html   enabled?
             "//":  ["em",  False],
@@ -364,9 +364,8 @@ class PageFormatter:
             self.h_level = 0
         else:
             self.h_level = len(word) - 1
-            self.h_cnt += 1
-            #abridged = re.sub('[^a-z_]', '', word.lower().replace(' ', '_'))
-            result = '<h%d id="%d"><a class="heading" href="#%d">¶</a> ' % (self.h_level, self.h_cnt, self.h_cnt)
+            abridged = re.sub('[^A-Za-z0-9_]', '', self.line).lower()
+            result = '<h%d id="%s"><a class="heading" href="#%s">¶</a> ' % (self.h_level, abridged, abridged)
         return result
 
     def _br_repl(self, word):
@@ -524,26 +523,26 @@ class PageFormatter:
         indent_re = re.compile(r"^\s*")
         tr_re = re.compile(r"^\s*\|\|")
         eol_re = re.compile(r"\r?\n")
-        for line in eol_re.split(self.raw.expandtabs()):
+        for self.line in eol_re.split(self.raw.expandtabs()):
             # Skip ACLs
             if self.in_header:
-                if line.startswith('#'):
+                if self.line.startswith('#'):
                     continue
                 self.in_header = False
 
             if self.in_pre:
-                print re.sub(pre_re, self.replace, line)
+                print re.sub(pre_re, self.replace, self.line)
             else:
-                if self.in_table and not tr_re.match(line):
+                if self.in_table and not tr_re.match(self.line):
                     self.in_table = False
                     print '</tbody></table><p>'
 
-                if blank_re.match(line):
+                if blank_re.match(self.line):
                     print '</p><p>'
                 else:
-                    indent = indent_re.match(line)
+                    indent = indent_re.match(self.line)
                     print self._indent_to(len(indent.group(0)))
-                    print re.sub(scan_re, self.replace, line)
+                    print re.sub(scan_re, self.replace, self.line)
 
         if self.in_pre: print '</pre>'
         if self.in_table: print '</tbody></table><p>'