diff --git a/client/js/chat.js b/client/js/chat.js index a0c4eff..eae3d04 100644 --- a/client/js/chat.js +++ b/client/js/chat.js @@ -1,5 +1,6 @@ let chatCount = 0; // Zähler für Chat-Sessions let currentChatId = null; // Aktuell angezeigte Chat-ID +let useMarkdown = true; document.getElementById('newChatButton').addEventListener('click', () => { createNewChat(); @@ -13,7 +14,14 @@ document.getElementById('sendButton').addEventListener('click', () => { if (messageText !== '' && currentChatId !== null) { // Stelle sicher, dass eine Chat-ID vorhanden ist const messageElement = document.createElement('div'); messageElement.classList.add('chat-message', 'user'); - messageElement.innerText = messageText; + //messageElement.innerText = messageText; + + if (useMarkdown) { + messageElement.innerHTML = renderMarkdown(messageText); + } else { + messageElement.innerText = messageText; + } + chatBox.prepend(messageElement); // Nachricht speichern @@ -238,6 +246,10 @@ function getLastUserMessage() { return ''; // Rückgabe eines leeren Strings, falls keine Nachricht gefunden wird } +function renderMarkdown(content) { + return marked.parse(content); +} + async function stream_api_open_ai(userMessage) { // Neues div-Element für die Antwort des Chatbots erstellen const chatBox = document.getElementById('chatBox'); @@ -287,8 +299,11 @@ async function stream_api_open_ai(userMessage) { const token = json.choices[0].delta.content; result += token; - // Live-Update des Chatbot-Textes - botMessageDiv.textContent = result; + if (useMarkdown) { + botMessageDiv.innerHTML = renderMarkdown(result); + } else { + botMessageDiv.textContent = result; + } } } catch (error) { console.error('Error parsing JSON:', error, 'Received:', jsonStr); diff --git a/client/welcome.html b/client/welcome.html index 559f8ec..3c305a1 100644 --- a/client/welcome.html +++ b/client/welcome.html @@ -43,7 +43,7 @@ - +