Changeset 4401
- Timestamp:
- 10/06/08 12:19:20 (2 months ago)
- Files:
-
- graphvizplugin/0.11/graphviz/graphviz.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
graphvizplugin/0.11/graphviz/graphviz.py
r4400 r4401 25 25 import sys 26 26 27 from genshi.builder import tag27 from genshi.builder import Element, tag 28 28 from genshi.core import Markup 29 29 … … 36 36 from trac.web.api import IRequestHandler 37 37 from trac.wiki.api import IWikiMacroProvider 38 from trac.wiki.formatter import wiki_to_oneliner38 from trac.wiki.formatter import extract_link 39 39 40 40 … … 360 360 # Create the map if not in cache 361 361 if not os.path.exists(map_path): 362 errmsg = self._launch(encoded_content, proc_cmd, '-Tcmap ',362 errmsg = self._launch(encoded_content, proc_cmd, '-Tcmapx', 363 363 '-o%s' % map_path, 364 364 *self.processor_options) … … 367 367 368 368 # Generate HTML output 369 img_url = formatter.href.graphviz(img_name) 369 370 # for SVG(z) 370 371 if out_format in Graphviz.Vector_Formats: 371 372 try: # try to get SVG dimensions 372 373 f = open(img_path, 'r') 373 svg = f.readlines( )374 svg = f.readlines(1024) # don't read all 374 375 f.close() 375 376 svg = "".join(svg).replace('\n', '') … … 389 390 # insert SVG, IE compatibility 390 391 return tag.object( 391 tag.embed(src= "%s/graphviz/%s", type="image/svg+xml",392 tag.embed(src=img_url, type="image/svg+xml", 392 393 width=width, height=height), 393 data= "%s/graphviz/%s" % (req.base_url, img_name),394 type="image/svg+xml",width=width, height=height)394 data=img_url, type="image/svg+xml", 395 width=width, height=height) 395 396 396 397 # for binary formats, add map … … 400 401 f.close() 401 402 map = "".join(map).replace('\n', '') 402 return tag(tag.map(Markup(map), id=sha_key, name=sha_key), 403 tag.img(id=sha_key, 404 src="%s/graphviz/%s" % (req.base_url, img_name), 405 usemap="#"+sha_key, alt="GraphViz image")) 403 return tag(tag.map(Markup(map), id='G'+sha_key, name='G'+sha_key), 404 tag.img(src=img_url, usemap="#G"+sha_key, 405 alt=_("GraphViz image"))) 406 406 else: 407 return tag.img(src= "%s/graphviz/%s" % (req.base_url, img_name))407 return tag.img(src=img_url, alt=_("GraphViz image")) 408 408 409 409 … … 412 412 def _expand_wiki_links(self, formatter, out_format, content): 413 413 """Expand TracLinks that follow all URL= patterns.""" 414 def _expand(match): 415 wiki_url = match.groups()[0] # TracLink ([1], source:file/, ...) 416 html_url = wiki_to_oneliner(wiki_url, self.env, req=formatter.req) 417 # <a href="http://someurl">...</a> 418 419 href = re.search('href="(.*?)"', html_url) # http://someurl 420 url = href and href.groups()[0] or html_url 414 def expand(match): 415 wiki_text = match.groups()[0] # TracLink ([1], source:file/, ...) 416 link = extract_link(self.env, formatter.context, wiki_text) 417 if isinstance(link, Element): 418 href = link.attrib.get('href') 419 name = link.children 420 description = link.attrib.get('title', '') 421 else: 422 href = wiki_text 423 description = None 421 424 if out_format == 'svg': 422 425 format = 'URL="javascript:window.parent.location.href=\'%s\'"' 423 426 else: 424 427 format = 'URL="%s"' 425 return format % url 426 return re.sub(r'URL="(.*?)"', _expand, content) 428 url = format % href 429 if description: 430 url += '\ntooltip="%s"' % description \ 431 .replace('"', '').replace('\n', '') 432 return url 433 return re.sub(r'URL="(.*?)"', expand, content) 427 434 428 435 def _load_config(self):
