Fix #2226: Math is not HTML-encoded when :nowrap: is given (jsmath, mathjax)

This commit is contained in:
Takeshi KOMIYA
2016-01-10 02:20:39 +09:00
parent 053d7806fe
commit c8c6dc1fe9
5 changed files with 25 additions and 4 deletions

View File

@@ -46,6 +46,7 @@ Bugs fixed
* #2198,#2205: ``make gettext`` generate broken msgid for definition lists.
* #2062: Escape characters in doctests are treated incorrectly with Python 2.
* #2225: Fix if the option does not begin with dash, linking is not performed
* #2226: Fix math is not HTML-encoded when :nowrap: is given (jsmath, mathjax)
Release 1.3.3 (released Dec 2, 2015)
====================================

View File

@@ -26,7 +26,7 @@ def html_visit_math(self, node):
def html_visit_displaymath(self, node):
if node['nowrap']:
self.body.append(self.starttag(node, 'div', CLASS='math'))
self.body.append(node['latex'])
self.body.append(self.encode(node['latex']))
self.body.append('</div>')
raise nodes.SkipNode
for i, part in enumerate(node['latex'].split('\n\n')):

View File

@@ -30,7 +30,7 @@ def html_visit_displaymath(self, node):
self.body.append(self.starttag(node, 'div', CLASS='math'))
if node['nowrap']:
self.body.append(self.builder.config.mathjax_display[0] +
node['latex'] +
self.encode(node['latex']) +
self.builder.config.mathjax_display[1])
self.body.append('</div>')
raise nodes.SkipNode

View File

@@ -7,7 +7,7 @@ This is inline math: :math:`a^2 + b^2 = c^2`.
.. math::
a^2 + b^2 = c^2
a + 1 < b
.. math::
:label: foo
@@ -23,4 +23,9 @@ This is inline math: :math:`a^2 + b^2 = c^2`.
n \in \mathbb N
.. math::
:nowrap:
a + 1 < b
Referencing equation :eq:`foo`.

View File

@@ -16,7 +16,7 @@ from six import PY3, iteritems
from six.moves import html_entities
from sphinx import __display_version__
from util import remove_unicode_literals, gen_with_app
from util import remove_unicode_literals, gen_with_app, with_app
from etree13 import ElementTree as ET
@@ -929,3 +929,18 @@ def test_numfig_with_secnum_depth(app, status, warning):
for xpath, check, be_found in paths:
yield check_xpath, etree, fname, xpath, check, be_found
@with_app(buildername='html')
def test_jsmath(app, status, warning):
app.builder.build_all()
content = (app.outdir / 'math.html').text()
assert '<div class="math">\na^2 + b^2 = c^2</div>' in content
assert '<div class="math">\n\\begin{split}a + 1 &lt; b\\end{split}</div>' in content
assert ('<span class="eqno">(1)</span><div class="math" id="equation-foo">\n'
'e^{i\\pi} = 1</div>' in content)
assert ('<span class="eqno">(2)</span><div class="math">\n'
'e^{ix} = \\cos x + i\\sin x</div>' in content)
assert '<div class="math">\nn \\in \\mathbb N</div>' in content
assert '<div class="math">\na + 1 &lt; b</div>' in content