--- trac/WikiFormatter.py	2004-11-16 09:58:49.000000000 +1100
+++ trac-modified/WikiFormatter.py	2004-11-25 11:23:26.000000000 +1100
@@ -269,6 +269,7 @@
 
     _compiled_rules = re.compile('(?:' + string.join(_rules, '|') + ')')
     _processor_re = re.compile('#\!([a-zA-Z0-9/+-]+)')
+    _anchor_re = re.compile('[^A-Za-z0-9]+')
     mime_type = ""
     
 
@@ -362,7 +363,9 @@
         self.close_paragraph()
         self.close_indentation()
         self.close_list()
-        self.out.write('<h%d>%s</h%d>' % (depth, match[depth + 1:len(match) - depth - 1], depth))
+        heading = match[depth + 1:len(match) - depth - 1]
+        anchor = self._anchor_re.sub("", heading)
+        self.out.write('<a name="%s"><h%d>%s</h%d></a>' % (anchor, depth, heading, depth))
         return ''
 
     def _svnimg_formatter(self, match, fullmatch):

