From 8245ebac831ec6ca40737f7a792675cee05ea135 Mon Sep 17 00:00:00 2001 From: Don Mitchell Date: Wed, 9 Jan 2013 15:36:16 -0500 Subject: [PATCH] On menu based markdown conversion, be picky about x as marker for correct requiring it to be first non-whitespace char on line, followed by whitespace, followed eventually but another non-whitespace char strip trailing newline from selection. --- .../xmodule/js/src/problem/edit.coffee | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/src/problem/edit.coffee b/common/lib/xmodule/xmodule/js/src/problem/edit.coffee index 7de33db726..7d209ff0d4 100644 --- a/common/lib/xmodule/xmodule/js/src/problem/edit.coffee +++ b/common/lib/xmodule/xmodule/js/src/problem/edit.coffee @@ -125,23 +125,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'