Skip to content

Commit e3dfdb9

Browse files
committed
Fix MathJax rendering
This PR deals with the following rendering issue: * Multiple dollar signs in MathJax expression lead to mistaken MathJax rendering - Thread ID: 1a78652b351779b476903c9966ef2c455fc244f2 - Test task URL: https://data-labeling-test.khanacademy.org/projects/314/data?tab=624&page=1&task=108725 * `/begin{}` and `\end{}` always trigger rendering dispite Marker not exists. This lead to bad selection threads. - Thread ID: 032e483505cd43f2bee52184b4dbec57db559681 - Test task URL: https://data-labeling-test.khanacademy.org/projects/314/data?tab=624&page=1&task=108659 This PR suppress that by adding `ignoreClass`, as well as removing unnecessary `no display` tags which also simplifies the rendering. Issue: https://khanacademy.atlassian.net/browse/DI-1514 Test Plan: Open the above threads and confirm that the MathJax rendering behaves correctly.
1 parent e633083 commit e3dfdb9

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/examples/rich_text_table/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"data": {
4-
"text": "[[\"Asking question?<a href=\\\"javascript:alert('pwned')\\\">click</a>\", \"Answer! Look at some LaTex\\n\\n\\\\(\\\\dfrac{1}{2k - 6} = \\\\dfrac{1}{3}\\\\) and \\\\(\\\\dfrac{1.5}{2k - 6} = \\\\dfrac{1}{3}\\\\)\\n\\n\"], [\"Asking more question in LaTex?\\n\\n\\\\[\\n\\\\begin{array}{r}\\n 3.050 \\\\\\\\\\n- 0.338 \\\\\\\\\\n\\\\hline\\n\\\\end{array}\\n\\\\]\\n\\n\", \"More LaTex!\\n\\n\\\\(\\\\dfrac{3}{2k - 6} = \\\\dfrac{1}{3}\\\\)\\n\\n\"]]"
4+
"text": "[[\"Asking question?<a href=\\\"javascript:alert('pwned')\\\">click</a>\", \"Answer! Look at some LaTex\\n\\n\\\\(\\\\dfrac{1}{2k - 6} = \\\\dfrac{1}{3}\\\\) and \\\\(\\\\dfrac{1.5}{2k - 6} = \\\\dfrac{1}{3}\\\\)\\n\\n\"], [\"Asking more question in LaTex?\\n\\n\\\\[\\n\\\\begin{array}{r}\\n 3.050 \\\\\\\\\\n- 0.338 \\\\\\\\\\n\\\\hline\\n\\\\end{array}\\n\\\\]\\n\\n\", \"More LaTex! $4 to $5. \\n\\n\\\\(\\\\dfrac{3}{2k - 6} = \\\\dfrac{1}{3}\\\\)\\n\\n\"], [\"Following is not Math\", \"$4 to $5\"]]"
55
},
66
"predictions": [
77
{

src/tags/object/RichText/table.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ import { HtxRichText } from './view';
3131
// We use a different marker than what is used in Khanmigo.
3232
const MATHJAX_MARKER = '$';
3333

34+
// A class that stop rendering MathJax expressions
35+
const NO_MATHJAX_CLASS = 'tex2jax_ignore';
36+
3437
// Extract math from conversation, alternate between math and non-math
3538
// Khanmigo uses "\(.*?\)" and "\[.*?\]" as the marker for math
3639
// For example, "What is \(2 + 2\)?" will split into ["What is ", "2 + 2", "?"]
@@ -76,14 +79,14 @@ const renderTableValue = (val) => {
7679
convoAndMathList.map((convo, i) => {
7780
if (i % 2 === 0) {
7881
// Non math
79-
return <span key={`eq=${i}`}>{convo}</span>;
82+
return <span key={`eq=${i}`} className={NO_MATHJAX_CLASS}>{convo}</span>;
8083
} else {
8184
// So for Math, we need to create a span as we want 2 piece of dom:
8285
// 1. The hidden raw MathJax expression, to allow slot Label to work
8386
// 2. A marked MathJax expression that allows <MathJax/> to render
8487
return (
8588
<span key={`eq-${i}`}>
86-
<span style={{ 'display': 'none' }}>{'\\(' + convo + '\\)'}</span>
89+
<span style={{ 'display': 'none' }} className={NO_MATHJAX_CLASS}>{'\\(' + convo + '\\)'}</span>
8790
<span data-skip-select='1'>{MATHJAX_MARKER + convo + MATHJAX_MARKER}</span>
8891
</span>
8992
);
@@ -99,7 +102,7 @@ const renderTableValue = (val) => {
99102
);
100103
hasMath = true;
101104
} else if (question) {
102-
mathQuestionComponent = <div className={questionItemClass}>{question}</div>;
105+
mathQuestionComponent = <div className={`${questionItemClass} ${NO_MATHJAX_CLASS}`}>{question}</div>;
103106
}
104107
if (mathAnswers.length > 1) {
105108
mathAnswerComponent = (
@@ -109,7 +112,7 @@ const renderTableValue = (val) => {
109112
);
110113
hasMath = true;
111114
} else if (answer){
112-
mathAnswerComponent = <div className={answerItemClass}>{answer}</div>;
115+
mathAnswerComponent = <div className={`${answerItemClass} ${NO_MATHJAX_CLASS}`}>{answer}</div>;
113116
}
114117

115118
return (
@@ -125,6 +128,9 @@ const renderTableValue = (val) => {
125128
tex: {
126129
inlineMath: [[MATHJAX_MARKER, MATHJAX_MARKER]],
127130
},
131+
options: {
132+
ignoreHtmlClass: NO_MATHJAX_CLASS,
133+
},
128134
};
129135

130136
return (

0 commit comments

Comments
 (0)