mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Enable automatic formatting for `sphinx/ext/autosectionlabel.py
`
This commit is contained in:
parent
e81c4e865e
commit
e637f3ea48
@ -415,7 +415,6 @@ exclude = [
|
||||
"sphinx/domains/python/_object.py",
|
||||
"sphinx/domains/rst.py",
|
||||
"sphinx/domains/std/__init__.py",
|
||||
"sphinx/ext/autosectionlabel.py",
|
||||
"sphinx/ext/autosummary/__init__.py",
|
||||
"sphinx/ext/coverage.py",
|
||||
"sphinx/ext/doctest.py",
|
||||
|
@ -32,8 +32,10 @@ def get_node_depth(node: Node) -> int:
|
||||
def register_sections_as_label(app: Sphinx, document: Node) -> None:
|
||||
domain = app.env.domains.standard_domain
|
||||
for node in document.findall(nodes.section):
|
||||
if (app.config.autosectionlabel_maxdepth and
|
||||
get_node_depth(node) >= app.config.autosectionlabel_maxdepth):
|
||||
if (
|
||||
app.config.autosectionlabel_maxdepth
|
||||
and get_node_depth(node) >= app.config.autosectionlabel_maxdepth
|
||||
):
|
||||
continue
|
||||
labelid = node['ids'][0]
|
||||
docname = app.env.docname
|
||||
@ -45,13 +47,23 @@ def register_sections_as_label(app: Sphinx, document: Node) -> None:
|
||||
name = nodes.fully_normalize_name(ref_name)
|
||||
sectname = clean_astext(title)
|
||||
|
||||
logger.debug(__('section "%s" gets labeled as "%s"'),
|
||||
ref_name, name,
|
||||
location=node, type='autosectionlabel', subtype=docname)
|
||||
logger.debug(
|
||||
__('section "%s" gets labeled as "%s"'),
|
||||
ref_name,
|
||||
name,
|
||||
location=node,
|
||||
type='autosectionlabel',
|
||||
subtype=docname,
|
||||
)
|
||||
if name in domain.labels:
|
||||
logger.warning(__('duplicate label %s, other instance in %s'),
|
||||
name, app.env.doc2path(domain.labels[name][0]),
|
||||
location=node, type='autosectionlabel', subtype=docname)
|
||||
logger.warning(
|
||||
__('duplicate label %s, other instance in %s'),
|
||||
name,
|
||||
app.env.doc2path(domain.labels[name][0]),
|
||||
location=node,
|
||||
type='autosectionlabel',
|
||||
subtype=docname,
|
||||
)
|
||||
|
||||
domain.anonlabels[name] = docname, labelid
|
||||
domain.labels[name] = docname, labelid, sectname
|
||||
|
Loading…
Reference in New Issue
Block a user