mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { QuestionType } from "../localQuizQuestion";
|
|
import { LocalQuizQuestionAnswer } from "../localQuizQuestionAnswer";
|
|
|
|
const parseMatchingAnswer = (input: string) => {
|
|
const matchingPattern = /^\^?/;
|
|
const textWithoutMatchDelimiter = input.replace(matchingPattern, "");
|
|
const [text, ...matchedParts] = textWithoutMatchDelimiter.split(" - ");
|
|
const answer: LocalQuizQuestionAnswer = {
|
|
correct: true,
|
|
text: text.trim(),
|
|
matchedText: matchedParts.join("-").trim(),
|
|
};
|
|
return answer;
|
|
};
|
|
|
|
export const quizQuestionAnswerMarkdownUtils = {
|
|
// getHtmlText(): string {
|
|
// return MarkdownService.render(this.text);
|
|
// }
|
|
|
|
parseMarkdown(input: string, questionType: string): LocalQuizQuestionAnswer {
|
|
const isCorrect = input.startsWith("*") || input[1] === "*";
|
|
|
|
if (questionType === QuestionType.MATCHING) {
|
|
return parseMatchingAnswer(input);
|
|
}
|
|
|
|
const startingQuestionPattern = /^(\*?[a-z]?\))|\[\s*\]|\[\*\]|\^ /;
|
|
|
|
let replaceCount = 0;
|
|
const text = input
|
|
.replace(startingQuestionPattern, (m) => (replaceCount++ === 0 ? "" : m))
|
|
.trim();
|
|
|
|
const answer: LocalQuizQuestionAnswer = {
|
|
correct: isCorrect,
|
|
text: text,
|
|
};
|
|
return answer;
|
|
},
|
|
};
|