update AI page

This commit is contained in:
Raven Scott 2024-10-02 04:29:24 -04:00
parent 4ece2a9461
commit 267f68c646

View File

@ -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) { function convertToMarkdown(element) {
let markdown = ''; let markdown = '';
const nodes = element.childNodes; const nodes = element.childNodes;
@ -422,8 +422,13 @@
if (node.nodeName === 'P') { if (node.nodeName === 'P') {
markdown += `${node.innerText}\n\n`; markdown += `${node.innerText}\n\n`;
} else if (node.nodeName === 'PRE') { } else if (node.nodeName === 'PRE') {
const codeBlock = node.querySelector('code').innerText; const codeBlock = node.querySelector('code');
markdown += `\`\`\`\n${codeBlock}\n\`\`\`\n\n`; 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`;
} }
}); });