Example #1
0
    def visit_image(self, node):
        olduri = node['uri']
        # rewrite the URI if the environment knows about it
        if olduri in self.builder.images:
            node['uri'] = posixpath.join(self.builder.imgpath,
                                         self.builder.images[olduri])

        uri = node['uri']
        if uri.lower().endswith('svg') or uri.lower().endswith('svgz'):
            atts = {'src': uri}
            if 'width' in node:
                atts['width'] = node['width']
            if 'height' in node:
                atts['height'] = node['height']
            atts['alt'] = node.get('alt', uri)
            if 'align' in node:
                self.body.append('<div align="%s" class="align-%s">' %
                                 (node['align'], node['align']))
                self.context.append('</div>\n')
            else:
                self.context.append('')
            self.body.append(self.emptytag(node, 'img', '', **atts))
            return

        if 'scale' in node:
            # Try to figure out image height and width.  Docutils does that too,
            # but it tries the final file name, which does not necessarily exist
            # yet at the time the HTML file is written.
            if not ('width' in node and 'height' in node):
                size = get_image_size(path.join(self.builder.srcdir, olduri))
                if size is None:
                    self.builder.env.warn_node('Could not obtain image size. '
                                               ':scale: option is ignored.', node)
                else:
                    if 'width' not in node:
                        node['width'] = str(size[0])
                    if 'height' not in node:
                        node['height'] = str(size[1])
        BaseTranslator.visit_image(self, node)
Example #2
0
    def visit_image(self, node):
        olduri = node["uri"]
        # rewrite the URI if the environment knows about it
        if olduri in self.builder.images:
            node["uri"] = posixpath.join(self.builder.imgpath, self.builder.images[olduri])

        uri = node["uri"]
        if uri.lower().endswith("svg") or uri.lower().endswith("svgz"):
            atts = {"src": uri}
            if "width" in node:
                atts["width"] = node["width"]
            if "height" in node:
                atts["height"] = node["height"]
            atts["alt"] = node.get("alt", uri)
            if "align" in node:
                self.body.append('<div align="%s" class="align-%s">' % (node["align"], node["align"]))
                self.context.append("</div>\n")
            else:
                self.context.append("")
            self.body.append(self.emptytag(node, "img", "", **atts))
            return

        if "scale" in node:
            # Try to figure out image height and width.  Docutils does that too,
            # but it tries the final file name, which does not necessarily exist
            # yet at the time the HTML file is written.
            if not ("width" in node and "height" in node):
                size = get_image_size(path.join(self.builder.srcdir, olduri))
                if size is None:
                    self.builder.env.warn_node("Could not obtain image size. " ":scale: option is ignored.", node)
                else:
                    if "width" not in node:
                        node["width"] = str(size[0])
                    if "height" not in node:
                        node["height"] = str(size[1])
        BaseTranslator.visit_image(self, node)