Changeset 735
- Timestamp:
- 05/02/06 01:11:46 (3 years ago)
- Files:
-
- tocmacro/0.9/tractoc/macro.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tocmacro/0.9/tractoc/macro.py
r655 r735 17 17 class MyOutlineFormatter(OutlineFormatter): 18 18 19 def format(self, page, *args, **kwords):19 def format(self, active_page, page, text, out, min_depth, max_depth): 20 20 self.__page = page 21 super(MyOutlineFormatter,self).format(*args, **kwords) 21 # XXX Code copied straight out of OutlineFormatter 22 self.outline = [] 23 class NullOut(object): 24 def write(self, data): pass 25 Formatter.format(self, text, NullOut()) 26 27 if min_depth > max_depth: 28 min_depth, max_depth = max_depth, min_depth 29 max_depth = min(6, max_depth) 30 min_depth = max(1, min_depth) 31 32 curr_depth = min_depth - 1 33 for depth, link in self.outline: 34 active = '' 35 if '/%s' % active_page in link: 36 active = ' class="active"' 37 if depth < min_depth or depth > max_depth: 38 continue 39 if depth < curr_depth: 40 out.write('</li></ol><li%s>' % active * (curr_depth - depth)) 41 elif depth > curr_depth: 42 out.write('<ol><li%s>' % active * (depth - curr_depth)) 43 else: 44 out.write("</li><li%s>\n" % active) 45 curr_depth = depth 46 out.write(link) 47 out.write('</li></ol>' * curr_depth) 22 48 23 49 def _heading_formatter(self, match, fullmatch): … … 136 162 for pagename in pagenames: 137 163 if params['title_index']: 164 li_class = pagename.startswith(current_page) and ' class="active"' or '' 138 165 prefix = (pagename.split('/'))[0] 139 166 prefix = prefix.replace('\'', '\'\'') … … 145 172 page_text, _ = get_page_text(page) 146 173 147 formatter.format( page, page_text, NullOut(), 1, 1)174 formatter.format(current_page, page, page_text, NullOut(), 1, 1) 148 175 header = '' 149 176 if formatter.outline: … … 151 178 title = re.sub('<[^>]*>','', title) # Strip all tags 152 179 header = ': ' + wiki_to_oneliner(title, self.env) 153 out.write('<li > <a href="%s">%s</a> %s</li>\n' % (self.env.href.wiki(page), page, header))180 out.write('<li%s> <a href="%s">%s</a> %s</li>\n' % (li_class, self.env.href.wiki(page), page, header)) 154 181 out.write('</ol>') 155 182 else : … … 159 186 page_text, page_exists = get_page_text(page) 160 187 if page_exists: 161 formatter.format( page, page_text, out, params['min_depth'], params['max_depth'])188 formatter.format(current_page, page, page_text, out, params['min_depth'], params['max_depth']) 162 189 else: 163 190 out.write('<div class="system-message"><strong>Error: Page %s does not exist</strong></div>' % pagename)
