sanitizing chat messages and added meme arrow greentext

This commit is contained in:
iou1name 2018-06-17 17:49:49 -04:00
parent e434f8277a
commit d4b6c14e23
2 changed files with 21 additions and 1 deletions

View File

@ -4,8 +4,11 @@ SocketIO events.
""" """
import time import time
import bleach
from flask_socketio import SocketIO, emit, join_room from flask_socketio import SocketIO, emit, join_room
import database as db
socketio = SocketIO() socketio = SocketIO()
@socketio.on('joined', namespace="/chat") @socketio.on('joined', namespace="/chat")
@ -29,4 +32,17 @@ def text(data):
date = int(time.time()) date = int(time.time())
data["date"] = date data["date"] = date
emit('message', data, room=room) message = message.strip()
if not message:
return
tags = ["b", "code", "i", "s"]
message = bleach.clean(message, tags=tags)
lines = []
for line in message.splitlines():
if line.startswith(">"):
line = '<span class="greenText">' + line + '</span>'
lines.append(line)
message = "<br />".join(lines)
data["message"] = message
emit("message", data, room=room)

View File

@ -34,3 +34,7 @@
resize: none; resize: none;
box-sizing: border-box; box-sizing: border-box;
} }
.greenText {
color: green;
}