From 8d677f3a225d782ae266b016599908412ba9ac07 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Thu, 15 Feb 2024 22:15:08 +0000 Subject: [PATCH] Fix markdown rendering --- src/lib/markdown.ts | 20 ++++++++++++-------- src/lib/question-group.ts | 1 + 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/lib/markdown.ts b/src/lib/markdown.ts index e0a7b2905..474c08174 100644 --- a/src/lib/markdown.ts +++ b/src/lib/markdown.ts @@ -2,15 +2,19 @@ import MarkdownIt from 'markdown-it'; export function markdownToHtml(markdown: string, isInline = true): string { - const md = new MarkdownIt({ - html: true, - linkify: true, - }); + try { + const md = new MarkdownIt({ + html: true, + linkify: true, + }); - if (isInline) { - return md.renderInline(markdown); - } else { - return md.render(markdown); + if (isInline) { + return md.renderInline(markdown); + } else { + return md.render(markdown); + } + } catch (e) { + return markdown; } } diff --git a/src/lib/question-group.ts b/src/lib/question-group.ts index a3d211d49..e50eee1f6 100644 --- a/src/lib/question-group.ts +++ b/src/lib/question-group.ts @@ -81,6 +81,7 @@ export async function getAllQuestionGroups(): Promise { if (answerText.endsWith('.md')) { const answerFilePath = `/src/data/question-groups/${questionGroupDir}/content/${answerText}`; answerText = + answerFilesMap[answerFilePath]?.default || answerFilesMap[answerFilePath] || `File missing: ${answerFilePath}`;