mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
fixed multiline regex
This commit is contained in:
@@ -67,7 +67,8 @@ Description: {Description}
|
||||
var settings = splitInput[0];
|
||||
var quizWithoutQuestions = getQuizWithOnlySettings(settings);
|
||||
|
||||
var questions = splitInput[1..]
|
||||
var rawQuestions = splitInput[1..];
|
||||
var questions = rawQuestions
|
||||
.Where(str => !string.IsNullOrWhiteSpace(str))
|
||||
.Select((q, i) => LocalQuizQuestion.ParseMarkdown(q, i))
|
||||
.ToArray();
|
||||
|
||||
@@ -114,7 +114,7 @@ public record LocalQuizQuestion
|
||||
if (linesWithoutPoints[^1].Equals("short_answer", StringComparison.CurrentCultureIgnoreCase))
|
||||
return "short_answer";
|
||||
|
||||
var answerLines = getAnswersGroupedByLines(linesWithoutPoints, questionIndex);
|
||||
var answerLines = getAnswerStringsWithMultilineSupport(linesWithoutPoints, questionIndex);
|
||||
var firstAnswerLine = answerLines.First();
|
||||
var isMultipleChoice =
|
||||
firstAnswerLine.StartsWith("a)")
|
||||
@@ -138,7 +138,7 @@ public record LocalQuizQuestion
|
||||
return "";
|
||||
}
|
||||
|
||||
private static List<string> getAnswersGroupedByLines(string[] linesWithoutPoints, int questionIndex)
|
||||
private static List<string> getAnswerStringsWithMultilineSupport(string[] linesWithoutPoints, int questionIndex)
|
||||
{
|
||||
var indexOfAnswerStart = linesWithoutPoints
|
||||
.ToList()
|
||||
@@ -175,7 +175,7 @@ public record LocalQuizQuestion
|
||||
|
||||
private static LocalQuizQuestionAnswer[] getAnswers(string[] linesWithoutPoints, int questionIndex, string questionType)
|
||||
{
|
||||
var answerLines = getAnswersGroupedByLines(linesWithoutPoints, questionIndex);
|
||||
var answerLines = getAnswerStringsWithMultilineSupport(linesWithoutPoints, questionIndex);
|
||||
|
||||
var answers = answerLines
|
||||
.Select((a, i) => LocalQuizQuestionAnswer.ParseMarkdown(a, questionType))
|
||||
|
||||
@@ -30,7 +30,12 @@ public record LocalQuizQuestionAnswer
|
||||
}
|
||||
|
||||
string startingQuestionPattern = @"^(\*?[a-z]?\))|\[\s*\]|\[\*\]|\^ ";
|
||||
var text = Regex.Replace(input, startingQuestionPattern, string.Empty).Trim();
|
||||
|
||||
int replaceCount = 0;
|
||||
var text = Regex.Replace(input, startingQuestionPattern, (m) =>
|
||||
{
|
||||
return replaceCount++ == 0 ? "" : m.Value;
|
||||
}).Trim();
|
||||
return new LocalQuizQuestionAnswer()
|
||||
{
|
||||
Correct = isCorrect,
|
||||
|
||||
Reference in New Issue
Block a user