Edgewall Software

Ticket #992: anchors.diff

File anchors.diff, 846 bytes (added by trac-form@…, 7 years ago)

Patch to add anchors to headings in the Wiki

  • WikiFormatter.py

    old new  
    269269 
    270270    _compiled_rules = re.compile('(?:' + string.join(_rules, '|') + ')') 
    271271    _processor_re = re.compile('#\!([a-zA-Z0-9/+-]+)') 
     272    _anchor_re = re.compile('[^A-Za-z0-9]+') 
    272273    mime_type = "" 
    273274     
    274275 
     
    362363        self.close_paragraph() 
    363364        self.close_indentation() 
    364365        self.close_list() 
    365         self.out.write('<h%d>%s</h%d>' % (depth, match[depth + 1:len(match) - depth - 1], depth)) 
     366        heading = match[depth + 1:len(match) - depth - 1] 
     367        anchor = self._anchor_re.sub("", heading) 
     368        self.out.write('<a name="%s"><h%d>%s</h%d></a>' % (anchor, depth, heading, depth)) 
    366369        return '' 
    367370 
    368371    def _svnimg_formatter(self, match, fullmatch):