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', -> ...@@ -10,8 +10,11 @@ describe 'MarkdownEditingDescriptor', ->
it 'recognizes x as a selection if there is non-whitespace after x', -> 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') 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') expect(revisedSelection).toEqual('( ) a\n(x) b\n( ) c\n( ) x \n( ) d\n(x) e\n')
it 'removes multiple newlines', -> it 'recognizes x as a selection if it is first non whitespace and has whitespace with other non-whitespace', ->
revisedSelection = MarkdownEditingDescriptor.insertMultipleChoice('a\nx b\n\n\nc') 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') expect(revisedSelection).toEqual('( ) a\n(x) b\n( ) c\n')
describe 'insertCheckboxChoice', -> describe 'insertCheckboxChoice', ->
......
...@@ -131,23 +131,17 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor ...@@ -131,23 +131,17 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
@insertGenericChoice: (selectedText, choiceStart, choiceEnd, template) -> @insertGenericChoice: (selectedText, choiceStart, choiceEnd, template) ->
if selectedText.length > 0 if selectedText.length > 0
# Replace adjacent newlines with a single newline # Replace adjacent newlines with a single newline, strip any trailing newline
cleanSelectedText = selectedText.replace(/\n+/g, '\n') cleanSelectedText = selectedText.replace(/\n+/g, '\n').replace(/\n$/,'')
lines = cleanSelectedText.split('\n') lines = cleanSelectedText.split('\n')
revisedLines = '' revisedLines = ''
for line in lines for line in lines
revisedLines += choiceStart revisedLines += choiceStart
# This is looking for a x before text to mark as selected. # a stand alone x before other text implies that this option is "correct"
if /x\s/i.test(line) if /^\s*x\s*(\S)/i.test(line)
# Remove the x and any initial whitespace # Remove the x and any initial whitespace as long as there's more text on the line
lineWithoutX = line.replace(/^(\s+)?x/i, '') line = line.replace(/^\s*x\s*(\S)/i, '$1')
# Check if any non-whitespace chars remain on the line revisedLines += 'x'
if not /^\s+$/.test(lineWithoutX)
# Remove initial whitespace, x, and space immediately after
line = line.replace(/^(\s+)?x\s/i, '')
revisedLines += 'x'
else
revisedLines += ' '
else else
revisedLines += ' ' revisedLines += ' '
revisedLines += choiceEnd + ' ' + line + '\n' revisedLines += choiceEnd + ' ' + line + '\n'
......
...@@ -3,8 +3,8 @@ metadata: ...@@ -3,8 +3,8 @@ metadata:
display_name: Multiple Choice display_name: Multiple Choice
rerandomize: never rerandomize: never
showanswer: always showanswer: always
markdown: " markdown:
A multiple choice problem presents radio buttons for student input. Students can only select a single "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 option presented. Multiple Choice questions have been the subject of many areas of research due to the early
invention and adoption of bubble sheets. invention and adoption of bubble sheets.
......
...@@ -3,8 +3,8 @@ metadata: ...@@ -3,8 +3,8 @@ metadata:
display_name: Numerical Response display_name: Numerical Response
rerandomize: never rerandomize: never
showanswer: always showanswer: always
markdown: " markdown:
A numerical response problem accepts a line of text input from the "A numerical response problem accepts a line of text input from the
student, and evaluates the input for correctness based on its student, and evaluates the input for correctness based on its
numerical value. numerical value.
......
...@@ -3,8 +3,8 @@ metadata: ...@@ -3,8 +3,8 @@ metadata:
display_name: Option Response display_name: Option Response
rerandomize: never rerandomize: never
showanswer: always showanswer: always
markdown: " markdown:
OptionResponse gives a limited set of options for students to respond with, and presents those options "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 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. with options from which to recognize the correct answer.
......
...@@ -4,8 +4,8 @@ metadata: ...@@ -4,8 +4,8 @@ metadata:
rerandomize: never rerandomize: never
showanswer: always showanswer: always
# Note, the extra newlines are needed to make the yaml parser add blank lines instead of folding # Note, the extra newlines are needed to make the yaml parser add blank lines instead of folding
markdown: " markdown:
A string response problem accepts a line of text input from the "A string response problem accepts a line of text input from the
student, and evaluates the input for correctness based on an expected student, and evaluates the input for correctness based on an expected
answer within each input box. 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