mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
fixed multiline regex
This commit is contained in:
@@ -54,7 +54,7 @@ DueAt: 2023-08-21T23:59:00
|
|||||||
LockAt: 2023-08-21T23:59:00
|
LockAt: 2023-08-21T23:59:00
|
||||||
AssignmentGroup: Assignments
|
AssignmentGroup: Assignments
|
||||||
AllowedAttempts: -1
|
AllowedAttempts: -1
|
||||||
Description: this is the
|
Description: this is the
|
||||||
multi line
|
multi line
|
||||||
description
|
description
|
||||||
---
|
---
|
||||||
@@ -80,4 +80,18 @@ Which events are triggered when the user clicks on an input field?
|
|||||||
firstQuestion.Answers.ElementAt(3).Text.Should().Be("submit");
|
firstQuestion.Answers.ElementAt(3).Text.Should().Be("submit");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CanUseBracesInAnswerFormultipleAnswer()
|
||||||
|
{
|
||||||
|
var rawMarkdownQuestion = @"
|
||||||
|
Which events are triggered when the user clicks on an input field?
|
||||||
|
[*] `int[] theThing()`
|
||||||
|
[] keydown
|
||||||
|
";
|
||||||
|
|
||||||
|
var question = LocalQuizQuestion.ParseMarkdown(rawMarkdownQuestion, 0);
|
||||||
|
question.Answers.First().Text.Should().Be("`int[] theThing()`");
|
||||||
|
question.Answers.Count().Should().Be(2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,8 @@ Description: {Description}
|
|||||||
var settings = splitInput[0];
|
var settings = splitInput[0];
|
||||||
var quizWithoutQuestions = getQuizWithOnlySettings(settings);
|
var quizWithoutQuestions = getQuizWithOnlySettings(settings);
|
||||||
|
|
||||||
var questions = splitInput[1..]
|
var rawQuestions = splitInput[1..];
|
||||||
|
var questions = rawQuestions
|
||||||
.Where(str => !string.IsNullOrWhiteSpace(str))
|
.Where(str => !string.IsNullOrWhiteSpace(str))
|
||||||
.Select((q, i) => LocalQuizQuestion.ParseMarkdown(q, i))
|
.Select((q, i) => LocalQuizQuestion.ParseMarkdown(q, i))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ public record LocalQuizQuestion
|
|||||||
if (linesWithoutPoints[^1].Equals("short_answer", StringComparison.CurrentCultureIgnoreCase))
|
if (linesWithoutPoints[^1].Equals("short_answer", StringComparison.CurrentCultureIgnoreCase))
|
||||||
return "short_answer";
|
return "short_answer";
|
||||||
|
|
||||||
var answerLines = getAnswersGroupedByLines(linesWithoutPoints, questionIndex);
|
var answerLines = getAnswerStringsWithMultilineSupport(linesWithoutPoints, questionIndex);
|
||||||
var firstAnswerLine = answerLines.First();
|
var firstAnswerLine = answerLines.First();
|
||||||
var isMultipleChoice =
|
var isMultipleChoice =
|
||||||
firstAnswerLine.StartsWith("a)")
|
firstAnswerLine.StartsWith("a)")
|
||||||
@@ -138,7 +138,7 @@ public record LocalQuizQuestion
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<string> getAnswersGroupedByLines(string[] linesWithoutPoints, int questionIndex)
|
private static List<string> getAnswerStringsWithMultilineSupport(string[] linesWithoutPoints, int questionIndex)
|
||||||
{
|
{
|
||||||
var indexOfAnswerStart = linesWithoutPoints
|
var indexOfAnswerStart = linesWithoutPoints
|
||||||
.ToList()
|
.ToList()
|
||||||
@@ -175,7 +175,7 @@ public record LocalQuizQuestion
|
|||||||
|
|
||||||
private static LocalQuizQuestionAnswer[] getAnswers(string[] linesWithoutPoints, int questionIndex, string questionType)
|
private static LocalQuizQuestionAnswer[] getAnswers(string[] linesWithoutPoints, int questionIndex, string questionType)
|
||||||
{
|
{
|
||||||
var answerLines = getAnswersGroupedByLines(linesWithoutPoints, questionIndex);
|
var answerLines = getAnswerStringsWithMultilineSupport(linesWithoutPoints, questionIndex);
|
||||||
|
|
||||||
var answers = answerLines
|
var answers = answerLines
|
||||||
.Select((a, i) => LocalQuizQuestionAnswer.ParseMarkdown(a, questionType))
|
.Select((a, i) => LocalQuizQuestionAnswer.ParseMarkdown(a, questionType))
|
||||||
|
|||||||
@@ -30,7 +30,12 @@ public record LocalQuizQuestionAnswer
|
|||||||
}
|
}
|
||||||
|
|
||||||
string startingQuestionPattern = @"^(\*?[a-z]?\))|\[\s*\]|\[\*\]|\^ ";
|
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()
|
return new LocalQuizQuestionAnswer()
|
||||||
{
|
{
|
||||||
Correct = isCorrect,
|
Correct = isCorrect,
|
||||||
|
|||||||
Reference in New Issue
Block a user