From 267f68c6466bca92643bd887346b1a5f7eb7d80a Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Wed, 2 Oct 2024 04:29:24 -0400 Subject: [PATCH] update AI page --- views/chat.ejs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/views/chat.ejs b/views/chat.ejs index 0e08620..5d30089 100644 --- a/views/chat.ejs +++ b/views/chat.ejs @@ -413,7 +413,7 @@ }); } - // Converts the HTML content of the response to Markdown + // Converts the HTML content of the response to Markdown, including language identifier function convertToMarkdown(element) { let markdown = ''; const nodes = element.childNodes; @@ -422,8 +422,13 @@ if (node.nodeName === 'P') { markdown += `${node.innerText}\n\n`; } else if (node.nodeName === 'PRE') { - const codeBlock = node.querySelector('code').innerText; - markdown += `\`\`\`\n${codeBlock}\n\`\`\`\n\n`; + const codeBlock = node.querySelector('code'); + const languageClass = codeBlock.className.match(/language-(\w+)/); // Extract language from class if available + const language = languageClass ? languageClass[1] : ''; // Default to empty if no language found + const codeText = codeBlock.innerText; + + // Add language identifier to the Markdown code block + markdown += `\`\`\`${language}\n${codeText}\n\`\`\`\n\n`; } });