Fix annotations

This commit is contained in:
Takeshi KOMIYA 2018-12-10 00:35:46 +09:00
parent f05eb1e8ec
commit 375ab2ac78
5 changed files with 11 additions and 8 deletions

View File

@ -82,7 +82,7 @@ class CObject(ObjectDescription):
))
def _parse_type(self, node, ctype):
# type: (nodes.Node, unicode) -> None
# type: (nodes.Element, unicode) -> None
# add cross-ref nodes for all words
for part in [_f for _f in wsplit_re.split(ctype) if _f]:
tnode = nodes.Text(part, part)

View File

@ -146,7 +146,7 @@ class BuildEnvironment:
self.longtitles = {} # type: Dict[unicode, nodes.title]
# docname -> title node; only different if
# set differently with title directive
self.tocs = {} # type: Dict[unicode, nodes.Element]
self.tocs = {} # type: Dict[unicode, nodes.bullet_list]
# docname -> table of contents nodetree
self.toc_num_entries = {} # type: Dict[unicode, int]
# docname -> number of real entries

View File

@ -74,11 +74,11 @@ class ReferencesResolver(SphinxTransform):
node.replace_self(newnode or contnode)
def resolve_anyref(self, refdoc, node, contnode):
# type: (unicode, addnodes.pending_xref, nodes.Node) -> nodes.Node
# type: (unicode, addnodes.pending_xref, nodes.TextElement) -> nodes.Element
"""Resolve reference generated by the "any" role."""
stddomain = self.env.get_domain('std')
target = node['reftarget']
results = [] # type: List[Tuple[unicode, nodes.Node]]
results = [] # type: List[Tuple[unicode, nodes.Element]]
# first, try resolving as :doc:
doc_ref = stddomain.resolve_xref(self.env, refdoc, self.app.builder,
'doc', target, node, contnode)
@ -116,7 +116,9 @@ class ReferencesResolver(SphinxTransform):
# Override "any" class with the actual role type to get the styling
# approximately correct.
res_domain = res_role.split(':')[0]
if newnode and newnode[0].get('classes'):
if (len(newnode) > 0 and
isinstance(newnode[0], nodes.Element) and
newnode[0].get('classes')):
newnode[0]['classes'].append(res_domain)
newnode[0]['classes'].append(res_role.replace(':', '-'))
return newnode

View File

@ -217,7 +217,7 @@ class TypedField(GroupedField):
# inconsistencies later when references are resolved
fieldtype = types.pop(fieldarg)
if len(fieldtype) == 1 and isinstance(fieldtype[0], nodes.Text):
typename = u''.join(n.astext() for n in fieldtype)
typename = fieldtype[0].astext()
par.extend(self.make_xrefs(self.typerolename, domain, typename,
addnodes.literal_emphasis, env=env))
else:

View File

@ -1205,7 +1205,8 @@ class TexinfoTranslator(SphinxTranslator):
def visit_admonition(self, node, name=''):
# type: (nodes.admonition, unicode) -> None
if not name:
name = self.escape(node[0].astext())
title = cast(nodes.title, node[0])
name = self.escape(title.astext())
self.body.append(u'\n@cartouche\n@quotation %s ' % name)
def _visit_named_admonition(self, node):
@ -1279,7 +1280,7 @@ class TexinfoTranslator(SphinxTranslator):
# ignore TOC's since we have to have a "menu" anyway
if 'contents' in node.get('classes', []):
raise nodes.SkipNode
title = node[0]
title = cast(nodes.title, node[0])
self.visit_rubric(title)
self.body.append('%s\n' % self.escape(title.astext()))