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;