+ {editorType === 'text' ? (
+
) : (
)}
diff --git a/src/components/TextResponse/index.scss b/src/components/TextResponse/index.scss
index 04e4bc69..d8d24011 100644
--- a/src/components/TextResponse/index.scss
+++ b/src/components/TextResponse/index.scss
@@ -1,4 +1,4 @@
-.pre-like-textarea {
+.div-textarea {
white-space: pre-wrap;
word-wrap: break-word;
word-break: break-all;
diff --git a/src/data/services/lms/types/blockInfo.ts b/src/data/services/lms/types/blockInfo.ts
index 02810574..3c511aa7 100644
--- a/src/data/services/lms/types/blockInfo.ts
+++ b/src/data/services/lms/types/blockInfo.ts
@@ -16,7 +16,7 @@ export interface TextResponseConfig {
enabled: boolean,
optional: boolean,
editorType: 'text' | 'tinymce',
- allowLatexPreviews: boolean,
+ allowLatexPreview: boolean,
}
export interface FileResponseConfig {
diff --git a/src/setupTest.js b/src/setupTest.js
index 7f11ec8f..944db905 100644
--- a/src/setupTest.js
+++ b/src/setupTest.js
@@ -108,3 +108,10 @@ Object.defineProperty(window, 'matchMedia', {
dispatchEvent: jest.fn(),
})),
});
+
+global.MathJax = {
+ Hub: {
+ Queue: jest.fn(),
+ Config: jest.fn(),
+ },
+};
diff --git a/src/views/SubmissionView/TextResponseEditor/LaTexPreview.jsx b/src/views/SubmissionView/TextResponseEditor/LaTexPreview.jsx
new file mode 100644
index 00000000..e3bbd7a7
--- /dev/null
+++ b/src/views/SubmissionView/TextResponseEditor/LaTexPreview.jsx
@@ -0,0 +1,22 @@
+import React, { useEffect } from 'react';
+import PropTypes from 'prop-types';
+
+const LatexPreview = ({ latexValue }) => {
+ const latexPreviewEl = React.useRef(null);
+
+ useEffect(() => {
+ MathJax.Hub.Queue(['Typeset', MathJax.Hub, latexPreviewEl.current]);
+ }, [latexValue]);
+
+ return (
+
+ );
+};
+
+LatexPreview.propTypes = {
+ latexValue: PropTypes.string.isRequired,
+};
+
+export default LatexPreview;
diff --git a/src/views/SubmissionView/TextResponseEditor/index.jsx b/src/views/SubmissionView/TextResponseEditor/index.jsx
index 8e480047..d86e9404 100644
--- a/src/views/SubmissionView/TextResponseEditor/index.jsx
+++ b/src/views/SubmissionView/TextResponseEditor/index.jsx
@@ -1,10 +1,14 @@
-import React from 'react';
+import React, { useCallback } from 'react';
import PropTypes from 'prop-types';
+import { Button } from '@edx/paragon';
+import { useIntl } from '@edx/frontend-platform/i18n';
import { useSubmissionConfig } from 'hooks/app';
import TextEditor from './TextEditor';
import RichTextEditor from './RichTextEditor';
+import LatexPreview from './LaTexPreview';
+import messages from './messages';
const TextResponseEditor = ({ value, onChange }) => {
const { textResponseConfig } = useSubmissionConfig();
@@ -12,7 +16,15 @@ const TextResponseEditor = ({ value, onChange }) => {
optional,
enabled,
editorType,
+ allowLatexPreview,
} = textResponseConfig || {};
+ const { formatMessage } = useIntl();
+
+ const [latexValue, setLatexValue] = React.useState('');
+
+ const previewLaTex = useCallback(() => {
+ setLatexValue(value);
+ }, [value]);
if (!enabled) {
return null;
@@ -23,6 +35,14 @@ const TextResponseEditor = ({ value, onChange }) => {
return (
+ {
+ allowLatexPreview && (
+
+
+
+
+ )
+ }
);
};
diff --git a/src/views/SubmissionView/TextResponseEditor/messages.js b/src/views/SubmissionView/TextResponseEditor/messages.js
index 898e7c09..e3752524 100644
--- a/src/views/SubmissionView/TextResponseEditor/messages.js
+++ b/src/views/SubmissionView/TextResponseEditor/messages.js
@@ -21,6 +21,11 @@ const messages = defineMessages({
description: 'Label for the optional indicator',
id: 'frontend-app-ora.TextResponse.optional',
},
+ previewLaTexButton: {
+ defaultMessage: 'Preview in LaTeX',
+ description: 'Label for the preview LaTeX button',
+ id: 'frontend-app-ora.TextResponse.previewLaTexButton',
+ },
});
export default messages;