Skip to content

Commit 7520d25

Browse files
committed
fix(mathjax): restore dollar delimiters
1 parent bea1245 commit 7520d25

10 files changed

Lines changed: 38 additions & 1 deletion

File tree

cms/djangoapps/pipeline_js/js/xmodule.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ define(
1919
window.MathJax = {
2020
tex: {
2121
inlineMath: [
22+
['$', '$'],
2223
['\\(', '\\)'],
2324
['[mathjaxinline]', '[/mathjaxinline]']
2425
],
2526
displayMath: [
27+
['$$', '$$'],
2628
['\\[', '\\]'],
2729
['[mathjax]', '[/mathjax]']
2830
],

cms/static/cms/js/require-config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@
5050
window.MathJax = {
5151
tex: {
5252
inlineMath: [
53+
['$', '$'],
5354
['\\(', '\\)'],
5455
['[mathjaxinline]', '[/mathjaxinline]']
5556
],
5657
displayMath: [
58+
['$$', '$$'],
5759
['\\[', '\\]'],
5860
['[mathjax]', '[/mathjax]']
5961
],

cms/static/cms/js/spec/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
window.MathJax = {
2424
tex: {
2525
inlineMath: [
26+
['$', '$'],
2627
['\\(', '\\)'],
2728
['[mathjaxinline]', '[/mathjaxinline]']
2829
],
2930
displayMath: [
31+
['$$', '$$'],
3032
['\\[', '\\]'],
3133
['[mathjax]', '[/mathjax]']
3234
],

cms/static/cms/js/spec/main_squire.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
window.MathJax = {
1010
tex: {
1111
inlineMath: [
12+
['$', '$'],
1213
['\\(', '\\)'],
1314
['[mathjaxinline]', '[/mathjaxinline]']
1415
],
1516
displayMath: [
17+
['$$', '$$'],
1618
['\\[', '\\]'],
1719
['[mathjax]', '[/mathjax]']
1820
],

common/static/common/js/discussion/mathjax_include.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ if (typeof MathJax === 'undefined') {
22
window.MathJax = {
33
tex: {
44
inlineMath: [
5+
['$', '$'],
56
['\\(', '\\)'],
67
['[mathjaxinline]', '[/mathjaxinline]']
78
],
89
displayMath: [
10+
['$$', '$$'],
911
['\\[', '\\]'],
1012
['[mathjax]', '[/mathjax]']
1113
],

common/templates/mathjax_include.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@
4343
window.MathJax = {
4444
tex: {
4545
inlineMath: [
46+
['$', '$'],
4647
["\\(","\\)"],
4748
['[mathjaxinline]','[/mathjaxinline]']
4849
],
4950
displayMath: [
51+
['$$', '$$'],
5052
["\\[","\\]"],
5153
['[mathjax]','[/mathjax]']
5254
],

common/templates/xblock_v2/xblock_iframe.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,12 @@
126126
window.MathJax = {
127127
tex: {
128128
inlineMath: [
129+
['$', '$'],
129130
["\\(","\\)"],
130131
['[mathjaxinline]','[/mathjaxinline]']
131132
],
132133
displayMath: [
134+
['$$', '$$'],
133135
["\\[","\\]"],
134136
['[mathjax]','[/mathjax]']
135137
],

lms/djangoapps/courseware/tests/test_views.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2811,6 +2811,8 @@ def setUp(self):
28112811
display_name='Vertical with No Mathjax HTML',
28122812
)
28132813
MATHJAX_TAG_PAIRS = [
2814+
("$", "$"),
2815+
("$$", "$$"),
28142816
(r"\(", r"\)"),
28152817
(r"\[", r"\]"),
28162818
("[mathjaxinline]", "[/mathjaxinline]"),
@@ -2831,6 +2833,12 @@ def setUp(self):
28312833
display_name="HTML Without Mathjax",
28322834
data="<p>I talk about mathjax, but I have no actual Math!</p>",
28332835
)
2836+
self.html_with_lone_dollar = BlockFactory.create(
2837+
category='html',
2838+
parent_location=self.no_math_vertical.location,
2839+
display_name="HTML With Lone Dollar",
2840+
data="<p>Price: $5</p>",
2841+
)
28342842

28352843
self.course_key = self.course.id
28362844
self.user = UserFactory(username='staff_user', profile__country='AX', is_staff=True)
@@ -2849,6 +2857,8 @@ def test_mathjax_detection(self):
28492857
response = self.client.get(url)
28502858
assert response.status_code == 200
28512859
assert b"window.MathJax" in response.content
2860+
assert b"['$', '$']" in response.content
2861+
assert b"['$$', '$$']" in response.content
28522862

28532863
# Check the one without Math...
28542864
url = reverse("render_xblock", kwargs={
@@ -2858,6 +2868,14 @@ def test_mathjax_detection(self):
28582868
assert response.status_code == 200
28592869
assert b"window.MathJax" not in response.content
28602870

2871+
# Check lone dollar sign isn't mistaken for MathJax
2872+
url = reverse("render_xblock", kwargs={
2873+
'usage_key_string': str(self.html_with_lone_dollar.location)
2874+
})
2875+
response = self.client.get(url)
2876+
assert response.status_code == 200
2877+
assert b"window.MathJax" not in response.content
2878+
28612879
# The containing vertical should still return MathJax (for now)
28622880
url = reverse("render_xblock", kwargs={
28632881
'usage_key_string': str(self.no_math_vertical.location)

lms/djangoapps/courseware/views/views.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,8 @@ def has_mathjax_content(self):
18021802
# The following pairs are used to mark Mathjax syntax in XBlocks. There
18031803
# are other options for the wiki, but we don't worry about those here.
18041804
MATHJAX_TAG_PAIRS = [
1805+
("$", "$"),
1806+
("$$", "$$"),
18051807
(r"\(", r"\)"),
18061808
(r"\[", r"\]"),
18071809
("[mathjaxinline]", "[/mathjaxinline]"),
@@ -1810,7 +1812,8 @@ def has_mathjax_content(self):
18101812
content = self.fragment.body_html()
18111813
for (start_tag, end_tag) in MATHJAX_TAG_PAIRS:
18121814
if start_tag in content and end_tag in content:
1813-
return True
1815+
if start_tag != end_tag or content.count(start_tag) >= 2:
1816+
return True
18141817

18151818
return False
18161819

lms/static/lms/js/spec/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
window.MathJax = {
1010
tex: {
1111
inlineMath: [
12+
['$', '$'],
1213
['\\(', '\\)'],
1314
['[mathjaxinline]', '[/mathjaxinline]']
1415
],
1516
displayMath: [
17+
['$$', '$$'],
1618
['\\[', '\\]'],
1719
['[mathjax]', '[/mathjax]']
1820
],

0 commit comments

Comments
 (0)