Fix codeblocks in chat (#676)
* allowed codeblocks in chat (owncast#675) * dont send empty chat messages back to frontend (owncast#675)
This commit is contained in:
parent
89cf6115b3
commit
4bfdf0e667
@ -117,11 +117,13 @@ func (s *server) Listen() {
|
|||||||
// and standardize this message into something safe we can send everyone else.
|
// and standardize this message into something safe we can send everyone else.
|
||||||
msg.RenderAndSanitizeMessageBody()
|
msg.RenderAndSanitizeMessageBody()
|
||||||
|
|
||||||
s.listener.MessageSent(msg)
|
if !msg.Empty() {
|
||||||
s.sendAll(msg)
|
s.listener.MessageSent(msg)
|
||||||
|
s.sendAll(msg)
|
||||||
|
|
||||||
// Store in the message history
|
// Store in the message history
|
||||||
addMessage(msg)
|
addMessage(msg)
|
||||||
|
}
|
||||||
case ping := <-s.pingCh:
|
case ping := <-s.pingCh:
|
||||||
fmt.Println("PING?", ping)
|
fmt.Println("PING?", ping)
|
||||||
|
|
||||||
|
@ -38,6 +38,10 @@ func (m *ChatEvent) RenderAndSanitizeMessageBody() {
|
|||||||
m.Body = RenderAndSanitize(raw)
|
m.Body = RenderAndSanitize(raw)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *ChatEvent) Empty() bool {
|
||||||
|
return m.Body == ""
|
||||||
|
}
|
||||||
|
|
||||||
// RenderAndSanitize will turn markdown into HTML, sanitize raw user-supplied HTML and standardize
|
// RenderAndSanitize will turn markdown into HTML, sanitize raw user-supplied HTML and standardize
|
||||||
// the message into something safe and renderable for clients.
|
// the message into something safe and renderable for clients.
|
||||||
func RenderAndSanitize(raw string) string {
|
func RenderAndSanitize(raw string) string {
|
||||||
@ -111,5 +115,9 @@ func sanitize(raw string) string {
|
|||||||
// Allow emphasis
|
// Allow emphasis
|
||||||
p.AllowElements("em")
|
p.AllowElements("em")
|
||||||
|
|
||||||
|
// Allow code blocks
|
||||||
|
p.AllowElements("code")
|
||||||
|
p.AllowElements("pre")
|
||||||
|
|
||||||
return p.Sanitize(raw)
|
return p.Sanitize(raw)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user