Add markdown support to the webclient
This commit is contained in:
parent
88e58bb79c
commit
4b7fe624bb
2 changed files with 16 additions and 2 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue