Browse Source

fixes

tags/1.0.1^0
Robin Thoni 8 years ago
parent
commit
09e3f945b2
1 changed files with 13 additions and 5 deletions
  1. 13
    5
      app/controllers/home.controller.js

+ 13
- 5
app/controllers/home.controller.js View File

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

Loading…
Cancel
Save