def get_entries(self):
def _get_sections(doctree):
"""
Return all sections after the 'Examples' section
"""
# Do not traverse all the sections, only look for those
# that are siblings of the first node.
ref_node = doctree[0][0]
kwargs = dict(descend=False, siblings=True)
exnode = None # Examples node
for section in ref_node.traverse(nodes.section, **kwargs):
if section[0].astext() == 'Examples':
exnode = section
break
if not exnode:
return
for section in exnode[0].traverse(nodes.section, **kwargs):
yield section
for section in _get_sections(self.doctree):
section_id = section.attributes['ids'][0]
section_title = section[0].astext()
# If an emphasis follows the section, it is the description
if isinstance(section[1][0], nodes.emphasis):
description = section[1][0].astext()
else:
description = ''
# Last image in the section is used to create the thumbnail
try:
image_node = section.traverse(nodes.image)[-1]
except IndexError:
continue
else:
image_filename = image_node.attributes['uri']
yield GalleryEntry(
title=section_title,
section_id=section_id,
html_link='{}#{}'.format(self.htmlfilename, section_id),
thumbnail=self.make_thumbnail(image_filename),
description=description)
评论列表
文章目录