Commit f8ee3efc by Tom Giannattasio

simplified syntax to match arjun's for string and numerical response

parent f2eb6656
...@@ -156,25 +156,22 @@ function updateXML() { ...@@ -156,25 +156,22 @@ function updateXML() {
// replace videos // replace videos
xml = xml.replace(/\{\{video\s(.*)\}\}/g, '<video youtube="1.0:$1" />\n\n'); xml = xml.replace(/\{\{video\s(.*)\}\}/g, '<video youtube="1.0:$1" />\n\n');
// replace string input // replace string and numerical
xml = xml.replace(/\_\_\_\[(.+)\]/g, '<stringresponse answer="$1" type="ci">\n <textline size="20"/>\n</stringresponse>\n\n'); xml = xml.replace(/\=\s*(.*)/g, function(match, p) {
var string;
// replace numerical input var params = /(.*)\+\-\s*(.*)/.exec(p);
xml = xml.replace(/\#\#\#\[(.+)\]/g, function(match, p) { if(parseFloat(p)) {
var solution = extractNumericalSolution(p); if(params) {
var string = '<numericalresponse answer="' + solution + '">\n'; string = '<numericalresponse answer="' + params[1] + '">\n';
string += ' <responseparam type="tolerance" default="' + params[2] + '" />\n';
var params = extractNumericalSettings(p); } else {
string = '<numericalresponse answer="' + p + '">\n';
if(params) {
for(var i = 0; i < params.length; i++) {
var splitProp = params[i].split(/:\s*/);
string += ' <responseparam type="' + splitProp[0] + '" default="' + splitProp[1] + '" />\n';
} }
string += ' <textline />\n';
string += '</numericalresponse>\n\n';
} else {
string = '<stringresponse answer="' + p + '" type="ci">\n <textline size="20"/>\n</stringresponse>\n\n';
} }
string += ' <textline />\n';
string += '</numericalresponse>\n\n';
return string; return string;
}); });
...@@ -256,6 +253,12 @@ function updatePreview() { ...@@ -256,6 +253,12 @@ function updatePreview() {
return groupString; return groupString;
}); });
html = html.replace(/\=\s*(.*)/g, function(match, p) {
var value = p.replace(/\+\-.*/g, '');
var string = '<input type="text" name="" id="" value="' + value + '" size="20">\n';
return string;
});
// wrap the paragraphs // wrap the paragraphs
html = html.replace(/(^(?!\<\/*ul|\s*\<li|\<h1|\s*\<label|\s*$).*$)/gm, '<p>$1</p>\n'); html = html.replace(/(^(?!\<\/*ul|\s*\<li|\<h1|\s*\<label|\s*$).*$)/gm, '<p>$1</p>\n');
...@@ -272,16 +275,7 @@ function updatePreview() { ...@@ -272,16 +275,7 @@ function updatePreview() {
// replace radios // replace radios
html = html.replace(/\(\s*\)/g, '<input type="radio" name="multiple-choice-id">'); html = html.replace(/\(\s*\)/g, '<input type="radio" name="multiple-choice-id">');
html = html.replace(/\(x\)/gi, '<input type="radio" checked name="multiple-choice-id">'); html = html.replace(/\(x\)/gi, '<input type="radio" checked name="multiple-choice-id">');
// replace string input
html = html.replace(/\_\_\_\[(.+)\]/g, function(match, p) {
var string = '<input type="text" name="" id="" value="' + p + '" size="20">\n';
return string;
});
// replace numerical input
html = html.replace(/\#\#\#\[(.+)\]/g, '<input type="text"><small>$1</small>');
// replace selects // replace selects
html = html.replace(/\[\[(.+)\]\]/g, function(match, p) { html = html.replace(/\[\[(.+)\]\]/g, function(match, p) {
...@@ -387,10 +381,10 @@ function makeMultipleChoice() { ...@@ -387,10 +381,10 @@ function makeMultipleChoice() {
function makeStringInput() { function makeStringInput() {
var selection = simpleEditor.getSelection(); var selection = simpleEditor.getSelection();
if(selection.length > 0) { if(selection.length > 0) {
var revisedSelection = '___[' + selection + ']'; var revisedSelection = '= ' + selection + '';
simpleEditor.replaceSelection(revisedSelection); simpleEditor.replaceSelection(revisedSelection);
} else { } else {
var template = '___[answer]\n'; var template = '= answer\n';
simpleEditor.replaceSelection(template); simpleEditor.replaceSelection(template);
setFocus(); setFocus();
} }
...@@ -399,10 +393,10 @@ function makeStringInput() { ...@@ -399,10 +393,10 @@ function makeStringInput() {
function makeNumberInput() { function makeNumberInput() {
var selection = simpleEditor.getSelection(); var selection = simpleEditor.getSelection();
if(selection.length > 0) { if(selection.length > 0) {
var revisedSelection = '###[' + selection + ']'; var revisedSelection = '= ' + selection + '';
simpleEditor.replaceSelection(revisedSelection); simpleEditor.replaceSelection(revisedSelection);
} else { } else {
var template = '###[answer +-tolerance]\n'; var template = '= answer +- x%\n';
simpleEditor.replaceSelection(template); simpleEditor.replaceSelection(template);
setFocus(); setFocus();
} }
......
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