本文整理汇总了Python中sphinx.writers.html.HTMLTranslator.visit_document方法的典型用法代码示例。如果您正苦于以下问题:Python HTMLTranslator.visit_document方法的具体用法?Python HTMLTranslator.visit_document怎么用?Python HTMLTranslator.visit_document使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sphinx.writers.html.HTMLTranslator
的用法示例。
在下文中一共展示了HTMLTranslator.visit_document方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: visit_document
# 需要导入模块: from sphinx.writers.html import HTMLTranslator [as 别名]
# 或者: from sphinx.writers.html.HTMLTranslator import visit_document [as 别名]
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