diff options
author | 2023-09-29 10:39:56 +0200 | |
---|---|---|
committer | 2023-09-29 10:39:56 +0200 | |
commit | 536d9e482d4ebc012855372b9fcfa4f022d1618a (patch) | |
tree | 36079fb403b9a9bb7d3a64ace582c6870bcce77b /internal/text/formatter.go | |
parent | [bugfix] Move follow.show_reblogs check further up to avoid showing unwanted ... (diff) | |
download | gotosocial-536d9e482d4ebc012855372b9fcfa4f022d1618a.tar.xz |
[chore/bugfix] Deinterface text.Formatter, allow underscores in hashtags (#2233)
Diffstat (limited to 'internal/text/formatter.go')
-rw-r--r-- | internal/text/formatter.go | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/internal/text/formatter.go b/internal/text/formatter.go index 0e5e0b554..8f7e6e1f6 100644 --- a/internal/text/formatter.go +++ b/internal/text/formatter.go @@ -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 -} - -type FormatFunc func(ctx context.Context, pmf gtsmodel.ParseMentionFunc, authorID string, statusID string, text string) *FormatResult - -type formatter struct { +// FormatFunc is fulfilled by FromPlain, +// FromPlainNoParagraph, and FromMarkdown. +type FormatFunc func( + ctx context.Context, + parseMention gtsmodel.ParseMentionFunc, + authorID string, + statusID string, + text string, +) *FormatResult + +// 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, } } |