[chore/bugfix] Deinterface text.Formatter, allow underscores in hashtags (#2233)

This commit is contained in:
tobi
2023-09-29 10:39:56 +02:00
committed by GitHub
parent b6b8f82c87
commit 536d9e482d
18 changed files with 1040 additions and 713 deletions

View File

@@ -24,29 +24,25 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)
// Formatter wraps some logic and functions for parsing statuses and other text input into nice html.
// Each of the member functions returns a struct containing the formatted HTML and any tags, mentions, and
// emoji that were found in the text.
type Formatter interface {
// FromPlain parses an HTML text from a plaintext.
FromPlain(ctx context.Context, pmf gtsmodel.ParseMentionFunc, authorID string, statusID string, plain string) *FormatResult
// FromPlainNoParagraph parses an HTML text from a plaintext, without wrapping the resulting text in <p> tags.
FromPlainNoParagraph(ctx context.Context, pmf gtsmodel.ParseMentionFunc, authorID string, statusID string, plain string) *FormatResult
// FromMarkdown parses an HTML text from a markdown-formatted text.
FromMarkdown(ctx context.Context, pmf gtsmodel.ParseMentionFunc, authorID string, statusID string, md string) *FormatResult
// FromPlainEmojiOnly parses an HTML text from a plaintext, only parsing emojis and not mentions etc.
FromPlainEmojiOnly(ctx context.Context, pmf gtsmodel.ParseMentionFunc, authorID string, statusID string, plain string) *FormatResult
}
// FormatFunc is fulfilled by FromPlain,
// FromPlainNoParagraph, and FromMarkdown.
type FormatFunc func(
ctx context.Context,
parseMention gtsmodel.ParseMentionFunc,
authorID string,
statusID string,
text string,
) *FormatResult
type FormatFunc func(ctx context.Context, pmf gtsmodel.ParseMentionFunc, authorID string, statusID string, text string) *FormatResult
type formatter struct {
// Formatter wraps logic and functions for parsing
// statuses and other text input into nice html.
type Formatter struct {
db db.DB
}
// NewFormatter returns a new Formatter interface for parsing statuses and other text input into nice html.
func NewFormatter(db db.DB) Formatter {
return &formatter{
// NewFormatter returns a new Formatter.
func NewFormatter(db db.DB) *Formatter {
return &Formatter{
db: db,
}
}