[feature] Parse content warning as HTML, serialize via API to plaintext

This commit is contained in:
tobi 2025-03-06 15:36:58 +01:00
commit 22ce924129
47 changed files with 947 additions and 553 deletions

View file

@ -508,7 +508,7 @@ func (suite *ReportsGetTestSuite) TestReportsGetAll() {
"muted": false,
"bookmarked": false,
"pinned": false,
"content": "dark souls status bot: \"thoughts of dog\"",
"content": "\u003cp\u003edark souls status bot: \"thoughts of dog\"\u003c/p\u003e",
"reblog": null,
"account": {
"id": "01F8MH5ZK5VRH73AKHQM6Y9VNX",
@ -765,7 +765,7 @@ func (suite *ReportsGetTestSuite) TestReportsGetCreatedByAccount() {
"muted": false,
"bookmarked": false,
"pinned": false,
"content": "dark souls status bot: \"thoughts of dog\"",
"content": "\u003cp\u003edark souls status bot: \"thoughts of dog\"\u003c/p\u003e",
"reblog": null,
"account": {
"id": "01F8MH5ZK5VRH73AKHQM6Y9VNX",
@ -1022,7 +1022,7 @@ func (suite *ReportsGetTestSuite) TestReportsGetTargetAccount() {
"muted": false,
"bookmarked": false,
"pinned": false,
"content": "dark souls status bot: \"thoughts of dog\"",
"content": "\u003cp\u003edark souls status bot: \"thoughts of dog\"\u003c/p\u003e",
"reblog": null,
"account": {
"id": "01F8MH5ZK5VRH73AKHQM6Y9VNX",

View file

@ -916,7 +916,7 @@ func (suite *SearchGetTestSuite) TestSearchAAny() {
}
suite.Len(searchResult.Accounts, 5)
suite.Len(searchResult.Statuses, 8)
suite.Len(searchResult.Statuses, 9)
suite.Len(searchResult.Hashtags, 0)
}
@ -959,7 +959,7 @@ func (suite *SearchGetTestSuite) TestSearchAAnyFollowingOnly() {
}
suite.Len(searchResult.Accounts, 2)
suite.Len(searchResult.Statuses, 8)
suite.Len(searchResult.Statuses, 9)
suite.Len(searchResult.Hashtags, 0)
}
@ -1002,7 +1002,7 @@ func (suite *SearchGetTestSuite) TestSearchAStatuses() {
}
suite.Len(searchResult.Accounts, 0)
suite.Len(searchResult.Statuses, 8)
suite.Len(searchResult.Statuses, 9)
suite.Len(searchResult.Hashtags, 0)
}

View file

@ -144,7 +144,7 @@ func (suite *StatusBoostTestSuite) TestPostBoost() {
},
"bookmarked": true,
"card": null,
"content": "hello world! #welcome ! first post on the instance :rainbow: !",
"content": "<p>hello world! <a href=\"http://localhost:8080/tags/welcome\" class=\"mention hashtag\" rel=\"tag nofollow noreferrer noopener\" target=\"_blank\">#<span>welcome</span></a> ! first post on the instance :rainbow: !</p>",
"created_at": "right the hell just now babyee",
"edited_at": null,
"emojis": [
@ -330,7 +330,7 @@ func (suite *StatusBoostTestSuite) TestPostBoostOwnFollowersOnly() {
},
"bookmarked": false,
"card": null,
"content": "hi!",
"content": "<p>hi!</p>",
"created_at": "right the hell just now babyee",
"edited_at": null,
"emojis": [],

View file

@ -103,7 +103,7 @@ func (suite *StatusFaveTestSuite) TestPostFave() {
},
"bookmarked": false,
"card": null,
"content": "🐕🐕🐕🐕🐕",
"content": "<p>🐕🐕🐕🐕🐕</p>",
"created_at": "right the hell just now babyee",
"edited_at": null,
"emojis": [],

View file

@ -91,7 +91,7 @@ func (suite *StatusHistoryTestSuite) TestGetHistory() {
suite.Equal(`[
{
"content": "hello everyone!",
"content": "\u003cp\u003ehello everyone!\u003c/p\u003e",
"spoiler_text": "introduction post",
"sensitive": true,
"created_at": "2021-10-20T10:40:37.000Z",

View file

@ -108,7 +108,7 @@ func (suite *StatusMuteTestSuite) TestMuteUnmuteStatus() {
"muted": true,
"bookmarked": false,
"pinned": false,
"content": "hello everyone!",
"content": "\u003cp\u003ehello everyone!\u003c/p\u003e",
"reblog": null,
"application": {
"name": "really cool gts application",
@ -197,7 +197,7 @@ func (suite *StatusMuteTestSuite) TestMuteUnmuteStatus() {
"muted": false,
"bookmarked": false,
"pinned": false,
"content": "hello everyone!",
"content": "\u003cp\u003ehello everyone!\u003c/p\u003e",
"reblog": null,
"application": {
"name": "really cool gts application",

View file

@ -123,6 +123,10 @@ type Status struct {
type WebStatus struct {
*Status
// HTML version of spoiler content
// (ie., not converted to plaintext).
SpoilerContent string `json:"-"`
// Override API account with web account.
Account *WebAccount `json:"account"`

View file

@ -67,7 +67,7 @@ func OGBase(instance *apimodel.InstanceV1) *OGMeta {
}
og := &OGMeta{
Title: text.SanitizeToPlaintext(instance.Title) + " - GoToSocial",
Title: text.RemoveHTML(instance.Title) + " - GoToSocial",
Type: "website",
Locale: locale,
URL: instance.URI,
@ -161,7 +161,7 @@ func AccountTitle(account *apimodel.WebAccount, accountDomain string) string {
// ParseDescription returns a string description which is
// safe to use as a template.HTMLAttr inside templates.
func ParseDescription(in string) string {
i := text.SanitizeToPlaintext(in)
i := text.RemoveHTML(in)
i = strings.ReplaceAll(i, "\n", " ")
i = strings.Join(strings.Fields(i), " ")
i = html.EscapeString(i)