From 536d9e482d4ebc012855372b9fcfa4f022d1618a Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Fri, 29 Sep 2023 10:39:56 +0200 Subject: [chore/bugfix] Deinterface text.Formatter, allow underscores in hashtags (#2233) --- internal/text/formatter.go | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'internal/text/formatter.go') 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
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, } } -- cgit v1.2.3