- Timestamp:
- 12/02/05 00:31:58 (7 years ago)
- File:
-
- 1 edited
-
trac/trunk/wiki-macros/TracNav.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trac/trunk/wiki-macros/TracNav.py
r3061 r3063 75 75 from trac.wiki.api import WikiSystem 76 76 from trac.wiki.model import WikiPage 77 from trac.wiki.formatter import OneLinerFormatter77 from trac.wiki.formatter import Formatter, OneLinerFormatter 78 78 from StringIO import StringIO 79 79 80 80 TRACNAVHOME = "http://svn.ipd.uka.de/trac/javaparty/wiki/TracNav" 81 81 LISTRULE = re.compile(r"^(?P<indent> +)\* +(?P<rest>.*)$", re.M) 82 83 def get_toc(hdf, env, curpage, name): 82 ALLOWED_MACROS = ["image"] 83 84 def get_toc(hdf, env, preview, name): 84 85 """ 85 86 Fetch the wiki page containing the toc, if available. 86 87 """ 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 '' 95 98 96 99 … … 115 118 return OneLinerFormatter._make_link( 116 119 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 '' 117 130 118 131 # FIXME: what about _make_relative_link() ? … … 181 194 Main routine of the wiki macro. 182 195 """ 196 #env.log.debug("hdf: %s", hdf) 183 197 preview = hdf.getValue('args.preview', "") 184 198 curpage = hdf.getValue('wiki.page_name', "") 185 199 name = args or 'TOC' 186 200 187 toc = parse_toc(get_toc(hdf, env, curpage, name), env)201 toc = parse_toc(get_toc(hdf, env, preview, name), env) 188 202 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) 196 204 197 205 (found, filtered) = filter_toc(curpage, toc, 0)
Note: See TracChangeset
for help on using the changeset viewer.
