diff --git a/freetextresponse/templates/freetextresponse_view.html b/freetextresponse/templates/freetextresponse_view.html index 07b75802..2ddf367d 100644 --- a/freetextresponse/templates/freetextresponse_view.html +++ b/freetextresponse/templates/freetextresponse_view.html @@ -2,7 +2,7 @@

{{ display_name }}

{{ problem_progress }}
-

{{ prompt }}

+

{{ prompt|safe }}

{{ word_count_message }}
diff --git a/freetextresponse/tests.py b/freetextresponse/tests.py index c2efbbe7..7c506344 100644 --- a/freetextresponse/tests.py +++ b/freetextresponse/tests.py @@ -12,6 +12,8 @@ from xblock.field_data import DictFieldData from xblock.validation import ValidationMessage +from django.template.loader import get_template + from .freetextresponse import Credit from .freetextresponse import FreeTextResponse @@ -167,6 +169,28 @@ def test_student_view(self): student_view_html ) + def test_build_fragment_prompt_html(self): + """ + Checks that build_fragment allows html in the prompt variable + + if the 'safe' filter is not used then the django + template pipeline returns html tags like, + '<p>Please enter your response here</p>' + """ + studio_settings_prompt = "

Please enter your response here

" + context = { + 'prompt': studio_settings_prompt, + } + template = get_template('freetextresponse_view.html') + fragment = self.xblock.build_fragment( + template, + context, + initialize_js_func='FreeTextResponseView', + additional_css=[], + additional_js=[], + ) + self.assertIn(studio_settings_prompt, fragment.content) + def test_max_score(self): """ Tests max_score function