123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- angular.module('app')
- .controller('HomeController', ['$scope', '$state',
- function($scope, $state) {
-
- $scope.Data = {
- Input: "",
- Output: ""
- };
-
- $scope.questions = [];
-
- $scope.formatText = function(text)
- {
- return text.replace(/\$([^\$]+)\$/g, function($1, $2)
- {
- return "\\(" + $2 + "\\)";
- })
- };
-
- $scope.convert = function()
- {
- $scope.questions = [];
- var input = $scope.Data.Input;
- $scope.Data.Output = "";
-
- var questions = input.split("\\section");
- questions.splice(0, 1);
-
- questions.forEach(function(questionStr)
- {
- var question = {
- Text: "",
- Answers: []
- };
- var responses = questionStr.split("\\item");
- question.Text = responses[0].replace(/^\*\{.*\}/, "")
- .replace(/\\medskip/, "")
- .replace(/\\begin\{.*\}/, "")
- .trim();
- question.Text = $scope.formatText(question.Text);
- responses.splice(0, 1);
-
- responses.forEach(function(answerStr) {
- answerStr = answerStr.replace(/\\medskip/, "")
- .replace(/\\end\{.*\}/, "")
- .trim();
- var a = answerStr.match(/^\[[^\]\[]+\]/)[0];
- answerStr = answerStr.substring(a.length, answerStr.length);
- answerStr = $scope.formatText(answerStr);
- question.Answers.push({
- Text: answerStr,
- Correct: a.length != 4
- })
- });
-
- $scope.questions.push(question);
- });
-
- /*var re = /\$[^$]+\$/g;
- console.log(input.match(re));*/
- };
-
- }]);
|