Explorar el Código

macros replacement; output string generation

tags/1.0.0
Robin Thoni hace 8 años
padre
commit
e5d4ce9553
Se han modificado 2 ficheros con 53 adiciones y 9 borrados
  1. 51
    7
      app/controllers/home.controller.js
  2. 2
    2
      app/views/home.html

+ 51
- 7
app/controllers/home.controller.js Ver fichero

@@ -9,16 +9,32 @@ angular.module('app')
9 9
 
10 10
             $scope.questions = [];
11 11
 
12
+            $scope.macros = [];
13
+
14
+            $scope.addMacro = function(latex, html)
15
+            {
16
+                $scope.macros.push({
17
+                    latex: latex,
18
+                    html: html
19
+                });
20
+            };
21
+
12 22
             $scope.formatText = function(text)
13 23
             {
14
-                return text.replace(/\$([^\$]+)\$/g, function($1, $2)
24
+                text = text.replace(/\$([^\$]+)\$/g, function($1, $2)
15 25
                 {
16 26
                     return "\\(" + $2 + "\\)";
17
-                })
27
+                }).replace("\n", "");
28
+                $scope.macros.forEach(function(macro)
29
+                {
30
+                    text = text.replace(macro.latex, macro.html);
31
+                });
32
+                return text;
18 33
             };
19 34
 
20 35
             $scope.convert = function()
21 36
             {
37
+                $scope.Data.Output = "";
22 38
                 $scope.questions = [];
23 39
                 var input = $scope.Data.Input;
24 40
                 $scope.Data.Output = "";
@@ -34,15 +50,15 @@ angular.module('app')
34 50
                     };
35 51
                     var responses = questionStr.split("\\item");
36 52
                     question.Text = responses[0].replace(/^\*\{.*\}/, "")
37
-                        .replace(/\\medskip/, "")
38
-                        .replace(/\\begin\{.*\}/, "")
53
+                        .replace(/\\medskip/g, "")
54
+                        .replace(/\\begin\{.*\}/g, "")
39 55
                         .trim();
40 56
                     question.Text = $scope.formatText(question.Text);
41 57
                     responses.splice(0, 1);
42 58
 
43 59
                     responses.forEach(function(answerStr) {
44 60
                         answerStr = answerStr.replace(/\\medskip/, "")
45
-                            .replace(/\\end\{.*\}/, "")
61
+                            .replace(/\\end\{.*\}/g, "")
46 62
                             .trim();
47 63
                         var a = answerStr.match(/^\[[^\]\[]+\]/)[0];
48 64
                         answerStr = answerStr.substring(a.length, answerStr.length);
@@ -56,8 +72,36 @@ angular.module('app')
56 72
                     $scope.questions.push(question);
57 73
                 });
58 74
 
59
-                /*var re = /\$[^$]+\$/g;
60
-                console.log(input.match(re));*/
75
+                $scope.questions.forEach(function(question)
76
+                {
77
+                    $scope.Data.Output += question.Text + "\n";
78
+
79
+                    var goodAnswersCount = 0;
80
+                    question.Answers.forEach(function(answer)
81
+                    {
82
+                        if (answer.Correct) {
83
+                            ++goodAnswersCount;
84
+                        }
85
+                    });
86
+
87
+                    question.Answers.forEach(function(answer)
88
+                    {
89
+                        $scope.Data.Output += "\t" + (goodAnswersCount > 1 ? "[" : "(") + (answer.Correct ? "x" : "") +
90
+                            (goodAnswersCount > 1 ? "]" : ")") + answer.Text + "\n";
91
+                    });
92
+                    $scope.Data.Output += "\n";
93
+                });
61 94
             };
62 95
 
96
+            $scope.addMacro("\\RR", "\\mathbb{R}");
97
+            $scope.addMacro("\\CC", "\\mathbb{C}");
98
+            $scope.addMacro("\\QQ", "\\mathbb{Q}");
99
+            $scope.addMacro("\\di", "\\displaystyle");
100
+            $scope.addMacro("\\dd", "\\text{d}");
101
+            $scope.addMacro("<<", "&#171");
102
+            $scope.addMacro(">>", "&#187");
103
+            $scope.addMacro("<", "&#60");
104
+            $scope.addMacro(">", "&#62");
105
+            $scope.addMacro("\\\'{E}", "&#201");
106
+            $scope.addMacro("\\\'{A}", "&#192");
63 107
     }]);

+ 2
- 2
app/views/home.html Ver fichero

@@ -21,10 +21,10 @@
21 21
                     </ul>
22 22
                 </div>
23 23
             </div>
24
-            <!--<div class="form-group">
24
+            <div class="form-group">
25 25
                 <label for="Output">Output:</label>
26 26
                 <textarea id="Output" rows="10" class="form-control" ng-model="Data.Output"></textarea>
27
-            </div>-->
27
+            </div>
28 28
         </div>
29 29
     </div>
30 30
 </div>

Loading…
Cancelar
Guardar