本文整理汇总了Python中sphinx.writers.html.HTMLTranslator类的典型用法代码示例。如果您正苦于以下问题:Python HTMLTranslator类的具体用法?Python HTMLTranslator怎么用?Python HTMLTranslator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HTMLTranslator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: depart_title
def depart_title(self, node):
close_tag = self.context[-1]
if (self.permalink_text and self.builder.add_permalinks and node.parent.hasattr('ids') and node.parent['ids']):
aname = ''
for id in node.parent['ids']:
if self.builder.env.domaindata['std']['labels'].has_key(id):
ref_text = '. Label :ref:`%s`' % id
aname = id
break
if aname:
link_text = ':ref:'
else:
ref_text = ''
aname = node.parent['ids'][0]
link_text = self.permalink_text
# add permalink anchor
if close_tag.startswith('</h'):
what = u'<a class="headerlink" href="#%s" ' % aname + u'title="%s">%s</a>' % (
_('Permalink to this headline') + ref_text, link_text)
if 0:
print 'what:', repr(what)
print 'aname:', repr(aname)
self.body.append(what)
elif close_tag.startswith('</a></h'):
what = u'</a><a class="headerlink" href="#%s" ' % aname + u'title="%s">%s' % (
_('Permalink to this headline') + ref_text, link_text)
if 0:
print 'what:', repr(what)
print 'aname:', repr(aname)
self.body.append(what)
HTMLTranslator.depart_title(self, node)
开发者ID:marble,项目名称:typo3-ExtendingSphinxForTYPO3,代码行数:34,代码来源:t3htmlwriter.py
示例2: visit_reference
def visit_reference(self, node):
if self.in_subnav and 'subnav-toggle' in node['classes']:
toggle = nodes.raw(
'', '<b class="dropdown-toggle caret" data-toggle="dropdown"></b>')
toggle['format'] = 'html'
node.append(toggle)
SphinxHTMLTranslator.visit_reference(self, node)
开发者ID:FisherLab,项目名称:slave,代码行数:7,代码来源:__init__.py
示例3: __init__
def __init__(self, builder, *args, **kwds):
"""
constructor
"""
HTMLTranslator.__init__(self, builder, *args, **kwds)
for name, f1, f2 in builder._function_node:
setattr(self.__class__, "visit_" + name, f1)
setattr(self.__class__, "depart_" + name, f2)
开发者ID:,项目名称:,代码行数:8,代码来源:
示例4: __init__
def __init__(self, *args, **kwargs):
HTMLTranslator.__init__(self, *args, **kwargs)
self.section_count = 0
self.body_stack = []
self.current_slide = None
self.slide_data = []
开发者ID:harrisonfeng,项目名称:hieroglyph,代码行数:8,代码来源:writer.py
示例5: visit_title
def visit_title(self, node):
if isinstance(node.parent, nodes.section):
level = self.section_level + self.initial_header_level - 1
tag = 'h%s' % level
self.body.append(self.starttag(node, tag, ''))
self.context.append('</%s>\n' % tag)
else:
HTMLTranslator.visit_title(self, node)
开发者ID:AndreaCrotti,项目名称:hieroglyph,代码行数:9,代码来源:writer.py
示例6: __init__
def __init__(self, builder, document, *args, **kwargs):
HTMLTranslator.__init__(self, builder, document, *args, **kwargs)
self._title = None # section title
self.parent = None
self.add_to_toc = False
self.order = 0
self.add_permalinks = False
self.css = ['main.css']
self._images = set()
开发者ID:nvdnkpr,项目名称:rst2epub2,代码行数:9,代码来源:sphinxext.py
示例7: depart_title
def depart_title(self, node):
if node.parent.hasattr('ids') and node.parent['ids'] and \
self.section_level == 2:
print "TITLE",self.section_level,node.parent['ids'][0]
#self._title = node.parent['ids'][0]
self._title = striptags(''.join(self.body[1:]))
print "\t",str(node)[:50]
print "\tBODY", self.body[:4]
HTMLTranslator.depart_title(self, node)
开发者ID:nvdnkpr,项目名称:rst2epub2,代码行数:9,代码来源:sphinxext.py
示例8: depart_title
def depart_title(self, node):
if self.current_slide and isinstance(node.parent, (nodes.section, slide)):
self.current_slide.title = "".join(self.body)
self.pop_body()
else:
HTMLTranslator.depart_title(self, node)
title = "".join(self.body)
self.pop_body()
self.body.append(title)
开发者ID:harrisonfeng,项目名称:hieroglyph,代码行数:10,代码来源:writer.py
示例9: visit_image
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
开发者ID:marble,项目名称:typo3-ExtendingSphinxForTYPO3,代码行数:55,代码来源:t3htmlwriter.py
示例10: visit_title
def visit_title(self, node):
if isinstance(node.parent, slide) or node.parent.attributes.get("include-as-slide", False):
slide_level = node.parent.attributes.get("level", self.section_level)
level = max(slide_level + self.initial_header_level - 1, 1)
tag = "h%s" % level
self.body.append(self.starttag(node, tag, ""))
self.context.append("</%s>\n" % tag)
else:
HTMLTranslator.visit_title(self, node)
开发者ID:prodigeni,项目名称:hieroglyph,代码行数:11,代码来源:writer.py
示例11: visit_title
def visit_title(self, node):
if isinstance(node.parent, nodes.section) and not self.builder.has_title(self.document):
h_level = self.section_level + self.initial_header_level - 1
if h_level == 1:
# Confluence take first title for page title from rst
# It use for making internal links
self.builder.set_title(self.document, node.children[0])
# ignore first header; document must have title header
raise nodes.SkipNode
HTMLTranslator.visit_title(self, node)
开发者ID:chadmv,项目名称:sphinx-confluence,代码行数:12,代码来源:__init__.py
示例12: depart_title
def depart_title(self, node):
if node.parent.hasattr("ids") and node.parent["ids"]:
aname = node.parent["ids"][0]
if self.builder.app.config.slide_link_to_html:
self.body.append(
u'<a class="headerlink" href="%s#%s" ' % (html.html_path(self.builder), aname)
+ u'title="%s">%s</a>' % (_("View HTML"), self.builder.app.config.slide_html_slide_link_symbol)
)
HTMLTranslator.depart_title(self, node)
开发者ID:prodigeni,项目名称:hieroglyph,代码行数:12,代码来源:writer.py
示例13: visit_document
def visit_document(self, node):
SphinxHTMLTranslator.visit_document(self, node)
# used to detect that bullet_lists are for the global and page tocs
self.is_partial = node.get('source') == '<partial node>'
self.page_toc_position = self.builder.config.html_theme_options.get(
'page_toc_position', 'subnav')
self.toc_nav = self.page_toc_position == 'nav'
self.toc_subnav = self.page_toc_position == 'subnav'
self.toc_sidebar = self.page_toc_position.startswith('sidebar-')
self.page_toc_handled_first = False
if self.toc_subnav:
self.page_toc_maxdepth = 1
else:
self.page_toc_maxdepth = int(
self.builder.config.html_theme_options.get('page_toc_maxdepth', '-1'))
self.in_subnav = False
if not self.is_partial and self.toc_subnav:
docname = os.path.relpath(
node['source'],
self.builder.env.srcdir
)
suffixes = self.builder.config.source_suffix
# retain backwards compatibility with sphinx < 1.3
if isinstance(suffixes, basestring):
suffixes = [suffixes]
for suffix in suffixes:
if docname.endswith(suffix):
docname = docname[:-len(suffix)]
break
self.page_toc = self.builder.env.get_toc_for(docname, self.builder)
toc_empty = bool(
not len(self.page_toc.children) or
len(self.page_toc.children[0].children) <= 1)
if not toc_empty:
toc_empty = True
for child in self.page_toc.children[0].children[1]:
if isinstance(child, nodes.list_item):
toc_empty = False
break
if not toc_empty:
# for page toc in the subnav, skip the first list
self.page_toc = self.page_toc.children[0].children[1]
self.page_toc['classes'].append('nav')
else:
self.page_toc = None
开发者ID:ervandew,项目名称:sphinx-bootstrap-theme,代码行数:53,代码来源:__init__.py
示例14: dispatch_visit
def dispatch_visit(self, node):
# Be super defensive at the top-level so we don't break builds
try:
if hasattr(self.builder.env, 'comment_config_map'):
config_map = self.builder.env.comment_config_map
page_config = config_map.get(self.builder.current_docname, [])
else:
page_config = {'header'}
if is_commentable(node, page_config):
self.handle_visit_commentable(node)
except Exception as e:
print('[Commenting] Visit Error: %s' % e)
HTMLTranslator.dispatch_visit(self, node)
开发者ID:blaisep,项目名称:readthedocs-sphinx-ext,代码行数:14,代码来源:translator.py
示例15: visit_section
def visit_section(self, node):
# insert the subnav after the section heading + optional lead
if not self.is_partial and \
self.toc_subnav and \
self.page_toc and \
self.section_level == 0:
index = 0
children = node.children
if len(children) and isinstance(children[0], nodes.title):
index = 1
if index and len(children) > 1 and 'lead' in children[1].get('classes'):
index = 2
node.children.insert(index, self.page_toc)
SphinxHTMLTranslator.visit_section(self, node)
开发者ID:FisherLab,项目名称:slave,代码行数:15,代码来源:__init__.py
示例16: depart_title
def depart_title(self, node):
# print "--TITLE", node.text
if not self._title:
self._title = striptags(''.join(self.body[1:]))
print "\n\n**title", self.section_level, ''.join(self.body[1:])[:150]
low_level = self.section_level \
<= int(self.builder.config.mobi_chapter_level)
if node.parent.getattr('ids', False) and low_level:
print "TITLE", self.section_level, node.parent['ids'][0]
self._title = striptags(''.join(self.body[1:]))
print "\t", str(node)[:50]
print "\tBODY", self.body[:4]
else:
print "FALSE"
HTMLTranslator.depart_title(self, node)
开发者ID:mattharrison,项目名称:rst2epub2,代码行数:15,代码来源:sphinxext.py
示例17: visit_block_quote
def visit_block_quote(self, node):
quote_slide_tags = ['paragraph', 'attribution']
# see if this looks like a quote slide
if (len(node.children) <= 2 and
[c.tagname for c in node.children] == quote_slide_tags[:len(node.children)]):
# process this as a quote slide
# first child must be a paragraph, process it as a <q> element
p = node.children[0]
self.body.append(self.starttag(node, 'q'))
for text_item in p:
text_item.walkabout(self)
self.body.append('</q>\n')
# optional second child must be an attribution, processing as a <div>
# following the <q>
if len(node.children) > 1:
attr = node.children[1]
self.body.append(self.starttag(attr, 'div', CLASS="author"))
for text_item in attr:
text_item.walkabout(self)
self.body.append('</div>\n')
# skip all normal processing
raise nodes.SkipNode
else:
return HTMLTranslator.visit_block_quote(self, node)
开发者ID:shuangjj,项目名称:hieroglyph,代码行数:31,代码来源:writer.py
示例18: visit_title
def visit_title(self, node):
self.push_body()
if isinstance(node.parent, slide) or node.parent.attributes.get("include-as-slide", False):
slide_level = node.parent.attributes.get("level", self.section_level)
level = max(slide_level + self.initial_header_level - 1, 1)
self.current_slide.level = level
# tag = 'h%s' % level
# self.body.append(self.starttag(node, tag, ''))
# self.context.append('</%s>\n' % tag)
if self.current_slide and isinstance(node.parent, (nodes.section, slide)):
self.current_slide.title = node.astext().strip()
else:
HTMLTranslator.visit_title(self, node)
开发者ID:harrisonfeng,项目名称:hieroglyph,代码行数:17,代码来源:writer.py
示例19: visit_title
def visit_title(self, node):
if (isinstance(node.parent, slide) or
node.parent.attributes.get('include-as-slide', False)):
slide_level = node.parent.attributes.get(
'level',
self.section_level)
level = max(
slide_level + self.initial_header_level - 1,
1,
)
tag = 'h%s' % level
self.body.append(self.starttag(node, tag, ''))
self.context.append('</%s>\n' % tag)
else:
HTMLTranslator.visit_title(self, node)
开发者ID:timtan,项目名称:hieroglyph,代码行数:17,代码来源:writer.py
示例20: visit_image
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)
开发者ID:FMHelder,项目名称:rst2epub2,代码行数:19,代码来源:sphinxext.py
注:本文中的sphinx.writers.html.HTMLTranslator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论