Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sphinx-doc/sphinx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2019-01-04 14:16:18 +0300
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2019-01-13 08:07:12 +0300
commit20bf74c63789bcf8daf9b7630c1f22f455533449 (patch)
tree15e9abbfd2d493c67b0a58bfe703c40b1c83ea28
parent3a6989d274fd2ebdbfe25590731e41f9f9423183 (diff)
Separate jsmath to sphinxcontrib package
-rw-r--r--CHANGES3
-rw-r--r--doc/extdev/index.rst5
-rw-r--r--setup.py1
-rw-r--r--sphinx/ext/jsmath.py81
-rw-r--r--tests/roots/test-root/conf.py6
-rw-r--r--tests/test_build_html.py6
-rw-r--r--tests/test_ext_math.py50
7 files changed, 32 insertions, 120 deletions
diff --git a/CHANGES b/CHANGES
index 48c4fae5b..89bef3c3d 100644
--- a/CHANGES
+++ b/CHANGES
@@ -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
--------------------
diff --git a/doc/extdev/index.rst b/doc/extdev/index.rst
index ddc8c09ee..8a22b1f7a 100644
--- a/doc/extdev/index.rst
+++ b/doc/extdev/index.rst
@@ -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
diff --git a/setup.py b/setup.py
index c8d24c6f0..be4097b70 100644
--- a/setup.py
+++ b/setup.py
@@ -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',
diff --git a/sphinx/ext/jsmath.py b/sphinx/ext/jsmath.py
index 84e0f9037..47e1b1836 100644
--- a/sphinx/ext/jsmath.py
+++ b/sphinx/ext/jsmath.py
@@ -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.setup_extension('sphinxcontrib.jsmath')
- app.add_config_value('jsmath_path', '', False)
- app.connect('env-check-consistency', install_jsmath)
- return {'version': sphinx.__display_version__, 'parallel_read_safe': True}
+ return {
+ 'version': sphinx.__display_version__,
+ 'parallel_read_safe': True,
+ 'parallel_write_safe': True,
+ }
diff --git a/tests/roots/test-root/conf.py b/tests/roots/test-root/conf.py
index 23e5de4f5..a8e317304 100644
--- a/tests/roots/test-root/conf.py
+++ b/tests/roots/test-root/conf.py
@@ -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'
diff --git a/tests/test_build_html.py b/tests/test_build_html.py
index 8b237ad6d..70fc2e32b 100644
--- a/tests/test_build_html.py
+++ b/tests/test_build_html.py
@@ -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):
diff --git a/tests/test_ext_math.py b/tests/test_ext_math.py
index 5cf9262c1..7fbfd1477 100644
--- a/tests/test_ext_math.py
+++ b/tests/test_ext_math.py
@@ -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',
@@ -194,23 +171,6 @@ def test_mathjax_numfig_html(app, status, warning):
@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,
'numfig_secnum_depth': 0,
@@ -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