|
@@ -11,6 +11,11 @@ angular.module('app')
|
11
|
11
|
|
12
|
12
|
$scope.macros = [];
|
13
|
13
|
|
|
14
|
+ $scope.escapeRegExp = function(str)
|
|
15
|
+ {
|
|
16
|
+ return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
|
17
|
+ };
|
|
18
|
+
|
14
|
19
|
$scope.addMacro = function(latex, html)
|
15
|
20
|
{
|
16
|
21
|
$scope.macros.push({
|
|
@@ -24,15 +29,18 @@ angular.module('app')
|
24
|
29
|
text = text.replace(/\$([^\$]+)\$/g, function($1, $2)
|
25
|
30
|
{
|
26
|
31
|
return "\\(" + $2 + "\\)";
|
27
|
|
- }).replace(/\\medskip/, "")
|
|
32
|
+ }).replace(/\\medskip/g, "")
|
28
|
33
|
.replace(/\\begin\{.*\}/g, "")
|
29
|
34
|
.replace(/\\end\{.*\}/g, "")
|
30
|
35
|
.replace(/\n|\r|\r\n|\n\r/g, " ")
|
31
|
|
- .replace(/ +/, " ")
|
|
36
|
+ .replace(/ +/g, " ")
|
32
|
37
|
.trim();
|
33
|
38
|
$scope.macros.forEach(function(macro)
|
34
|
39
|
{
|
35
|
|
- text = text.replace(macro.latex, macro.html);
|
|
40
|
+ text = text.replace(new RegExp($scope.escapeRegExp(macro.latex) + "([^a-zA-Z])", "g"), function($1, $2)
|
|
41
|
+ {
|
|
42
|
+ return macro.html + $2;
|
|
43
|
+ });
|
36
|
44
|
});
|
37
|
45
|
return text;
|
38
|
46
|
};
|
|
@@ -55,7 +63,8 @@ angular.module('app')
|
55
|
63
|
Answers: []
|
56
|
64
|
};
|
57
|
65
|
var responses = questionStr.split("\\item");
|
58
|
|
- question.Text = responses[0].replace(/^\*\{.* ([0-9]+).*\}/, function($1, $2)
|
|
66
|
+ question.Text = $scope.formatText(responses[0]);
|
|
67
|
+ question.Text = question.Text.replace(/^\*\{[^\}]* ([0-9]+)[^\}]*\}/, function($1, $2)
|
59
|
68
|
{
|
60
|
69
|
$2 = parseInt($2);
|
61
|
70
|
if (firstQuestion == null) {
|
|
@@ -63,7 +72,6 @@ angular.module('app')
|
63
|
72
|
}
|
64
|
73
|
return "Question " + ($2 - firstQuestion + 1) + "\n";
|
65
|
74
|
});
|
66
|
|
- question.Text = $scope.formatText(question.Text);
|
67
|
75
|
responses.splice(0, 1);
|
68
|
76
|
|
69
|
77
|
responses.forEach(function(answerStr) {
|