Commit 2caa5a51 by cahrens

Merge branch 'feature/cas/speed-editor' of github.com:MITx/mitx into feature/cas/speed-editor

parents b3d168b6 603c6ce2
......@@ -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', ->
......
......@@ -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'
......
......@@ -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.
......
......@@ -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.
......
......@@ -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.
......
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment