mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
refactor: autosectionlabel: Use accessors of std domain
This commit is contained in:
parent
74351b2d43
commit
04698d525a
@ -15,6 +15,7 @@ from docutils import nodes
|
||||
from docutils.nodes import Node
|
||||
|
||||
from sphinx.application import Sphinx
|
||||
from sphinx.domains.std import StandardDomain
|
||||
from sphinx.locale import __
|
||||
from sphinx.util import logging
|
||||
from sphinx.util.nodes import clean_astext
|
||||
@ -33,8 +34,7 @@ def get_node_depth(node: Node) -> int:
|
||||
|
||||
|
||||
def register_sections_as_label(app: Sphinx, document: Node) -> None:
|
||||
labels = app.env.domaindata['std']['labels']
|
||||
anonlabels = app.env.domaindata['std']['anonlabels']
|
||||
domain = cast(StandardDomain, app.env.get_domain('std'))
|
||||
for node in document.traverse(nodes.section):
|
||||
if (app.config.autosectionlabel_maxdepth and
|
||||
get_node_depth(node) >= app.config.autosectionlabel_maxdepth):
|
||||
@ -49,13 +49,13 @@ def register_sections_as_label(app: Sphinx, document: Node) -> None:
|
||||
name = nodes.fully_normalize_name(ref_name)
|
||||
sectname = clean_astext(title)
|
||||
|
||||
if name in labels:
|
||||
if name in domain.labels:
|
||||
logger.warning(__('duplicate label %s, other instance in %s'),
|
||||
name, app.env.doc2path(labels[name][0]),
|
||||
name, app.env.doc2path(domain.labels[name][0]),
|
||||
location=node, type='autosectionlabel', subtype=docname)
|
||||
|
||||
anonlabels[name] = docname, labelid
|
||||
labels[name] = docname, labelid, sectname
|
||||
domain.anonlabels[name] = docname, labelid
|
||||
domain.labels[name] = docname, labelid, sectname
|
||||
|
||||
|
||||
def setup(app: Sphinx) -> Dict[str, Any]:
|
||||
|
Loading…
Reference in New Issue
Block a user