telegramfmt

package
v0.15.4-0...-7630340 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(ctx context.Context, message string, entities []tg.MessageEntityClass, params FormatParams) *event.MessageEventContent

Types

type BodyRange

type BodyRange struct {
	Start  int
	Length int
	Value  BodyRangeValue
}

func (BodyRange) End

func (b BodyRange) End() int

End returns the end index of the range.

func (BodyRange) Offset

func (b BodyRange) Offset(offset int) *BodyRange

Offset changes the start of the range without affecting the length.

func (BodyRange) String

func (b BodyRange) String() string

func (BodyRange) TruncateEnd

func (b BodyRange) TruncateEnd(maxEnd int) *BodyRange

TruncateEnd changes the length of the range, so it ends at or before the given index and starts at the same index as before.

func (BodyRange) TruncateStart

func (b BodyRange) TruncateStart(startAt int) *BodyRange

TruncateStart changes the length of the range, so it starts at the given index and ends at the same index as before.

type BodyRangeList

type BodyRangeList []BodyRange

func (BodyRangeList) Len

func (b BodyRangeList) Len() int

func (BodyRangeList) Less

func (b BodyRangeList) Less(i, j int) bool

func (BodyRangeList) Swap

func (b BodyRangeList) Swap(i, j int)

type BodyRangeValue

type BodyRangeValue interface {
	String() string
	Format(message string) string
	IsCode() bool
}

type FormatParams

type FormatParams struct {
	CustomEmojis          map[networkid.EmojiID]emojis.EmojiInfo
	GetUserInfoByUsername func(ctx context.Context, username string) (UserInfo, error)
	GetUserInfoByID       func(ctx context.Context, id int64) (UserInfo, error)
	NormalizeURL          func(ctx context.Context, url string) string
}

func (FormatParams) WithCustomEmojis

func (fp FormatParams) WithCustomEmojis(emojis map[networkid.EmojiID]emojis.EmojiInfo) FormatParams

type LinkedRangeTree

type LinkedRangeTree struct {
	Node    *BodyRange
	Sibling *LinkedRangeTree
	Child   *LinkedRangeTree
}

LinkedRangeTree is a linked tree of formatting entities.

It's meant to parse a list of Telegram entity ranges into nodes that either overlap completely or not at all, which enables more natural conversion to HTML.

func (*LinkedRangeTree) Add

func (lrt *LinkedRangeTree) Add(r *BodyRange)

Add adds the given formatting entity to this tree.

func (*LinkedRangeTree) Format

func (lrt *LinkedRangeTree) Format(message UTF16String, ctx formatContext) string

type Mention

type Mention struct {
	UserInfo
	UserID     networkid.UserID
	AccessHash int64
	Username   string
}

func (Mention) Format

func (m Mention) Format(message string) string

func (Mention) IsCode

func (m Mention) IsCode() bool

func (Mention) String

func (m Mention) String() string

type Style

type Style struct {
	// Type is the type of style.
	Type StyleType

	// Language is the language of the code block, if applicable.
	Language string

	// URL is the URL to link to, if applicable.
	URL string

	// EmojiInfo is the emoji to display, if applicable.
	EmojiInfo emojis.EmojiInfo
}

Style represents a style to apply to a range of text.

func (Style) Format

func (s Style) Format(message string) string

func (Style) IsCode

func (s Style) IsCode() bool

func (Style) String

func (s Style) String() string

type StyleType

type StyleType int
const (
	StyleNone StyleType = iota
	StyleBold
	StyleItalic
	StyleUnderline
	StyleStrikethrough
	StyleBlockquote
	StyleCode
	StylePre
	StyleEmail
	StyleTextURL
	StyleURL
	StyleCustomEmoji
	StyleBotCommand
	StyleHashtag
	StyleCashtag
	StylePhone
	StyleSpoiler
	StyleBankCard
	StyleFormattedDate
)

func (StyleType) String

func (s StyleType) String() string

type UTF16String

type UTF16String []uint16

func NewUTF16String

func NewUTF16String(s string) UTF16String

func (UTF16String) String

func (u UTF16String) String() string

type UserInfo

type UserInfo struct {
	MXID id.UserID
	Name string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL