1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-discord.git synced 2024-11-01 12:24:15 +00:00
cchat-discord/internal/segments/md.go

35 lines
986 B
Go
Raw Normal View History

2020-06-19 01:00:24 +00:00
package segments
import (
"github.com/diamondburned/arikawa/discord"
"github.com/diamondburned/arikawa/state"
"github.com/diamondburned/cchat-discord/internal/segments/embed"
"github.com/diamondburned/cchat-discord/internal/segments/renderer"
2020-06-19 01:00:24 +00:00
"github.com/diamondburned/cchat/text"
"github.com/diamondburned/ningen/md"
)
func ParseMessage(m *discord.Message, s state.Store) text.Rich {
var content = []byte(m.Content)
var node = md.ParseWithMessage(content, s, m, true)
r := renderer.New(content, node)
// Register the needed states for some renderers.
r.WithState(m, s)
// Render the main message body.
r.Walk(node)
// Render the extra bits.
embed.RenderAttachments(r, m.Attachments)
embed.RenderEmbeds(r, m.Embeds, m, s)
return text.Rich{
Content: r.String(),
Segments: r.Segments,
}
2020-06-19 01:00:24 +00:00
}
func ParseWithMessage(b []byte, m *discord.Message, s state.Store, msg bool) text.Rich {
2020-06-19 01:00:24 +00:00
node := md.ParseWithMessage(b, s, m, msg)
return renderer.RenderNode(b, node)
}