Skip to content

Commit

Permalink
Add support for syntax highlighted code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
hloeung committed Nov 12, 2022
1 parent d01e51b commit 093bc11
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions mm-go-irckit/userbridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (u *User) handleDirectMessageEvent(event *bridge.DirectMessageEvent) {
text = wordwrap.String(text, maxlen)
lines := strings.Split(text, "\n")
for _, text := range lines {
if text == "```" {
if strings.HasPrefix(text, "```") {
codeBlock = !codeBlock
}
// skip empty lines for anything not part of a code block.
Expand Down Expand Up @@ -293,7 +293,7 @@ func (u *User) handleChannelMessageEvent(event *bridge.ChannelMessageEvent) {
text = wordwrap.String(text, maxlen)
lines := strings.Split(text, "\n")
for _, text := range lines {
if text == "```" {
if strings.HasPrefix(text, "```") {
codeBlock = !codeBlock
}
// skip empty lines for anything not part of a code block.
Expand Down Expand Up @@ -1198,6 +1198,10 @@ func (u *User) loadLastViewedAt() map[string]int64 {
}

func (u *User) saveLastViewedAt(channelID string) {
if channelID == "" {
return
}

currentTime := make([]byte, 8)
binary.LittleEndian.PutUint64(currentTime, uint64(model.GetMillis()))

Expand Down Expand Up @@ -1291,7 +1295,7 @@ func (u *User) handleMessageThreadContext(channelID, messageID, parentID, event,
case u.v.GetBool(u.br.Protocol()+".prefixcontext") && strings.HasPrefix(text, "\x01"):
prefix = u.prefixContext(channelID, messageID, parentID, event) + " "
newText = strings.Replace(text, "\x01ACTION ", "\x01ACTION "+prefix, 1)
maxlen = len(text)
maxlen = len(newText)
case u.v.GetBool(u.br.Protocol()+".prefixcontext") && u.v.GetBool(u.br.Protocol()+".showcontextmulti"):
prefix = u.prefixContext(channelID, messageID, parentID, event) + " "
newText = text
Expand All @@ -1303,6 +1307,7 @@ func (u *User) handleMessageThreadContext(channelID, messageID, parentID, event,
case u.v.GetBool(u.br.Protocol()+".suffixcontext") && strings.HasSuffix(text, "\x01"):
suffix = " " + u.prefixContext(channelID, messageID, parentID, event)
newText = strings.Replace(text, " \x01", suffix+" \x01", 1)
maxlen = len(newText)
case u.v.GetBool(u.br.Protocol()+".suffixcontext") && u.v.GetBool(u.br.Protocol()+".showcontextmulti"):
suffix = " " + u.prefixContext(channelID, messageID, parentID, event)
newText = text
Expand Down

0 comments on commit 093bc11

Please sign in to comment.