mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
working on parsing markdown as a quiz
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace LocalModels;
|
||||
@@ -56,4 +57,61 @@ Description: {Description}
|
||||
{questionMarkdown}
|
||||
";
|
||||
}
|
||||
|
||||
public static LocalQuiz ParseMarkdown(string input)
|
||||
{
|
||||
|
||||
var splitInput = input.Split(Environment.NewLine + Environment.NewLine);
|
||||
var settings = splitInput[0];
|
||||
|
||||
var name = extractLabelValue(settings, "Name");
|
||||
var lockAtDueDate = bool.Parse(extractLabelValue(settings, "LockAtDueDate"));
|
||||
var shuffleAnswers = bool.Parse(extractLabelValue(settings, "ShuffleAnswers"));
|
||||
var oneQuestionAtATime = bool.Parse(extractLabelValue(settings, "OneQuestionAtATime"));
|
||||
var allowedAttempts = int.Parse(extractLabelValue(settings, "AllowedAttempts"));
|
||||
var dueAt = DateTime.Parse(extractLabelValue(settings, "DueAt"));
|
||||
var lockAt = DateTime.Parse(extractLabelValue(settings, "LockAt"));
|
||||
var description = extractDescription(settings);
|
||||
|
||||
// var assignmentGroup = ExtractLabelValue(settings, "AssignmentGroup");
|
||||
return new LocalQuiz()
|
||||
{
|
||||
Id = "id-" + name,
|
||||
Name = name,
|
||||
Description = description,
|
||||
LockAtDueDate = lockAtDueDate,
|
||||
LockAt = lockAt,
|
||||
DueAt = dueAt,
|
||||
ShuffleAnswers = shuffleAnswers,
|
||||
OneQuestionAtATime = oneQuestionAtATime,
|
||||
// LocalAssignmentGroupId = "someId",
|
||||
AllowedAttempts = allowedAttempts,
|
||||
Questions = new LocalQuizQuestion[] { }
|
||||
};
|
||||
}
|
||||
static string extractLabelValue(string input, string label)
|
||||
{
|
||||
string pattern = $@"{label}: (.*?)\n";
|
||||
Match match = Regex.Match(input, pattern);
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
return match.Groups[1].Value;
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
static string extractDescription(string input)
|
||||
{
|
||||
string pattern = "Description: (.*?)$";
|
||||
Match match = Regex.Match(input, pattern, RegexOptions.Singleline);
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
return match.Groups[1].Value;
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user