diff --git a/chatserver/server.py b/chatserver/server.py index cc7edb4..40978b3 100644 --- a/chatserver/server.py +++ b/chatserver/server.py @@ -8,6 +8,7 @@ from flask import Flask, request, jsonify from flask_socketio import SocketIO, emit, join_room, leave_room from flask_cors import CORS from datetime import datetime # Import for timestamps +import markdown # Import the markdown library # Flask app for REST API and WebSocket app = Flask(__name__) @@ -78,6 +79,9 @@ def handle_message(username, chat_room, message): # Add a timestamp to the message timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S') + # Convert the message to HTML using Markdown + html_message = markdown.markdown(message) + # Store the message in the chat room's history if chat_room not in message_history: message_history[chat_room] = [] @@ -86,7 +90,7 @@ def handle_message(username, chat_room, message): # Broadcast the message to WebSocket clients in the chat room socketio.emit('message', { 'username': username, - 'message': message, + 'message': html_message, # Send the HTML-rendered message 'timestamp': timestamp, 'chat_room': chat_room }, room=chat_room) diff --git a/chatserver/templates/index.html b/chatserver/templates/index.html index 802036d..021517b 100644 --- a/chatserver/templates/index.html +++ b/chatserver/templates/index.html @@ -5,6 +5,8 @@ Web Chat Client + +