diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-06-03 15:45:52 +0300 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-06-15 17:05:45 +0300 |
commit | 9b0f415e217c3167057d39b30ef4f873a893e5ff (patch) | |
tree | d78d42ee42cf313fe74df688c9350575f2f0e3bc /sphinx/directives | |
parent | e5881c23449f8fd78c87796897d42c7cb6b9037b (diff) |
refactor: Add data accessors to MathDomain
Diffstat (limited to 'sphinx/directives')
-rw-r--r-- | sphinx/directives/patches.py | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/sphinx/directives/patches.py b/sphinx/directives/patches.py index b4b1664ab..7bc13bf87 100644 --- a/sphinx/directives/patches.py +++ b/sphinx/directives/patches.py @@ -16,6 +16,7 @@ from docutils.parsers.rst.directives import images, html, tables from sphinx import addnodes from sphinx.directives import optional_int +from sphinx.domains.math import MathDomain from sphinx.util.docutils import SphinxDirective from sphinx.util.nodes import set_source_info @@ -194,18 +195,15 @@ class MathDirective(SphinxDirective): return # register label to domain - domain = self.env.get_domain('math') - try: - eqno = domain.add_equation(self.env, self.env.docname, node['label']) # type: ignore # NOQA - node['number'] = eqno - - # add target node - node_id = make_id('equation-%s' % node['label']) - target = nodes.target('', '', ids=[node_id]) - self.state.document.note_explicit_target(target) - ret.insert(0, target) - except UserWarning as exc: - self.state_machine.reporter.warning(exc, line=self.lineno) + domain = cast(MathDomain, self.env.get_domain('math')) + domain.note_equation(self.env.docname, node['label'], location=node) + node['number'] = domain.get_equation_number_for(node['label']) + + # add target node + node_id = make_id('equation-%s' % node['label']) + target = nodes.target('', '', ids=[node_id]) + self.state.document.note_explicit_target(target) + ret.insert(0, target) def setup(app: "Sphinx") -> Dict[str, Any]: |