mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Make it more probable for docutils to report the correct source
for content generated by autodoc.
This commit is contained in:
parent
66609e8165
commit
4e9d0f4f4b
@ -428,6 +428,7 @@ def desc_directive(desctype, arguments, options, content, lineno,
|
||||
env = state.document.settings.env
|
||||
inode = addnodes.index(entries=[])
|
||||
node = addnodes.desc()
|
||||
node.document = state.document
|
||||
node['desctype'] = desctype
|
||||
|
||||
noindex = ('noindex' in options)
|
||||
@ -520,6 +521,7 @@ def desc_directive(desctype, arguments, options, content, lineno,
|
||||
inode['entries'].append(('single', indextext, fullname, fullname))
|
||||
|
||||
subnode = addnodes.desc_content()
|
||||
node.append(subnode)
|
||||
# needed for automatic qualification of members
|
||||
clsname_set = False
|
||||
if desctype in ('class', 'exception') and names:
|
||||
@ -537,7 +539,6 @@ def desc_directive(desctype, arguments, options, content, lineno,
|
||||
if clsname_set:
|
||||
env.currclass = None
|
||||
env.currdesc = None
|
||||
node.append(subnode)
|
||||
return [inode, node]
|
||||
|
||||
desc_directive.content = 1
|
||||
|
@ -228,6 +228,7 @@ directives.register_directive('index', index_directive)
|
||||
def version_directive(name, arguments, options, content, lineno,
|
||||
content_offset, block_text, state, state_machine):
|
||||
node = addnodes.versionmodified()
|
||||
node.document = state.document
|
||||
node['type'] = name
|
||||
node['version'] = arguments[0]
|
||||
if len(arguments) == 2:
|
||||
@ -333,6 +334,7 @@ def glossary_directive(name, arguments, options, content, lineno,
|
||||
"""Glossary with cross-reference targets for :term: roles."""
|
||||
env = state.document.settings.env
|
||||
node = addnodes.glossary()
|
||||
node.document = state.document
|
||||
state.nested_parse(content, content_offset, node)
|
||||
|
||||
# the content should be definition lists
|
||||
@ -381,6 +383,7 @@ directives.register_directive('centered', centered_directive)
|
||||
def acks_directive(name, arguments, options, content, lineno,
|
||||
content_offset, block_text, state, state_machine):
|
||||
node = addnodes.acks()
|
||||
node.document = state.document
|
||||
state.nested_parse(content, content_offset, node)
|
||||
if len(node.children) != 1 or not isinstance(node.children[0], nodes.bullet_list):
|
||||
return [state.document.reporter.warning('.. acks content is not a list',
|
||||
@ -396,6 +399,7 @@ def hlist_directive(name, arguments, options, content, lineno,
|
||||
content_offset, block_text, state, state_machine):
|
||||
ncolumns = options.get('columns', 2)
|
||||
node = nodes.paragraph()
|
||||
node.document = state.document
|
||||
state.nested_parse(content, content_offset, node)
|
||||
if len(node.children) != 1 or not isinstance(node.children[0], nodes.bullet_list):
|
||||
return [state.document.reporter.warning('.. hlist content is not a list',
|
||||
|
@ -652,9 +652,12 @@ def _auto_directive(dirname, arguments, options, content, lineno,
|
||||
state.memo.reporter = AutodocReporter(generator.result, state.memo.reporter)
|
||||
if dirname == 'automodule':
|
||||
node = nodes.section()
|
||||
node.document = state.document # necessary so that the child nodes
|
||||
# get the right source/line set
|
||||
nested_parse_with_titles(state, generator.result, node)
|
||||
else:
|
||||
node = nodes.paragraph()
|
||||
node.document = state.document
|
||||
state.nested_parse(generator.result, 0, node)
|
||||
state.memo.reporter = old_reporter
|
||||
return generator.warnings + node.children
|
||||
|
@ -281,9 +281,11 @@ def nested_parse_with_titles(state, content, node):
|
||||
surrounding_section_level = state.memo.section_level
|
||||
state.memo.title_styles = []
|
||||
state.memo.section_level = 0
|
||||
state.nested_parse(content, 0, node, match_titles=1)
|
||||
state.memo.title_styles = surrounding_title_styles
|
||||
state.memo.section_level = surrounding_section_level
|
||||
try:
|
||||
return state.nested_parse(content, 0, node, match_titles=1)
|
||||
finally:
|
||||
state.memo.title_styles = surrounding_title_styles
|
||||
state.memo.section_level = surrounding_section_level
|
||||
|
||||
|
||||
def ustrftime(format, *args):
|
||||
@ -374,7 +376,9 @@ def movefile(source, dest):
|
||||
os.rename(source, dest)
|
||||
|
||||
|
||||
# monkey-patch Node.traverse
|
||||
# monkey-patch Node.traverse to get more speed
|
||||
# traverse() is called so many times during a build that it saves
|
||||
# on average 20-25% overall build time!
|
||||
|
||||
def _all_traverse(self):
|
||||
"""Version of Node.traverse() that doesn't need a condition."""
|
||||
|
Loading…
Reference in New Issue
Block a user