本文整理汇总了Python中docutils.writers.html5_polyglot.HTMLTranslator.visit_image方法的典型用法代码示例。如果您正苦于以下问题:Python HTMLTranslator.visit_image方法的具体用法?Python HTMLTranslator.visit_image怎么用?Python HTMLTranslator.visit_image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docutils.writers.html5_polyglot.HTMLTranslator
的用法示例。
在下文中一共展示了HTMLTranslator.visit_image方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: visit_image
# 需要导入模块: from docutils.writers.html5_polyglot import HTMLTranslator [as 别名]
# 或者: from docutils.writers.html5_polyglot.HTMLTranslator import visit_image [as 别名]
def visit_image(self, node):
# type: (nodes.Node) -> None
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', '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(os.path.join(self.builder.srcdir, olduri))
if size is None:
logger.warning('Could not obtain image size. :scale: option is ignored.',
location=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)