Commits

Georg Brandl committed aeb1d50 Merge

Merged in benallard/sphinx (pull request #18)

  • Participants
  • Parent commits f16b029, f0d405d

Comments (0)

Files changed (2)

File sphinx/ext/graphviz.py

 
 
 mapname_re = re.compile(r'<map id="(.*?)"')
-svg_dim_re = re.compile(r'<svg\swidth="(\d+)pt"\sheight="(\d+)pt"', re.M)
 
 
 class GraphvizError(SphinxError):
     return relfn, outfn
 
 
-def get_svg_tag(svgref, svgfile, imgcls=None):
-    # Webkit can't figure out svg dimensions when using object tag
-    # so we need to get it from the svg file
-    fp = open(svgfile, 'r')
-    try:
-        for line in fp:
-            match = svg_dim_re.match(line)
-            if match:
-                dimensions = match.groups()
-                break
-        else:
-            dimensions = None
-    finally:
-        fp.close()
-
-    # We need this hack to make WebKit show our object tag properly
-    def pt2px(x):
-        return int(ceil((96.0/72.0) * float(x)))
-
-    if dimensions:
-        style = ' width="%s" height="%s"' % tuple(map(pt2px, dimensions))
-    else:
-        style = ''
-
-    # The object tag works fine on Firefox and WebKit
-    # Besides it's a hack, this strategy does not mess with templates.
-    imgcss = imgcls and ' class="%s"' % imgcls or ''
-    return '<object type="image/svg+xml" data="%s"%s%s></object>\n' % \
-           (svgref, imgcss, style)
-
-
 def render_dot_html(self, node, code, options, prefix='graphviz',
                     imgcls=None, alt=None):
     format = self.builder.config.graphviz_output_format
         if format not in ('png', 'svg'):
             raise GraphvizError("graphviz_output_format must be one of 'png', "
                                 "'svg', but is %r" % format)
-        fname, outfn = render_dot(self, code, options, format, prefix)
+        fname, outfn = render_dot(self, code, options, format, prefix)g
     except GraphvizError, exc:
         self.builder.warn('dot code %r: ' % code + str(exc))
         raise nodes.SkipNode
     else:
         if alt is None:
             alt = node.get('alt', self.encode(code).strip())
+        imgcss = imgcls and 'class="%s"' % imgcls or ''
         if format == 'svg':
-            svgtag = get_svg_tag(fname, outfn, imgcls)
+            svgtag = '<img src="%s" alt="%s" %s/>\n' % (fname, alt, imgcss)
             self.body.append(svgtag)
         else:
             mapfile = open(outfn + '.map', 'rb')
                 imgmap = mapfile.readlines()
             finally:
                 mapfile.close()
-            imgcss = imgcls and 'class="%s"' % imgcls or ''
             if len(imgmap) == 2:
                 # nothing in image map (the lines are <map> and </map>)
                 self.body.append('<img src="%s" alt="%s" %s/>\n' %

File sphinx/writers/html.py

 
         if node['uri'].lower().endswith('svg') or \
            node['uri'].lower().endswith('svgz'):
-            atts = {'data': node['uri'], 'type': 'image/svg+xml'}
+            atts = {'src': node['uri']}
             if node.has_key('width'):
                 atts['width'] = node['width']
             if node.has_key('height'):
                 atts['height'] = node['height']
+            if node.has_key('alt'):
+                atts['alt'] = node['alt']
             if node.has_key('align'):
                 self.body.append('<div align="%s" class="align-%s">' %
                                  (node['align'], node['align']))
                 self.context.append('</div>\n')
             else:
                 self.context.append('')
-            embatts = atts.copy()
-            embatts['src'] = embatts.pop('data')
-            self.body.append(self.starttag(node, 'object', '', **atts))
-            self.body.append(self.emptytag(node, 'embed', '', **embatts))
-            self.body.append('</object>\n')
+            self.body.append(self.emptytag(node, 'img', '', **atts))
             return
 
         if node.has_key('scale'):