Browse Source

fixed newline replace; added question number

tags/1.0.0^0
Robin Thoni 8 years ago
parent
commit
90e51dd43e
2 changed files with 20 additions and 12 deletions
  1. 16
    8
      app/controllers/home.controller.js
  2. 4
    4
      app/views/home.html

+ 16
- 8
app/controllers/home.controller.js View File

@@ -24,7 +24,12 @@ angular.module('app')
24 24
                 text = text.replace(/\$([^\$]+)\$/g, function($1, $2)
25 25
                 {
26 26
                     return "\\(" + $2 + "\\)";
27
-                }).replace("\n", "");
27
+                }).replace(/\\medskip/, "")
28
+                    .replace(/\\begin\{.*\}/g, "")
29
+                    .replace(/\\end\{.*\}/g, "")
30
+                    .replace(/\n|\r|\r\n|\n\r/g, " ")
31
+                    .replace(/ +/, " ")
32
+                    .trim();
28 33
                 $scope.macros.forEach(function(macro)
29 34
                 {
30 35
                     text = text.replace(macro.latex, macro.html);
@@ -42,6 +47,7 @@ angular.module('app')
42 47
                 var questions = input.split("\\section");
43 48
                 questions.splice(0, 1);
44 49
 
50
+                var firstQuestion = null;
45 51
                 questions.forEach(function(questionStr)
46 52
                 {
47 53
                     var question = {
@@ -49,17 +55,19 @@ angular.module('app')
49 55
                         Answers: []
50 56
                     };
51 57
                     var responses = questionStr.split("\\item");
52
-                    question.Text = responses[0].replace(/^\*\{.*\}/, "")
53
-                        .replace(/\\medskip/g, "")
54
-                        .replace(/\\begin\{.*\}/g, "")
55
-                        .trim();
58
+                    question.Text = responses[0].replace(/^\*\{.* ([0-9]+).*\}/, function($1, $2)
59
+                    {
60
+                        $2 = parseInt($2);
61
+                        if (firstQuestion == null) {
62
+                            firstQuestion = $2;
63
+                        }
64
+                        return "Question " + ($2 - firstQuestion + 1) + "\n";
65
+                    });
56 66
                     question.Text = $scope.formatText(question.Text);
57 67
                     responses.splice(0, 1);
58 68
 
59 69
                     responses.forEach(function(answerStr) {
60
-                        answerStr = answerStr.replace(/\\medskip/, "")
61
-                            .replace(/\\end\{.*\}/g, "")
62
-                            .trim();
70
+                        answerStr = answerStr.replace(/\\medskip/, "").trim();
63 71
                         var a = answerStr.match(/^\[[^\]\[]+\]/)[0];
64 72
                         answerStr = answerStr.substring(a.length, answerStr.length);
65 73
                         answerStr = $scope.formatText(answerStr);

+ 4
- 4
app/views/home.html View File

@@ -11,6 +11,10 @@
11 11
             <div class="form-group">
12 12
                 <button class="btn btn-primary btn-block" ng-click="convert()">Do the magic</button>
13 13
             </div>
14
+            <div class="form-group">
15
+                <label for="Output">Output:</label>
16
+                <textarea id="Output" rows="10" class="form-control" ng-model="Data.Output"></textarea>
17
+            </div>
14 18
             <div class="form-group">
15 19
                 <div ng-repeat="question in questions">
16 20
                     {{ question.Text }}
@@ -21,10 +25,6 @@
21 25
                     </ul>
22 26
                 </div>
23 27
             </div>
24
-            <div class="form-group">
25
-                <label for="Output">Output:</label>
26
-                <textarea id="Output" rows="10" class="form-control" ng-model="Data.Output"></textarea>
27
-            </div>
28 28
         </div>
29 29
     </div>
30 30
 </div>

Loading…
Cancel
Save