summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2011-09-19 09:12:40 +0200
committerGeorg Brandl <georg@python.org>2011-09-19 09:12:40 +0200
commit494f301732c5f14455f7ed2261a9a3b89b7b8deb (patch)
tree1eda53f1b8eb28ce710c98eb0643a7df630bb8a2
parent0a9c4d641f1c1f9f6e9ec0ec1fc10f22c4e57e99 (diff)
parent9038036b43465f0d9a751073580f9f39e23b9a4b (diff)
downloadsphinx-494f301732c5f14455f7ed2261a9a3b89b7b8deb.tar.gz
Merged in benallard/sphinx (pull request #18)
-rw-r--r--sphinx/ext/graphviz.py38
-rw-r--r--sphinx/writers/html.py10
2 files changed, 7 insertions, 41 deletions
diff --git a/sphinx/ext/graphviz.py b/sphinx/ext/graphviz.py
index 6b875081..36932c17 100644
--- a/sphinx/ext/graphviz.py
+++ b/sphinx/ext/graphviz.py
@@ -30,7 +30,6 @@ from sphinx.util.compat import Directive
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):
@@ -187,37 +186,6 @@ def render_dot(self, code, options, format, prefix='graphviz'):
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
@@ -225,7 +193,7 @@ def render_dot_html(self, node, code, options, prefix='graphviz',
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
@@ -242,8 +210,9 @@ def render_dot_html(self, node, code, options, prefix='graphviz',
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')
@@ -251,7 +220,6 @@ def render_dot_html(self, node, code, options, prefix='graphviz',
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' %
diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py
index 99d621c6..17c7d43d 100644
--- a/sphinx/writers/html.py
+++ b/sphinx/writers/html.py
@@ -336,22 +336,20 @@ class HTMLTranslator(BaseTranslator):
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'):