summaryrefslogtreecommitdiff
path: root/internal/processing/status/common.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2025-03-07 15:04:34 +0100
committerLibravatar GitHub <noreply@github.com>2025-03-07 14:04:34 +0000
commitd8113c11e4d84a6d04d56b58d337c235154a535b (patch)
tree3ed983cbb8f95c9ef51a02a51a50ab89c42abd14 /internal/processing/status/common.go
parent[bugfix] Store and expose status content type (#3870) (diff)
downloadgotosocial-d8113c11e4d84a6d04d56b58d337c235154a535b.tar.xz
[feature] Parse content warning to HTML, serialize via client API as plaintext (#3876)
* [feature] Parse content warning as HTML, serialize via API to plaintext * tidy up some cruft * whoops * oops * i'm da joker baybee * clemency muy lorde * rename some of the text functions for clarity * jiggle the opts * fiddle de deee * hopefully the last test fix i ever have to do in my beautiful life
Diffstat (limited to 'internal/processing/status/common.go')
-rw-r--r--internal/processing/status/common.go31
1 files changed, 17 insertions, 14 deletions
diff --git a/internal/processing/status/common.go b/internal/processing/status/common.go
index 6a4851f51..77058ed10 100644
--- a/internal/processing/status/common.go
+++ b/internal/processing/status/common.go
@@ -171,19 +171,25 @@ func (p *Processor) processContent(
)
}
- // format is the currently set text formatting
- // function, according to the provided content-type.
- var format text.FormatFunc
+ var (
+ // format is the currently set text formatting
+ // function, according to the provided content-type.
+ format text.FormatFunc
+ // formatCW is like format, but for content warning.
+ formatCW text.FormatFunc
+ )
switch contentType {
// Format status according to text/plain.
case gtsmodel.StatusContentTypePlain:
format = p.formatter.FromPlain
+ formatCW = p.formatter.FromPlainBasic
// Format status according to text/markdown.
case gtsmodel.StatusContentTypeMarkdown:
format = p.formatter.FromMarkdown
+ formatCW = p.formatter.FromMarkdownBasic
// Unknown.
default:
@@ -215,26 +221,23 @@ func (p *Processor) processContent(
status.Emojis = contentRes.Emojis
status.Tags = contentRes.Tags
- // From here-on-out just use emoji-only
- // plain-text formatting as the FormatFunc.
- format = p.formatter.FromPlainEmojiOnly
-
// Sanitize content warning and format.
- warning := text.SanitizeToPlaintext(contentWarning)
- warningRes := formatInput(format, warning)
+ cwRes := formatInput(formatCW, contentWarning)
// Gather results of the formatted.
- status.ContentWarning = warningRes.HTML
- status.Emojis = append(status.Emojis, warningRes.Emojis...)
+ status.ContentWarning = cwRes.HTML
+ status.Emojis = append(status.Emojis, cwRes.Emojis...)
if poll != nil {
// Pre-allocate slice of poll options of expected length.
status.PollOptions = make([]string, len(poll.Options))
for i, option := range poll.Options {
- // Sanitize each poll option and format.
- option = text.SanitizeToPlaintext(option)
- optionRes := formatInput(format, option)
+ // Strip each poll option and format.
+ //
+ // For polls just use basic formatting.
+ option = text.StripHTMLFromText(option)
+ optionRes := formatInput(p.formatter.FromPlainBasic, option)
// Gather results of the formatted.
status.PollOptions[i] = optionRes.HTML