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 @@ LinkUp +
@@ -53,7 +54,9 @@ -
+
+
+
diff --git a/package.json b/package.json index 6a89c1f..446d262 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "hyperdrive": "^11.8.1", "hyperswarm": "^4.7.14", "localdrive": "^1.11.4", + "marked": "^12.0.2", "serve-drive": "^5.0.8" } } diff --git a/style.css b/style.css index 4d147c9..6a1bc72 100644 --- a/style.css +++ b/style.css @@ -12,6 +12,11 @@ body { transition: background-color 0.3s ease, color 0.3s ease; } +#messages-container { + height: 45vh; /* Adjust as needed */ + overflow-y: auto; + } + /* Header styles */ header { display: flex;