aboutsummaryrefslogtreecommitdiff
path: root/ui/messages/parser
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-04-18 14:20:57 +0300
committerTulir Asokan <tulir@maunium.net>2018-04-18 14:46:03 +0300
commitbb36996194492db6cc17f9cfd91769f31df7003b (patch)
treea10b83a338615e5386a05d38913b3f97165b1792 /ui/messages/parser
parent3750d5007fe31b1a4d706357f43774d08944213e (diff)
Add support for sending Markdown messages
Diffstat (limited to 'ui/messages/parser')
-rw-r--r--ui/messages/parser/htmlparser.go14
-rw-r--r--ui/messages/parser/parser.go2
2 files changed, 13 insertions, 3 deletions
diff --git a/ui/messages/parser/htmlparser.go b/ui/messages/parser/htmlparser.go
index 4f3522a..5e3b289 100644
--- a/ui/messages/parser/htmlparser.go
+++ b/ui/messages/parser/htmlparser.go
@@ -37,6 +37,9 @@ var matrixToURL = regexp.MustCompile("^(?:https?://)?(?:www\\.)?matrix\\.to/#/([
type MatrixHTMLProcessor struct {
text tstring.TString
+ sender string
+ msgtype string
+
indent string
listType string
lineIsNew bool
@@ -52,7 +55,11 @@ func (parser *MatrixHTMLProcessor) newline() {
}
}
-func (parser *MatrixHTMLProcessor) Preprocess() {}
+func (parser *MatrixHTMLProcessor) Preprocess() {
+ if parser.msgtype == "m.emote" {
+ parser.text = tstring.NewColorTString(fmt.Sprintf("* %s ", parser.sender), widget.GetHashColor(parser.sender))
+ }
+}
func (parser *MatrixHTMLProcessor) HandleText(text string) {
style := tcell.StyleDefault
@@ -170,12 +177,15 @@ func (parser *MatrixHTMLProcessor) Postprocess() {
}
// ParseHTMLMessage parses a HTML-formatted Matrix event into a UIMessage.
-func ParseHTMLMessage(room *rooms.Room, evt *gomatrix.Event) tstring.TString {
+func ParseHTMLMessage(room *rooms.Room, evt *gomatrix.Event, senderDisplayname string) tstring.TString {
htmlData, _ := evt.Content["formatted_body"].(string)
+ msgtype, _ := evt.Content["msgtype"].(string)
processor := &MatrixHTMLProcessor{
room: room,
text: tstring.NewBlankTString(),
+ msgtype: msgtype,
+ sender: senderDisplayname,
indent: "",
listType: "",
lineIsNew: true,
diff --git a/ui/messages/parser/parser.go b/ui/messages/parser/parser.go
index 58b0248..d12383a 100644
--- a/ui/messages/parser/parser.go
+++ b/ui/messages/parser/parser.go
@@ -60,7 +60,7 @@ func ParseMessage(gmx ifc.Gomuks, room *rooms.Room, evt *gomatrix.Event) message
case "m.text", "m.notice", "m.emote":
format, hasFormat := evt.Content["format"].(string)
if hasFormat && format == "org.matrix.custom.html" {
- text := ParseHTMLMessage(room, evt)
+ text := ParseHTMLMessage(room, evt, displayname)
return messages.NewExpandedTextMessage(evt.ID, evt.Sender, displayname, msgtype, text, ts)
} else {
text, _ := evt.Content["body"].(string)