From d8466634a1c2df10a0246c1cfd0e2329f12141b8 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Fri, 4 Apr 2025 11:12:34 +0100 Subject: [PATCH] Fix: Lesson generation fails --- src/components/GenerateCourse/AICourseLesson.tsx | 11 +++++++++-- src/lib/markdown.ts | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/GenerateCourse/AICourseLesson.tsx b/src/components/GenerateCourse/AICourseLesson.tsx index 12cab027a..91819953e 100644 --- a/src/components/GenerateCourse/AICourseLesson.tsx +++ b/src/components/GenerateCourse/AICourseLesson.tsx @@ -205,13 +205,20 @@ export function AICourseLesson(props: AICourseLessonProps) { const questions = getQuestionsFromResult(result); setDefaultQuestions(questions); - + const newResult = result.replace( /=START_QUESTIONS=.*?=END_QUESTIONS=/, '', ); - setLessonHtml(await markdownToHtmlWithHighlighting(newResult)); + const markdownHtml = await markdownToHtmlWithHighlighting( + newResult, + ).catch((e) => { + console.error(e); + return newResult; + }); + + setLessonHtml(markdownHtml); queryClient.invalidateQueries(getAiCourseLimitOptions()); setIsGenerating(false); }, diff --git a/src/lib/markdown.ts b/src/lib/markdown.ts index c5429df42..13956ad25 100644 --- a/src/lib/markdown.ts +++ b/src/lib/markdown.ts @@ -51,6 +51,9 @@ const markdownItAsync = MarkdownItAsync({ const html = await codeToHtml(code, { lang: lang?.toLowerCase(), theme: 'dracula', + }).catch((e) => { + console.warn(e); + return code; }); return html;