Merge pull request #5886 from tk0miya/separate_jsmath

Separate jsmath to sphinxcontrib package
This commit is contained in:
Takeshi KOMIYA 2019-01-13 14:17:09 +09:00 committed by GitHub
commit 0c2511d2c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 32 additions and 120 deletions

View File

@ -18,6 +18,9 @@ Dependencies
e.g. in Fedora 29 via package ``texlive-gnu-freefont``.
* requests 2.5.0 or above
* The six package is no longer a dependency.
* Some packages are separated to sub packages:
- sphinxcontrib.jsmath
Incompatible changes
--------------------

View File

@ -350,6 +350,11 @@ The following is a list of deprecated interfaces.
- 4.0
- N/A
* - ``sphinx.ext.jsmath``
- 2.0
- 4.0
- ``sphinxcontrib.jsmath``
* - ``sphinx.testing.util.remove_unicode_literal()``
- 2.0
- 4.0

View File

@ -15,6 +15,7 @@ if sys.version_info < (3, 5):
sys.exit(1)
install_requires = [
'sphinxcontrib-jsmath',
'Jinja2>=2.3',
'Pygments>=2.0',
'docutils>=0.12',

View File

@ -9,81 +9,32 @@
:license: BSD, see LICENSE for details.
"""
from typing import cast
import warnings
from docutils import nodes
from sphinxcontrib.jsmath import ( # NOQA
html_visit_math,
html_visit_displaymath,
install_jsmath,
)
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
from sphinx.deprecation import RemovedInSphinx40Warning
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()) + '</span>')
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('</div>')
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('<span class="eqno">(%s)' % number)
self.add_permalink_ref(node, _('Permalink to this equation'))
self.body.append('</span>')
self.body.append(self.starttag(node, 'div', CLASS='math notranslate nohighlight'))
else:
# but only once!
self.body.append('<div class="math">')
if '&' in part or '\\\\' in part:
self.body.append('\\begin{split}' + part + '\\end{split}')
else:
self.body.append(part)
self.body.append('</div>\n')
raise nodes.SkipNode
def install_jsmath(app, env):
# type: (Sphinx, BuildEnvironment) -> None
if app.builder.format != 'html' or app.builder.math_renderer_name != 'jsmath': # type: ignore # NOQA
return
if not app.config.jsmath_path:
raise ExtensionError('jsmath_path config value must be set for the '
'jsmath extension to work')
builder = cast(StandaloneHTMLBuilder, app.builder)
domain = cast(MathDomain, env.get_domain('math'))
if domain.has_equations():
# Enable jsmath only if equations exists
builder.add_js_file(app.config.jsmath_path)
def setup(app):
# type: (Sphinx) -> Dict[str, Any]
app.add_html_math_renderer('jsmath',
(html_visit_math, None),
(html_visit_displaymath, None))
warnings.warn('sphinx.ext.jsmath has been moved to sphinxcontrib-jsmath.',
RemovedInSphinx40Warning)
app.add_config_value('jsmath_path', '', False)
app.connect('env-check-consistency', install_jsmath)
return {'version': sphinx.__display_version__, 'parallel_read_safe': True}
app.setup_extension('sphinxcontrib.jsmath')
return {
'version': sphinx.__display_version__,
'parallel_read_safe': True,
'parallel_write_safe': True,
}

View File

@ -9,8 +9,10 @@ from sphinx import addnodes
sys.path.append(os.path.abspath('.'))
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.jsmath', 'sphinx.ext.todo',
'sphinx.ext.coverage', 'sphinx.ext.extlinks']
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.extlinks']
jsmath_path = 'dummy.js'

View File

@ -1366,7 +1366,7 @@ def test_html_math_renderer_is_imgmath(app, status, warning):
@pytest.mark.sphinx('html', testroot='basic',
confoverrides={'extensions': ['sphinx.ext.jsmath',
confoverrides={'extensions': ['sphinxcontrib.jsmath',
'sphinx.ext.imgmath']})
def test_html_math_renderer_is_duplicated(make_app, app_params):
try:
@ -1387,7 +1387,7 @@ def test_html_math_renderer_is_duplicated2(app, status, warning):
@pytest.mark.sphinx('html', testroot='basic',
confoverrides={'extensions': ['sphinx.ext.jsmath',
confoverrides={'extensions': ['sphinxcontrib.jsmath',
'sphinx.ext.imgmath'],
'html_math_renderer': 'imgmath'})
def test_html_math_renderer_is_chosen(app, status, warning):
@ -1395,7 +1395,7 @@ def test_html_math_renderer_is_chosen(app, status, warning):
@pytest.mark.sphinx('html', testroot='basic',
confoverrides={'extensions': ['sphinx.ext.jsmath',
confoverrides={'extensions': ['sphinxcontrib.jsmath',
'sphinx.ext.mathjax'],
'html_math_renderer': 'imgmath'})
def test_html_math_renderer_is_mismatched(make_app, app_params):

View File

@ -8,7 +8,6 @@
:license: BSD, see LICENSE for details.
"""
import errno
import re
import subprocess
import warnings
@ -29,28 +28,6 @@ def has_binary(binary):
return True
@pytest.mark.sphinx(
'html', testroot='ext-math',
confoverrides = {'extensions': ['sphinx.ext.jsmath'], 'jsmath_path': 'dummy.js'})
def test_jsmath(app, status, warning):
app.builder.build_all()
content = (app.outdir / 'math.html').text()
assert '<div class="math notranslate nohighlight">\na^2 + b^2 = c^2</div>' in content
assert ('<div class="math notranslate nohighlight">\n\\begin{split}a + 1 &lt; '
'b\\end{split}</div>' in content)
assert ('<span class="eqno">(1)<a class="headerlink" href="#equation-foo" '
'title="Permalink to this equation">\xb6</a></span>'
'<div class="math notranslate nohighlight" id="equation-foo">'
'\ne^{i\\pi} = 1</div>' in content)
assert ('<span class="eqno">(2)<a class="headerlink" href="#equation-math-0" '
'title="Permalink to this equation">\xb6</a></span>'
'<div class="math notranslate nohighlight" id="equation-math-0">\n'
'e^{ix} = \\cos x + i\\sin x</div>' in content)
assert '<div class="math notranslate nohighlight">\nn \\in \\mathbb N</div>' in content
assert '<div class="math notranslate nohighlight">\na + 1 &lt; b</div>' in content
@pytest.mark.skipif(not has_binary('dvipng'),
reason='Requires dvipng" binary')
@pytest.mark.sphinx('html', testroot='ext-math-simple',
@ -193,23 +170,6 @@ def test_mathjax_numfig_html(app, status, warning):
assert html in content
@pytest.mark.sphinx('html', testroot='ext-math',
confoverrides={'extensions': ['sphinx.ext.jsmath'],
'jsmath_path': 'dummy.js',
'numfig': True,
'math_numfig': True})
def test_jsmath_numfig_html(app, status, warning):
app.builder.build_all()
content = (app.outdir / 'math.html').text()
html = '<span class="eqno">(1.2)<a class="headerlink" href="#equation-math-0"'
assert html in content
html = ('<p>Referencing equation <a class="reference internal" '
'href="#equation-foo">(1.1)</a> and '
'<a class="reference internal" href="#equation-foo">(1.1)</a>.</p>')
assert html in content
@pytest.mark.sphinx('html', testroot='ext-math',
confoverrides={'extensions': ['sphinx.ext.imgmath'],
'numfig': True,
@ -271,13 +231,3 @@ def test_mathjax_is_not_installed_if_no_equations(app, status, warning):
content = (app.outdir / 'index.html').text()
assert 'MathJax.js' not in content
@pytest.mark.sphinx('html', testroot='basic',
confoverrides={'extensions': ['sphinx.ext.jsmath'],
'jsmath_path': 'jsmath.js'})
def test_jsmath_is_not_installed_if_no_equations(app, status, warning):
app.builder.build_all()
content = (app.outdir / 'index.html').text()
assert 'jsmath.js' not in content