Changeset 643

Show
Ignore:
Timestamp:
04/11/06 23:16:37 (3 years ago)
Author:
coderanger
Message:

TocMacro:

Fixing refs on other pages.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tocmacro/0.9/tractoc/macro.py

    r615 r643  
    1313class NullOut(object): 
    1414   def write(self, *args): pass 
     15 
     16 
     17class MyOutlineFormatter(OutlineFormatter): 
     18 
     19    def format(self, page, *args, **kwords): 
     20        self.__page = page 
     21        super(MyOutlineFormatter,self).format(*args, **kwords) 
     22 
     23    def _heading_formatter(self, match, fullmatch): 
     24        Formatter._heading_formatter(self, match, fullmatch) 
     25        depth = min(len(fullmatch.group('hdepth')), 5) 
     26        heading = match[depth + 1:len(match) - depth - 1] 
     27        anchor = self._anchors[-1] 
     28        text = wiki_to_oneliner(heading, self.env, self.db, self._absurls) 
     29        text = re.sub(r'</?a(?: .*?)?>', '', text) # Strip out link tags 
     30        self.outline.append((depth, '<a href="%s#%s">%s</a>' % (self.__page, anchor, text))) 
    1531 
    1632class TracTocMacro(Component): 
     
    5167    def render_macro(self, req, name, args): 
    5268        db = self.env.get_db_cnx() 
    53         formatter = OutlineFormatter(self.env) 
     69        formatter = MyOutlineFormatter(self.env) 
    5470         
    5571        # If this is a page preview, try to figure out where its from 
     
    122138                        page_text, _ = get_page_text(page) 
    123139     
    124                         formatter.format(page_text, NullOut(), 1, 1) 
    125                         self.log.debug(page + ' --> ' + repr(formatter.outline)) 
     140                        formatter.format(page, page_text, NullOut(), 1, 1) 
    126141                        header = '' 
    127142                        if formatter.outline: 
     
    137152                page_text, page_exists = get_page_text(page) 
    138153                if page_exists: 
    139                     formatter.format(page_text, out, params['min_depth'], params['max_depth']) 
     154                    formatter.format(page, page_text, out, params['min_depth'], params['max_depth']) 
    140155                else: 
    141156                    out.write('<div class="system-message"><strong>Error: Page %s does not exist</strong></div>' % pagename)