Skip to content

Commit

Permalink
Merge branch 'fix/TAO-2460-mathjax-error-500' into fix/TAO-2460-mathj…
Browse files Browse the repository at this point in the history
…ax-error
  • Loading branch information
krampstudio committed Mar 31, 2016
2 parents c1a0d76 + 566eb3c commit 894c898
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 30 deletions.
2 changes: 1 addition & 1 deletion manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'label' => 'QTI item model',
'description' => 'TAO QTI item model',
'license' => 'GPL-2.0',
'version' => '2.12.10',
'version' => '2.12.11',
'author' => 'Open Assessment Technologies',
'requires' => array(
'taoItems' => '>=2.9.7'
Expand Down
2 changes: 1 addition & 1 deletion scripts/update/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public function update($initialVersion){
}

$this->setVersion($currentVersion);
$this->skip('2.12.9', '2.12.10');
$this->skip('2.12.9', '2.12.11');
}

}
10 changes: 5 additions & 5 deletions views/js/controllers.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion views/js/controllers.min.js.map

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions views/js/qtiCreator/editor/MathEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,16 @@ define([
jaxQueue.Push(
["Typeset", MathJax.Hub, this.$buffer[0]],
function(){
var $script = _this.$buffer.find('script');

_this.processing = false;

args.target.html(_this.$buffer.html());

if ($script.length){
_this.mathML = _stripMathTags($script.html());
}

_this.$buffer.empty();
}
);
Expand Down Expand Up @@ -159,8 +166,8 @@ define([
};

var _stripComments = function(mathMLstr) {
mathMLstr = mathMLstr.replace(/<!--.*?-->/, '');
mathMLstr = mathMLstr.replace(/&lt;!--.*?--&gt;/, '');
mathMLstr = mathMLstr.replace(/<!--.*?-->/g, '');
mathMLstr = mathMLstr.replace(/&lt;!--.*?--&gt;/g, '');

return mathMLstr;
};
Expand Down
2 changes: 1 addition & 1 deletion views/js/qtiCreator/test/MathEditor/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8">
<title>QtiElements Test - QTI item model information model definition </title>
<title>MathJax Editor Test</title>
<link rel="stylesheet" type="text/css" href="/tao/views/js/lib/qunit/qunit.css">
<script type="text/javascript" src="/tao/views/js/lib/require.js"></script>
<script type="text/javascript" src="/tao/views/js/lib/qunit/qunit.js"></script>
Expand Down
75 changes: 56 additions & 19 deletions views/js/qtiCreator/test/MathEditor/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ function($, MathEditor, mathJax) {
display: data.display
});

if (typeof mathJax === 'undefined') {
assert.ok(false, 'MathJax is not available');
QUnit.start();

} else {
if (isMathJaxAvailable()) {
mathEditor.setTex(data.input);
mathEditor.renderFromTex();

Expand All @@ -60,6 +56,7 @@ function($, MathEditor, mathJax) {

QUnit.module('Matheditor MathML rendering');


var texWithSpecialChars = [
{ title: 'lower than', input: 'w < y' },
{ title: 'lower than equal', input: 'x \\leq y' },
Expand All @@ -76,15 +73,10 @@ function($, MathEditor, mathJax) {

mathEditor = new MathEditor({
buffer: $buffer,
target: $target,
display: data.display
target: $target
});

if (typeof mathJax === 'undefined') {
assert.ok(false, 'MathJax is not available');
QUnit.start();

} else {
if (isMathJaxAvailable()) {
mathEditor.setTex(data.input);
mathEditor.renderFromTex();

Expand All @@ -101,6 +93,7 @@ function($, MathEditor, mathJax) {
}
});


var mathMLWithComments = [
{ title: 'plain comment', input: '<mstyle displaystyle="true" scriptlevel="0"><mrow class="MJX-TeXAtom-ORD"><mi>x</mi><mo>&#x2264;<!-- ≤ --></mo><mi>w</mi></mrow></mstyle>'},
{ title: 'html-encoded comment', input: '<mstyle displaystyle="true" scriptlevel="0"><mrow class="MJX-TeXAtom-ORD"><mi>x</mi><mo>&#x2264;&lt;!-- ≤ --&gt;</mo><mi>w</mi></mrow></mstyle>'}
Expand All @@ -116,15 +109,10 @@ function($, MathEditor, mathJax) {

mathEditor = new MathEditor({
buffer: $buffer,
target: $target,
display: data.display
target: $target
});

if (typeof mathJax === 'undefined') {
assert.ok(false, 'MathJax is not available');
QUnit.start();

} else {
if (isMathJaxAvailable()) {
mathEditor.setMathML(data.input);
mathEditor.renderFromMathML();

Expand All @@ -144,6 +132,55 @@ function($, MathEditor, mathJax) {
function doesntContainsComments(string) {
return string.match(/<!--.*?-->/) === null && string.match(/&lt;!--.*?--&gt;/) === null;
}


var mathMLWithSpecialChars = [
{ title: 'inferior',
input: '<mstyle><mrow><mi>x</mi><mo><</mo><mi>y</mi></mrow></mstyle>',
output: '<mstyle><mrow><mi>x</mi><mo>&lt;</mo><mi>y</mi></mrow></mstyle>' },
{ title: 'superior',
input: '<mstyle><mrow><mi>x</mi><mo>></mo><mi>y</mi></mrow></mstyle>',
output: '<mstyle><mrow><mi>x</mi><mo>&gt;</mo><mi>y</mi></mrow></mstyle>' },
{ title: 'both',
input: '<mstyle><mrow><mi>x</mi><mo>></mo><mi>y</mi><mo><</mo><mi>y</mi></mrow></mstyle>',
output: '<mstyle><mrow><mi>x</mi><mo>&gt;</mo><mi>y</mi><mo>&lt;</mo><mi>y</mi></mrow></mstyle>' }
];

QUnit
.cases(mathMLWithSpecialChars)
.asyncTest('MathML rendering encodes special chars', 1, function test(data, assert) {
var mathjaxRenderingDelayMs = 750,

$buffer = $('.mj-buffer'),
$target = $('.mj-target'),

mathEditor = new MathEditor({
buffer: $buffer,
target: $target
});

if (isMathJaxAvailable()) {
mathEditor.setMathML(data.input);
mathEditor.renderFromMathML();

setTimeout(function checkMathJaxOutput() {
assert.strictEqual(mathEditor.mathML, data.output);

QUnit.start();
}, mathjaxRenderingDelayMs);
}
});

function isMathJaxAvailable() {
if (typeof mathJax === 'undefined') {
QUnit.assert.ok(false, 'MathJax is not available');
QUnit.start();

return false;
}
return true;
}

});


0 comments on commit 894c898

Please sign in to comment.