mirror of
https://github.com/diamondburned/cchat-discord.git
synced 2024-11-01 20:34:27 +00:00
56 lines
958 B
Go
56 lines
958 B
Go
|
package segments
|
||
|
|
||
|
import (
|
||
|
"github.com/diamondburned/cchat/text"
|
||
|
"github.com/diamondburned/ningen/md"
|
||
|
"github.com/yuin/goldmark/ast"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
InlineEmojiSize = 22
|
||
|
LargeEmojiSize = 48
|
||
|
)
|
||
|
|
||
|
type EmojiSegment struct {
|
||
|
start int
|
||
|
name string
|
||
|
emojiURL string
|
||
|
large bool
|
||
|
}
|
||
|
|
||
|
var _ text.Imager = (*EmojiSegment)(nil)
|
||
|
|
||
|
func (r *TextRenderer) emoji(n *md.Emoji, enter bool) ast.WalkStatus {
|
||
|
if enter {
|
||
|
r.append(EmojiSegment{
|
||
|
start: r.i(),
|
||
|
name: n.Name,
|
||
|
large: n.Large,
|
||
|
emojiURL: n.EmojiURL() + "&size=64",
|
||
|
})
|
||
|
}
|
||
|
|
||
|
return ast.WalkContinue
|
||
|
}
|
||
|
|
||
|
func (e EmojiSegment) Bounds() (start, end int) {
|
||
|
return e.start, e.start
|
||
|
}
|
||
|
|
||
|
func (e EmojiSegment) Image() string {
|
||
|
return e.emojiURL
|
||
|
}
|
||
|
|
||
|
// TODO: large emoji
|
||
|
|
||
|
func (e EmojiSegment) ImageSize() (w, h int) {
|
||
|
if e.large {
|
||
|
return LargeEmojiSize, LargeEmojiSize
|
||
|
}
|
||
|
return InlineEmojiSize, InlineEmojiSize
|
||
|
}
|
||
|
|
||
|
func (e EmojiSegment) ImageText() string {
|
||
|
return ":" + e.name + ":"
|
||
|
}
|