本文整理汇总了Python中sphinx.writers.html.HTMLTranslator.visit_image方法的典型用法代码示例。如果您正苦于以下问题:Python HTMLTranslator.visit_image方法的具体用法?Python HTMLTranslator.visit_image怎么用?Python HTMLTranslator.visit_image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sphinx.writers.html.HTMLTranslator
的用法示例。
在下文中一共展示了HTMLTranslator.visit_image方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: visit_image
# 需要导入模块: from sphinx.writers.html import HTMLTranslator [as 别名]
# 或者: from sphinx.writers.html.HTMLTranslator import visit_image [as 别名]
def visit_image(self, node):
olduri = node['uri']
s = olduri.lower()
go = True
go = go and not Image is None
go = go and not (s.endswith('svg') or
s.endswith('svgz') or
s.endswith('swf'))
go = go and not (node.has_key('width') or
node.has_key('height') or
node.has_key('scale'))
if go and node.has_key('classes'):
go = go and not 'screenshot-detail' in node['classes']
if go:
# 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.
try:
im = Image.open(os.path.join(self.builder.srcdir, olduri))
except (IOError, # Source image can't be found or opened
UnicodeError): # PIL doesn't like Unicode paths.
go = False # better warn?
else:
im_width = str(im.size[0])
im_height = str(im.size[1])
del im
if go:
# 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])
atts = {}
atts['src'] = node['uri']
if not node.has_key('classes'):
node['classes'] = ['img-scaling']
elif not 'img-scaling' in node['classes']:
node['classes'].append('img-scaling')
else:
pass
atts['style'] = 'max-width: %spx;' % im_width
if node.has_key('alt'):
atts['alt'] = node['alt']
else:
atts['alt'] = node['uri']
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('')
self.body.append(self.emptytag(node, 'img', '', **atts))
else:
del s, go
HTMLTranslator.visit_image(self,node)
return
示例2: visit_image
# 需要导入模块: from sphinx.writers.html import HTMLTranslator [as 别名]
# 或者: from sphinx.writers.html.HTMLTranslator import visit_image [as 别名]
def visit_image(self, node):
olduri = node['uri']
import pdb;pdb.set_trace()
# 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])
# #import pdb; pdb.set_trace()
print "IMAGE!!!", node, node['uri'], path.abspath(node['uri'])
if path.abspath(olduri) != olduri:
pass
# # relative
# dest = path.join(self.builder.outdir,olduri)
# print "COPYING TO", dest
# olduri = path.join(path.dirname(self.doc_path),
# dest)
self._images.add(path.abspath(olduri))
self.builder.ebook.add_image(path.abspath(olduri), olduri, id='image_{0}'.format(len(self._images)))
HTMLTranslator.visit_image(self, node)
示例3: visit_image
# 需要导入模块: from sphinx.writers.html import HTMLTranslator [as 别名]
# 或者: from sphinx.writers.html.HTMLTranslator import visit_image [as 别名]
def visit_image(self, node):
print "IMAGE!!!", node, node['uri'], path.abspath(node['uri'])
self._images.add(path.abspath(node['uri']))
print "images", self._images
HTMLTranslator.visit_image(self, node)