diff options
Diffstat (limited to 'sphinx/ext/jsmath.py')
-rw-r--r-- | sphinx/ext/jsmath.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/sphinx/ext/jsmath.py b/sphinx/ext/jsmath.py index 63bcf248e..84e0f9037 100644 --- a/sphinx/ext/jsmath.py +++ b/sphinx/ext/jsmath.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ sphinx.ext.jsmath ~~~~~~~~~~~~~~~~~ @@ -10,9 +9,13 @@ :license: BSD, see LICENSE for details. """ +from typing import cast + from docutils import nodes import sphinx +from sphinx.builders.html import StandaloneHTMLBuilder +from sphinx.domains.math import MathDomain from sphinx.errors import ExtensionError from sphinx.locale import _ from sphinx.util.math import get_node_equation_number @@ -22,17 +25,18 @@ if False: from typing import Any, Dict # NOQA from sphinx.application import Sphinx # NOQA from sphinx.environment import BuildEnvironment # NOQA + from sphinx.writers.html import HTMLTranslator # NOQA def html_visit_math(self, node): - # type: (nodes.NodeVisitor, nodes.Node) -> None + # type: (HTMLTranslator, nodes.math) -> None self.body.append(self.starttag(node, 'span', '', CLASS='math notranslate nohighlight')) self.body.append(self.encode(node.astext()) + '</span>') raise nodes.SkipNode def html_visit_displaymath(self, node): - # type: (nodes.NodeVisitor, nodes.Node) -> None + # type: (HTMLTranslator, nodes.math_block) -> None if node['nowrap']: self.body.append(self.starttag(node, 'div', CLASS='math notranslate nohighlight')) self.body.append(self.encode(node.astext())) @@ -67,13 +71,15 @@ def install_jsmath(app, env): raise ExtensionError('jsmath_path config value must be set for the ' 'jsmath extension to work') - if env.get_domain('math').has_equations(): # type: ignore + builder = cast(StandaloneHTMLBuilder, app.builder) + domain = cast(MathDomain, env.get_domain('math')) + if domain.has_equations(): # Enable jsmath only if equations exists - app.builder.add_js_file(app.config.jsmath_path) # type: ignore + builder.add_js_file(app.config.jsmath_path) def setup(app): - # type: (Sphinx) -> Dict[unicode, Any] + # type: (Sphinx) -> Dict[str, Any] app.add_html_math_renderer('jsmath', (html_visit_math, None), (html_visit_displaymath, None)) |