Exam generation rework, batch user tables, fastapi endpoint switch
This commit is contained in:
27
src/components/ExamEditor/Exercises/WriteBlanks/parsing.ts
Normal file
27
src/components/ExamEditor/Exercises/WriteBlanks/parsing.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
export interface ParsedQuestion {
|
||||
id: string;
|
||||
questionText: string;
|
||||
}
|
||||
|
||||
const parseText = (text: string): ParsedQuestion[] => {
|
||||
const lines = text.split('\\n').filter(line => line.trim());
|
||||
return lines.map(line => {
|
||||
const match = line.match(/(.*?)\{\{(\d+)\}\}/);
|
||||
if (match) {
|
||||
return {
|
||||
questionText: match[1],
|
||||
id: match[2]
|
||||
};
|
||||
}
|
||||
return { questionText: line, id: '' };
|
||||
}).filter(q => q.id);
|
||||
};
|
||||
|
||||
const reconstructText = (questions: ParsedQuestion[]): string => {
|
||||
return questions.map(q => `${q.questionText}{{${q.id}}}`).join('\\n') + '\\n';
|
||||
};
|
||||
|
||||
export {
|
||||
parseText,
|
||||
reconstructText
|
||||
}
|
||||
Reference in New Issue
Block a user