From 7bafbe463c7b85b817437df14fadc4c6b37022d9 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 16 Aug 2020 16:06:32 +0200 Subject: Greentext when first character is > --- matrix/matrix.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'matrix') diff --git a/matrix/matrix.go b/matrix/matrix.go index f7f308b..88ec406 100644 --- a/matrix/matrix.go +++ b/matrix/matrix.go @@ -17,6 +17,7 @@ package matrix import ( + "strings" "context" "crypto/tls" "encoding/gob" @@ -819,7 +820,26 @@ func (c *Container) MarkRead(roomID id.RoomID, eventID id.EventID) { }() } +func greentext(text string) string { + var result strings.Builder + for i, line := range strings.Split(text, "\n") { + if i > 0 { + result.WriteByte('\n') + } + if len(line) > 0 && line[0] == '>' { + result.WriteString("") + result.WriteString(line) + result.WriteString("") + } else { + result.WriteString(line) + } + } + return result.String() +} + func (c *Container) PrepareMarkdownMessage(roomID id.RoomID, msgtype event.MessageType, text, html string, rel *ifc.Relation) *muksevt.Event { + text = greentext(text) + var content event.MessageEventContent if html != "" { content = event.MessageEventContent{ -- cgit v1.2.3