Changeset 2723


Ignore:
Timestamp:
02/21/05 08:59:18 (8 years ago)
Author:
hauma
Message:
  • Bugfix: Use newest version of TOC page for creating the navigation bar. This requires to sort the results from the query in reverse order.
  • Allow non-linked headlines in the TOC page. Submenus with non-linked headlines are always displayed expanded, but not displayed at the top.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trac/trunk/wiki-macros/JPNav.py

    r2705 r2723  
    1414 
    1515import re 
     16import sys 
    1617 
    17 listRule = re.compile(r"""(?P<indent>^\s+)\*\s+\[wiki:(?P<link>(&#34;(.*?)&#34;|'(.*?)')|([^ ]*[^'~_\., \)]))\s+(?P<label>.*)\]""", re.M) 
     18listRule = re.compile(r"""^(?P<indent> +)\* +(?:(?P<wikilink>\[wiki:(?P<link>(&#34;([^&#34;]*)&#34;|'([^']*)')|([^ \]]+)) +(?P<label>[^\]]*)\])|(?P<text>.*))""", re.M) 
    1819 
    19 def getToc(db, name): 
     20def getToc(env, db, name): 
    2021    cursor = db.cursor() 
    21     cursor.execute('SELECT text FROM wiki WHERE name=%s', name) 
     22    cursor.execute('SELECT text FROM wiki WHERE name=%s ORDER BY version DESC LIMIT 1', name) 
    2223    row = cursor.fetchone() 
    2324    if not row: 
     
    2627    tocText = row[0] 
    2728 
     29    # env.log.debug(tocText) 
     30 
    2831    stack = [(1, [])] 
    2932    nextPos = 0 
     
    3134        match = listRule.search(tocText, nextPos) 
    3235        if not match: 
     36            env.log.debug("No more matches") 
    3337            break 
    3438 
    3539        indent = len(match.group('indent')) 
    36         link = match.group('link') 
    37         label = match.group('label') 
     40        if match.group('wikilink'): 
     41            link = match.group('link') 
     42            label = match.group('label') 
     43        else: 
     44            link = None 
     45            label = match.group('text') 
     46 
     47        if link == None: 
     48            env.log.debug(label + " ---") 
     49        else: 
     50            env.log.debug(label + ": " + link) 
    3851 
    3952        (lastIndent, list) = stack[len(stack) - 1] 
     
    7285 
    7386    db = env.get_db_cnx() 
    74     toc = getToc(db, name) 
     87    toc = getToc(env, db, name) 
    7588    if not toc: 
    7689        msg = '' 
     
    102115                cls = '' 
    103116            html += '<li%s>' % ( cls ) 
    104             html += '<a href="%s">%s</a>' % (env.href.wiki(name), title) 
     117            if name == None: 
     118                html += title 
     119            else: 
     120                html += '<a href="%s">%s</a>' % (env.href.wiki(name), title) 
    105121            html += '</li>' 
    106122        else: 
    107123            (subfound, subhtml) = generate(env, curpage, sub, level + 1) 
    108             if subfound: 
     124            if subfound or (name == None): 
    109125                menu = '' 
    110126                menu += '<li>' 
     
    113129                menu += '</li>' 
    114130                found = 1 
    115                 if level == 0: 
     131                if level == 0 and name != None: 
    116132                    html = menu + html 
    117133                else: 
Note: See TracChangeset for help on using the changeset viewer.