Changeset 3063 for trac


Ignore:
Timestamp:
12/02/05 00:31:58 (7 years ago)
Author:
moschny
Message:
  • Allow usage of the Image macro in toc entries. Note: References to local attachments (a single argument without colon) cannot be used currently (the Image macro needs the a reference to the request in that case, which we don't have.)
  • Bugfix: Show the submitted version of the toc, when previewing the toc page itself (broken since transition to trac 0.9).
  • Don't display the big fat error message anymore.
File:
1 edited

Legend:

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

    r3061 r3063  
    7575from trac.wiki.api import WikiSystem 
    7676from trac.wiki.model import WikiPage 
    77 from trac.wiki.formatter import OneLinerFormatter 
     77from trac.wiki.formatter import Formatter, OneLinerFormatter 
    7878from StringIO import StringIO 
    7979 
    8080TRACNAVHOME = "http://svn.ipd.uka.de/trac/javaparty/wiki/TracNav" 
    8181LISTRULE = re.compile(r"^(?P<indent> +)\* +(?P<rest>.*)$", re.M) 
    82  
    83 def get_toc(hdf, env, curpage, name): 
     82ALLOWED_MACROS = ["image"] 
     83 
     84def get_toc(hdf, env, preview, name): 
    8485    """ 
    8586    Fetch the wiki page containing the toc, if available. 
    8687    """ 
    87     toc_text = " * Table of contents" 
    88  
    89     preview = hdf.getValue('args.preview', "") 
    90     if preview and (name == curpage): 
    91         toc_text = hdf.getValue('wiki.page_source', toc_text); 
    92     elif WikiSystem(env).has_page(name): 
    93         toc_text = WikiPage(env, name).text 
    94     return toc_text 
     88    if preview: 
     89        cur_path = hdf.getValue('HTTP.PathInfo', '') 
     90        toc_path = "/wiki/" + name 
     91        if cur_path == toc_path: 
     92            return hdf.getValue('args.text', '') 
     93 
     94    if WikiSystem(env).has_page(name): 
     95        return WikiPage(env, name).text 
     96    else: 
     97        return '' 
    9598 
    9699 
     
    115118        return OneLinerFormatter._make_link( 
    116119            self, namespace, target, match, label) 
     120 
     121    def _macro_formatter(self, match, fullmatch): 
     122        name = fullmatch.group('macroname').lower() 
     123        if name == 'br': 
     124            return ' ' 
     125        elif name in ALLOWED_MACROS: 
     126            # leapfrog the OneLinerFormatter 
     127            return Formatter._macro_formatter(self, match, fullmatch) 
     128        else: 
     129            return '' 
    117130 
    118131    # FIXME: what about _make_relative_link() ? 
     
    181194    Main routine of the wiki macro. 
    182195    """ 
     196    #env.log.debug("hdf: %s", hdf) 
    183197    preview = hdf.getValue('args.preview', "") 
    184198    curpage = hdf.getValue('wiki.page_name', "") 
    185199    name = args or 'TOC' 
    186200 
    187     toc = parse_toc(get_toc(hdf, env, curpage, name), env) 
     201    toc = parse_toc(get_toc(hdf, env, preview, name), env) 
    188202    if not toc: 
    189         msg = '<div class="system-message">' \ 
    190               "<strong>Error: Table of contents does not exist or is empty." 
    191         if (not preview) and (hdf.getValue('trac.acl.WIKI_MODIFY', '')): 
    192             msg += ' Click here to <a href="%s?edit=yes">edit</a>.' % \ 
    193                    env.href.wiki(name) 
    194         msg += '</strong></div>\n' 
    195         return msg 
     203        toc = parse_toc(' * TOC "%s" is empty!' % name, env) 
    196204 
    197205    (found, filtered) = filter_toc(curpage, toc, 0) 
Note: See TracChangeset for help on using the changeset viewer.