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
                 text = text.replace(/\$([^\$]+)\$/g, function($1, $2)
24
                 text = text.replace(/\$([^\$]+)\$/g, function($1, $2)
25
                 {
25
                 {
26
                     return "\\(" + $2 + "\\)";
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
                 $scope.macros.forEach(function(macro)
33
                 $scope.macros.forEach(function(macro)
29
                 {
34
                 {
30
                     text = text.replace(macro.latex, macro.html);
35
                     text = text.replace(macro.latex, macro.html);
42
                 var questions = input.split("\\section");
47
                 var questions = input.split("\\section");
43
                 questions.splice(0, 1);
48
                 questions.splice(0, 1);
44
 
49
 
50
+                var firstQuestion = null;
45
                 questions.forEach(function(questionStr)
51
                 questions.forEach(function(questionStr)
46
                 {
52
                 {
47
                     var question = {
53
                     var question = {
49
                         Answers: []
55
                         Answers: []
50
                     };
56
                     };
51
                     var responses = questionStr.split("\\item");
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
                     question.Text = $scope.formatText(question.Text);
66
                     question.Text = $scope.formatText(question.Text);
57
                     responses.splice(0, 1);
67
                     responses.splice(0, 1);
58
 
68
 
59
                     responses.forEach(function(answerStr) {
69
                     responses.forEach(function(answerStr) {
60
-                        answerStr = answerStr.replace(/\\medskip/, "")
61
-                            .replace(/\\end\{.*\}/g, "")
62
-                            .trim();
70
+                        answerStr = answerStr.replace(/\\medskip/, "").trim();
63
                         var a = answerStr.match(/^\[[^\]\[]+\]/)[0];
71
                         var a = answerStr.match(/^\[[^\]\[]+\]/)[0];
64
                         answerStr = answerStr.substring(a.length, answerStr.length);
72
                         answerStr = answerStr.substring(a.length, answerStr.length);
65
                         answerStr = $scope.formatText(answerStr);
73
                         answerStr = $scope.formatText(answerStr);

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

11
             <div class="form-group">
11
             <div class="form-group">
12
                 <button class="btn btn-primary btn-block" ng-click="convert()">Do the magic</button>
12
                 <button class="btn btn-primary btn-block" ng-click="convert()">Do the magic</button>
13
             </div>
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
             <div class="form-group">
18
             <div class="form-group">
15
                 <div ng-repeat="question in questions">
19
                 <div ng-repeat="question in questions">
16
                     {{ question.Text }}
20
                     {{ question.Text }}
21
                     </ul>
25
                     </ul>
22
                 </div>
26
                 </div>
23
             </div>
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
         </div>
28
         </div>
29
     </div>
29
     </div>
30
 </div>
30
 </div>

Loading…
Cancel
Save