Skip to content
Snippets Groups Projects
Commit 41e2e54e authored by Chris Sangwin's avatar Chris Sangwin
Browse files

Change the "teacher's answer" output of strings to remove quotes and maths environments.

Needed for Parson block output, but a general improvement.
parent b9f63579
No related branches found
No related tags found
No related merge requests found
......@@ -100,8 +100,8 @@ class stack_string_input extends stack_algebraic_input {
return '';
}
$value = stack_utils::maxima_string_to_php_string($value);
return stack_string('teacheranswershow', array('value' => '<code>'.$value.'</code>', 'display' => $display));
$display = stack_utils::maxima_string_strip_mbox($display);
return stack_string('teacheranswershow_disp', array('display' => $display));
}
/**
......
......@@ -781,6 +781,7 @@ class stack_utils {
$converted = str_replace("\"", "\\\"", $converted);
return '"' . $converted . '"';
}
/**
* Converts a PHP string object containing a Maxima string as presented by the grind command to a PHP string object.
* @param a string that contains ""-quotes around the content.
......@@ -792,6 +793,22 @@ class stack_utils {
return substr($converted, 1, -1);
}
/**
* Remove redundant "mbox" environments from Latex equations strings containing just strings.
* @param a string that contains ""-quotes around the content.
* @return a string without those quotes.
*/
public static function maxima_string_strip_mbox($string) {
$converted = trim($string);
if (substr($converted, 0, 2) == '\(' || substr($converted, 0, 2) == '\[') {
$converted = substr($converted, 2, -2);
}
if (substr(trim($converted), 0, 6) == '\mbox{') {
return substr(trim($converted), 6, -1);
}
return $string;
}
/**
* Translate some strings from Maxima.
* @param string $string
......
......@@ -57,9 +57,7 @@ class input_string_test extends qtype_stack_testcase {
.'style="width: 13.6em" autocapitalize="none" spellcheck="false" class="maxima-string" value="0" />',
$el->render(new stack_input_state(stack_input::VALID, array('0'), '', '', '', '', ''),
'stack1__ans1', false, null));
$this->assertEquals('The answer <span class="filter_mathjaxloader_equation"><span class="nolink">' .
'\( \\mbox{Hello world} \)</span></span>, which can be typed as <code>Hello world</code>, ' .
'would be correct.',
$this->assertEquals('The answer Hello world would be correct.',
$el->get_teacher_answer_display('"Hello world"', '\\mbox{Hello world}'));
}
......@@ -72,9 +70,7 @@ class input_string_test extends qtype_stack_testcase {
$this->assertEquals(stack_input::VALID, $state->status);
$this->assertEquals('"Hello world"', $state->contentsmodified);
$this->assertEquals('\[ \mbox{Hello world} \]', $state->contentsdisplayed);
$this->assertEquals('The answer <span class="filter_mathjaxloader_equation">' .
'<span class="nolink">\[ \[ \mbox{Hello world} \]</span></span> \), ' .
'which can be typed as <code>Hello world</code>, would be correct.',
$this->assertEquals('The answer Hello world would be correct.',
$el->get_teacher_answer_display($state->contentsmodified, $state->contentsdisplayed));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment