diff --git a/common/lib/xmodule/xmodule/js/spec/problem/edit_spec.coffee b/common/lib/xmodule/xmodule/js/spec/problem/edit_spec.coffee index 8d75b1822d..25f862d133 100644 --- a/common/lib/xmodule/xmodule/js/spec/problem/edit_spec.coffee +++ b/common/lib/xmodule/xmodule/js/spec/problem/edit_spec.coffee @@ -10,8 +10,11 @@ describe 'MarkdownEditingDescriptor', -> it 'recognizes x as a selection if there is non-whitespace after x', -> revisedSelection = MarkdownEditingDescriptor.insertMultipleChoice('a\nx b\nc\nx \nd\n x e') expect(revisedSelection).toEqual('( ) a\n(x) b\n( ) c\n( ) x \n( ) d\n(x) e\n') - it 'removes multiple newlines', -> - revisedSelection = MarkdownEditingDescriptor.insertMultipleChoice('a\nx b\n\n\nc') + it 'recognizes x as a selection if it is first non whitespace and has whitespace with other non-whitespace', -> + revisedSelection = MarkdownEditingDescriptor.insertMultipleChoice(' x correct\n x \nex post facto\nb x c\nx c') + expect(revisedSelection).toEqual('(x) correct\n( ) x \n( ) ex post facto\n( ) b x c\n(x) c\n') + it 'removes multiple newlines but not last one', -> + revisedSelection = MarkdownEditingDescriptor.insertMultipleChoice('a\nx b\n\n\nc\n') expect(revisedSelection).toEqual('( ) a\n(x) b\n( ) c\n') describe 'insertCheckboxChoice', -> diff --git a/common/lib/xmodule/xmodule/js/src/problem/edit.coffee b/common/lib/xmodule/xmodule/js/src/problem/edit.coffee index a721859035..e66bc708f2 100644 --- a/common/lib/xmodule/xmodule/js/src/problem/edit.coffee +++ b/common/lib/xmodule/xmodule/js/src/problem/edit.coffee @@ -131,23 +131,17 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor @insertGenericChoice: (selectedText, choiceStart, choiceEnd, template) -> if selectedText.length > 0 - # Replace adjacent newlines with a single newline - cleanSelectedText = selectedText.replace(/\n+/g, '\n') + # Replace adjacent newlines with a single newline, strip any trailing newline + cleanSelectedText = selectedText.replace(/\n+/g, '\n').replace(/\n$/,'') lines = cleanSelectedText.split('\n') revisedLines = '' for line in lines revisedLines += choiceStart - # This is looking for a x before text to mark as selected. - if /x\s/i.test(line) - # Remove the x and any initial whitespace - lineWithoutX = line.replace(/^(\s+)?x/i, '') - # Check if any non-whitespace chars remain on the line - if not /^\s+$/.test(lineWithoutX) - # Remove initial whitespace, x, and space immediately after - line = line.replace(/^(\s+)?x\s/i, '') - revisedLines += 'x' - else - revisedLines += ' ' + # a stand alone x before other text implies that this option is "correct" + if /^\s*x\s*(\S)/i.test(line) + # Remove the x and any initial whitespace as long as there's more text on the line + line = line.replace(/^\s*x\s*(\S)/i, '$1') + revisedLines += 'x' else revisedLines += ' ' revisedLines += choiceEnd + ' ' + line + '\n' diff --git a/common/lib/xmodule/xmodule/templates/problem/multiplechoice.yaml b/common/lib/xmodule/xmodule/templates/problem/multiplechoice.yaml index 1e9ccad040..b8624987ce 100644 --- a/common/lib/xmodule/xmodule/templates/problem/multiplechoice.yaml +++ b/common/lib/xmodule/xmodule/templates/problem/multiplechoice.yaml @@ -3,8 +3,8 @@ metadata: display_name: Multiple Choice rerandomize: never showanswer: always - markdown: " - A multiple choice problem presents radio buttons for student input. Students can only select a single + markdown: + "A multiple choice problem presents radio buttons for student input. Students can only select a single option presented. Multiple Choice questions have been the subject of many areas of research due to the early invention and adoption of bubble sheets. diff --git a/common/lib/xmodule/xmodule/templates/problem/numericalresponse.yaml b/common/lib/xmodule/xmodule/templates/problem/numericalresponse.yaml index 614cf66d6f..b0f5e92691 100644 --- a/common/lib/xmodule/xmodule/templates/problem/numericalresponse.yaml +++ b/common/lib/xmodule/xmodule/templates/problem/numericalresponse.yaml @@ -3,8 +3,8 @@ metadata: display_name: Numerical Response rerandomize: never showanswer: always - markdown: " - A numerical response problem accepts a line of text input from the + markdown: + "A numerical response problem accepts a line of text input from the student, and evaluates the input for correctness based on its numerical value. diff --git a/common/lib/xmodule/xmodule/templates/problem/optionresponse.yaml b/common/lib/xmodule/xmodule/templates/problem/optionresponse.yaml index 5e07151e50..7ad2e8960c 100644 --- a/common/lib/xmodule/xmodule/templates/problem/optionresponse.yaml +++ b/common/lib/xmodule/xmodule/templates/problem/optionresponse.yaml @@ -3,8 +3,8 @@ metadata: display_name: Option Response rerandomize: never showanswer: always - markdown: " - OptionResponse gives a limited set of options for students to respond with, and presents those options + markdown: + "OptionResponse gives a limited set of options for students to respond with, and presents those options in a format that encourages them to search for a specific answer rather than being immediately presented with options from which to recognize the correct answer. diff --git a/common/lib/xmodule/xmodule/templates/problem/string_response.yaml b/common/lib/xmodule/xmodule/templates/problem/string_response.yaml index adeff4bb58..933c8083ed 100644 --- a/common/lib/xmodule/xmodule/templates/problem/string_response.yaml +++ b/common/lib/xmodule/xmodule/templates/problem/string_response.yaml @@ -4,8 +4,8 @@ metadata: rerandomize: never showanswer: always # Note, the extra newlines are needed to make the yaml parser add blank lines instead of folding - markdown: " - A string response problem accepts a line of text input from the + markdown: + "A string response problem accepts a line of text input from the student, and evaluates the input for correctness based on an expected answer within each input box.