mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[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
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user