Changeset 3266


Ignore:
Timestamp:
11/05/08 12:43:12 (5 years ago)
Author:
moschny
Message:

Make the list of "allowed" (i.e. expanded) macros in the toc configurable.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trac/plugins/tracnav-0.11/tracnav/tracnav.py

    r3262 r3266  
    7070TRACNAVHOME = "http://svn.ipd.uka.de/trac/javaparty/wiki/TracNav" 
    7171LISTRULE = re.compile(r"^(?P<indent>[ \t\v]+)\* +(?P<rest>.*)$", re.M) 
    72 ALLOWED_MACROS = ["image"] 
    7372 
    7473 
     
    7877    last wiki link. 
    7978    """ 
    80     def __init__(self, env, ctx): 
     79    def __init__(self, env, ctx, allowed_macros=[]): 
    8180        OneLinerFormatter.__init__(self, env, ctx) 
    8281        self.lastlink = None 
     82        self.allowed_macros = allowed_macros 
    8383 
    8484    def format_toc(self, wikitext): 
     
    9595 
    9696    def _macro_formatter(self, match, fullmatch): 
    97         name = fullmatch.group('macroname').lower() 
    98         if name in ALLOWED_MACROS: 
     97        name = fullmatch.group('macroname') 
     98        if name in self.allowed_macros: 
    9999            # leapfrog the OneLinerFormatter 
    100100            return Formatter._macro_formatter(self, match, fullmatch) 
     
    125125        self.collapse = True 
    126126        self.reorder = True 
     127        self.allowed_macros = 'Image' 
    127128        if args: 
    128             for arg in map(lambda a: a.strip(), args.split('|')): 
     129            for arg, _, values in map(lambda s: s.partition('='), args.split('|')): 
     130                arg = arg.strip() 
    129131                if arg == 'nocollapse': 
    130132                    self.collapse = False 
     
    133135                elif arg == 'noreorder': 
    134136                    self.reorder = False 
     137                elif arg == 'allowed_macros': 
     138                    self.allowed_macros = map(lambda s: s.strip(), values.split(',')) 
    135139                else: 
    136140                    self.names.append(arg) 
     
    151155        Parse and format the entries in toc_text. 
    152156        """ 
    153         formatter = TocFormatter(self.env, self.ctx) 
     157        formatter = TocFormatter(self.env, self.ctx, self.allowed_macros) 
    154158        for match in LISTRULE.finditer(toc_text): 
    155159            indent = len(match.group('indent')) 
Note: See TracChangeset for help on using the changeset viewer.