You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

home.controller.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. angular.module('app')
  2. .controller('HomeController', ['$scope', '$state',
  3. function($scope, $state) {
  4. $scope.Data = {
  5. Input: "",
  6. Output: ""
  7. };
  8. $scope.questions = [];
  9. $scope.formatText = function(text)
  10. {
  11. return text.replace(/\$([^\$]+)\$/g, function($1, $2)
  12. {
  13. return "\\(" + $2 + "\\)";
  14. })
  15. };
  16. $scope.convert = function()
  17. {
  18. $scope.questions = [];
  19. var input = $scope.Data.Input;
  20. $scope.Data.Output = "";
  21. var questions = input.split("\\section");
  22. questions.splice(0, 1);
  23. questions.forEach(function(questionStr)
  24. {
  25. var question = {
  26. Text: "",
  27. Answers: []
  28. };
  29. var responses = questionStr.split("\\item");
  30. question.Text = responses[0].replace(/^\*\{.*\}/, "")
  31. .replace(/\\medskip/, "")
  32. .replace(/\\begin\{.*\}/, "")
  33. .trim();
  34. question.Text = $scope.formatText(question.Text);
  35. responses.splice(0, 1);
  36. responses.forEach(function(answerStr) {
  37. answerStr = answerStr.replace(/\\medskip/, "")
  38. .replace(/\\end\{.*\}/, "")
  39. .trim();
  40. var a = answerStr.match(/^\[[^\]\[]+\]/)[0];
  41. answerStr = answerStr.substring(a.length, answerStr.length);
  42. answerStr = $scope.formatText(answerStr);
  43. question.Answers.push({
  44. Text: answerStr,
  45. Correct: a.length != 4
  46. })
  47. });
  48. $scope.questions.push(question);
  49. });
  50. /*var re = /\$[^$]+\$/g;
  51. console.log(input.match(re));*/
  52. };
  53. }]);