diff --git a/app.js b/app.js index 1546d7c..b546677 100644 --- a/app.js +++ b/app.js @@ -6,7 +6,6 @@ import Localdrive from 'localdrive'; import fs from 'fs'; import Hyperdrive from 'hyperdrive'; import Corestore from 'corestore'; - const store = new Corestore('./storage'); const drive = new Hyperdrive(store); @@ -236,8 +235,13 @@ function sendMessage(e) { } } -// appends element to #messages element with content set to sender and message +function scrollToBottom() { + var container = document.getElementById("messages-container"); + container.scrollTop = container.scrollHeight; +} + function onMessageAdded(from, message, avatar) { + const $div = document.createElement('div'); $div.classList.add('message'); @@ -255,21 +259,18 @@ function onMessageAdded(from, message, avatar) { const $text = document.createElement('div'); $text.classList.add('message-text'); - // Split message by line breaks and create a new paragraph for each line - const lines = message.split('\n'); - lines.forEach(line => { - const $line = document.createElement('p'); - $line.textContent = line; - $text.appendChild($line); - }); + // Render Markdown content + const md = window.markdownit(); + $text.innerHTML = md.render(message); $content.appendChild($header); $content.appendChild($text); $div.appendChild($content); document.querySelector('#messages').appendChild($div); -} + scrollToBottom(); +} async function updateIcon(username, avatarBuffer) { // Update the icon in the local HTML if necessary // This can be adjusted as per your needs diff --git a/index.html b/index.html index 6f25aee..0746973 100644 --- a/index.html +++ b/index.html @@ -6,6 +6,7 @@