From d864d7529a11fbfc3d69b5f0c9ad0d380fbbce28 Mon Sep 17 00:00:00 2001 From: Joakim Persson Date: Tue, 30 Jul 2024 16:42:59 +0200 Subject: [PATCH] =?UTF-8?q?Konfigurerar=20parser.=20St=C3=A4dat=20upp=20fr?= =?UTF-8?q?=C3=A5n=20bortkommenterad=20kod.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smartassist/src/static/js/frontend.js | 28 ++++++++++----------------- 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/smartassist/src/static/js/frontend.js b/smartassist/src/static/js/frontend.js index f62a278..54f0453 100644 --- a/smartassist/src/static/js/frontend.js +++ b/smartassist/src/static/js/frontend.js @@ -3,7 +3,13 @@ const chatbox = document.getElementById('chatbox'); const userInput = document.getElementById('userInput'); -const parser = window.markdownit(); +const parser = window.markdownit({ + linkify: true, + strikethrough: true, +}); + +parser.enable(['table']); + // const html = markdownIt.use({ // // You can customize the parser options here, e.g., enable/disable certain features @@ -42,18 +48,6 @@ function sendMessage() { } } -function customRenderer(markdownText) { - // Use a regex pattern to match LaTeX code (e.g. $$...$$ or $...$) - const latexPattern = /(?:\$\$|\\\[)(.*?)?(?:\$\$|\\\])/g; - - // Replace each occurrence of LaTeX code with an HTML span element - const html = markdownText.replace(latexPattern, (match, p1) => { - return `${p1}`; - }); - - // Return the rendered HTML - return html; -} // Define a function to render a message in the chatbox with a specific class name @@ -67,20 +61,18 @@ function renderMessage(text, className) { // // Set the text content of the element to the message text // messageElement.textContent = text; - // Parse Markdown text into HTML and set it as the innerHTML of the element - // messageElement.innerHTML = marked.parse(text); - // Use the markdown-it parser const html = parser.render(text); messageElement.innerHTML = html; - // Typeset math // Append the message element to the chatbox immediately - chatbox.appendChild(messageElement); + // chatbox.appendChild(messageElement); // Typeset math in the message element MathJax.typesetPromise([messageElement]).then(() => { // No need to append anything here, it's already appended above + chatbox.appendChild(messageElement); + }); }