""" sphinx.ext.jsmath ~~~~~~~~~~~~~~~~~ Set up everything for use of JSMath to display math in HTML via JavaScript. :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS. :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 if False: # For type annotation 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: (HTMLTranslator, nodes.math) -> None self.body.append(self.starttag(node, 'span', '', CLASS='math notranslate nohighlight')) self.body.append(self.encode(node.astext()) + '') raise nodes.SkipNode def html_visit_displaymath(self, node): # 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())) self.body.append('') raise nodes.SkipNode for i, part in enumerate(node.astext().split('\n\n')): part = self.encode(part) if i == 0: # necessary to e.g. set the id property correctly if node['number']: number = get_node_equation_number(self, node) self.body.append('(%s)' % number) self.add_permalink_ref(node, _('Permalink to this equation')) self.body.append('') self.body.append(self.starttag(node, 'div', CLASS='math notranslate nohighlight')) else: # but only once! self.body.append('