From d8113c11e4d84a6d04d56b58d337c235154a535b Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Fri, 7 Mar 2025 15:04:34 +0100 Subject: [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 --- internal/text/markdown_test.go | 86 ++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 37 deletions(-) (limited to 'internal/text/markdown_test.go') diff --git a/internal/text/markdown_test.go b/internal/text/markdown_test.go index 153673415..923487978 100644 --- a/internal/text/markdown_test.go +++ b/internal/text/markdown_test.go @@ -41,43 +41,45 @@ that was some JSON :) ` const ( - simpleMarkdown = "# Title\n\nHere's a simple text in markdown.\n\nHere's a [link](https://example.org)." - simpleMarkdownExpected = "
Here's a simple text in markdown.
Here's a link.
" - withCodeBlockExpected = "Below is some JSON.
{\n "key": "value",\n "another_key": [\n "value1",\n "value2"\n ]\n}\nthat was some JSON :)
" - withInlineCode = "`Nobody tells you about theSECRET CODE, do they?`"
- withInlineCodeExpected = "Nobody tells you about the <code><del>SECRET CODE</del></code>, do they?
, do they?`"
- withInlineCode2Expected = "Nobody tells you about the </code><del>SECRET CODE</del><code>, do they?
"
- withHashtag = "# Title\n\nhere's a simple status that uses hashtag #Hashtag!"
- withHashtagExpected = "Title
here's a simple status that uses hashtag #Hashtag!
"
- withTamilHashtag = "here's a simple status that uses a hashtag in Tamil #தமிழ்"
- withTamilHashtagExpected = "here's a simple status that uses a hashtag in Tamil #தமிழ்
"
- mdWithHTML = "# Title\n\nHere's a simple text in markdown.\n\nHere's a link.\n\nHere's an image:
"
- mdWithHTMLExpected = "Title
Here's a simple text in markdown.
Here's a link.
Here's an image:
"
- mdWithCheekyHTML = "# Title\n\nHere's a simple text in markdown.\n\nHere's a cheeky little script: "
- mdWithCheekyHTMLExpected = "Title
Here's a simple text in markdown.
Here's a cheeky little script:
"
- mdWithHashtagInitial = "#welcome #Hashtag"
- mdWithHashtagInitialExpected = ""
- mdCodeBlockWithNewlines = "some code coming up\n\n```\n\n\n\n```\nthat was some code"
- mdCodeBlockWithNewlinesExpected = "some code coming up
\n\n\n
that was some code
"
- mdWithFootnote = "fox mulder,fbi.[^1]\n\n[^1]: federated bureau of investigation"
- mdWithFootnoteExpected = "fox mulder,fbi.[^1]
[^1]: federated bureau of investigation
"
- mdWithBlockQuote = "get ready, there's a block quote coming:\n\n>line1\n>line2\n>\n>line3\n\n"
- mdWithBlockQuoteExpected = "get ready, there's a block quote coming:
line1
line2
line3
"
- mdHashtagAndCodeBlock = "#Hashtag\n\n```\n#Hashtag\n```"
- mdHashtagAndCodeBlockExpected = "#Hashtag\n
"
- mdMentionAndCodeBlock = "@the_mighty_zork\n\n```\n@the_mighty_zork\n```"
- mdMentionAndCodeBlockExpected = "@the_mighty_zork\n
"
- mdWithSmartypants = "\"you have to quargle the bleepflorp\" they said with 1/2 of nominal speed and 1/3 of the usual glumping"
- mdWithSmartypantsExpected = "\"you have to quargle the bleepflorp\" they said with 1/2 of nominal speed and 1/3 of the usual glumping
"
- mdWithAsciiHeart = "hello <3 old friend <3 i loved u 3 :(( you stole my heart"
- mdWithAsciiHeartExpected = "hello <3 old friend <3 i loved u </3 :(( you stole my heart
"
- mdWithStrikethrough = "I have ~~mdae~~ made an error"
- mdWithStrikethroughExpected = "I have mdae made an error
"
- mdWithLink = "Check out this code, i heard it was written by a sloth https://github.com/superseriousbusiness/gotosocial"
- mdWithLinkExpected = "Check out this code, i heard it was written by a sloth https://github.com/superseriousbusiness/gotosocial
"
- mdObjectInCodeBlock = "@foss_satan@fossbros-anonymous.io this is how to mention a user\n```\n@the_mighty_zork hey bud! nice #ObjectOrientedProgramming software you've been writing lately! :rainbow:\n```\nhope that helps"
- mdObjectInCodeBlockExpected = "@foss_satan this is how to mention a user
@the_mighty_zork hey bud! nice #ObjectOrientedProgramming software you've been writing lately! :rainbow:\n
hope that helps
"
+ simpleMarkdown = "# Title\n\nHere's a simple text in markdown.\n\nHere's a [link](https://example.org)."
+ simpleMarkdownExpected = "Title
Here's a simple text in markdown.
Here's a link.
"
+ withCodeBlockExpected = "Title
Below is some JSON.
{\n "key": "value",\n "another_key": [\n "value1",\n "value2"\n ]\n}\n
that was some JSON :)
"
+ withInlineCode = "`Nobody tells you about the SECRET CODE, do they?`"
+ withInlineCodeExpected = "Nobody tells you about the <code><del>SECRET CODE</del></code>, do they?
"
+ withInlineCode2 = "`Nobody tells you about the , do they?`"
+ withInlineCode2Expected = "Nobody tells you about the </code><del>SECRET CODE</del><code>, do they?
"
+ withHashtag = "# Title\n\nhere's a simple status that uses hashtag #Hashtag!"
+ withHashtagExpected = "Title
here's a simple status that uses hashtag #Hashtag!
"
+ withTamilHashtag = "here's a simple status that uses a hashtag in Tamil #தமிழ்"
+ withTamilHashtagExpected = "here's a simple status that uses a hashtag in Tamil #தமிழ்
"
+ mdWithHTML = "# Title\n\nHere's a simple text in markdown.\n\nHere's a link.\n\nHere's an image:
"
+ mdWithHTMLExpected = "Title
Here's a simple text in markdown.
Here's a link.
Here's an image:
"
+ mdWithCheekyHTML = "# Title\n\nHere's a simple text in markdown.\n\nHere's a cheeky little script: "
+ mdWithCheekyHTMLExpected = "Title
Here's a simple text in markdown.
Here's a cheeky little script:
"
+ mdWithHashtagInitial = "#welcome #Hashtag"
+ mdWithHashtagInitialExpected = ""
+ mdCodeBlockWithNewlines = "some code coming up\n\n```\n\n\n\n```\nthat was some code"
+ mdCodeBlockWithNewlinesExpected = "some code coming up
\n\n\n
that was some code
"
+ mdWithFootnote = "fox mulder,fbi.[^1]\n\n[^1]: federated bureau of investigation"
+ mdWithFootnoteExpected = "fox mulder,fbi.[^1]
[^1]: federated bureau of investigation
"
+ mdWithBlockQuote = "get ready, there's a block quote coming:\n\n>line1\n>line2\n>\n>line3\n\n"
+ mdWithBlockQuoteExpected = "get ready, there's a block quote coming:
line1
line2
line3
"
+ mdHashtagAndCodeBlock = "#Hashtag\n\n```\n#Hashtag\n```"
+ mdHashtagAndCodeBlockExpected = "#Hashtag\n
"
+ mdMentionAndCodeBlock = "@the_mighty_zork\n\n```\n@the_mighty_zork\n```"
+ mdMentionAndCodeBlockExpected = "@the_mighty_zork\n
"
+ mdMentionAndCodeBlockBasicExpected = "@the_mighty_zork
@the_mighty_zork\n
"
+ mdWithSmartypants = "\"you have to quargle the bleepflorp\" they said with 1/2 of nominal speed and 1/3 of the usual glumping"
+ mdWithSmartypantsExpected = "\"you have to quargle the bleepflorp\" they said with 1/2 of nominal speed and 1/3 of the usual glumping
"
+ mdWithAsciiHeart = "hello <3 old friend <3 i loved u 3 :(( you stole my heart"
+ mdWithAsciiHeartExpected = "hello <3 old friend <3 i loved u </3 :(( you stole my heart
"
+ mdWithStrikethrough = "I have ~~mdae~~ made an error"
+ mdWithStrikethroughExpected = "I have mdae made an error
"
+ mdWithLink = "Check out this code, i heard it was written by a sloth https://github.com/superseriousbusiness/gotosocial"
+ mdWithLinkExpected = "Check out this code, i heard it was written by a sloth https://github.com/superseriousbusiness/gotosocial
"
+ mdWithLinkBasicExpected = "Check out this code, i heard it was written by a sloth https://github.com/superseriousbusiness/gotosocial"
+ mdObjectInCodeBlock = "@foss_satan@fossbros-anonymous.io this is how to mention a user\n```\n@the_mighty_zork hey bud! nice #ObjectOrientedProgramming software you've been writing lately! :rainbow:\n```\nhope that helps"
+ mdObjectInCodeBlockExpected = "@foss_satan this is how to mention a user
@the_mighty_zork hey bud! nice #ObjectOrientedProgramming software you've been writing lately! :rainbow:\n
hope that helps
"
// Hashtags can be italicized but only with *, not _.
mdItalicHashtag = "*#hashtag*"
mdItalicHashtagExpected = ""
@@ -169,6 +171,11 @@ func (suite *MarkdownTestSuite) TestParseMentionWithCodeBlock() {
suite.Equal(mdMentionAndCodeBlockExpected, formatted.HTML)
}
+func (suite *MarkdownTestSuite) TestParseMentionWithCodeBlockBasic() {
+ formatted := suite.FromMarkdownBasic(mdMentionAndCodeBlock)
+ suite.Equal(mdMentionAndCodeBlockBasicExpected, formatted.HTML)
+}
+
func (suite *MarkdownTestSuite) TestParseSmartypants() {
formatted := suite.FromMarkdown(mdWithSmartypants)
suite.Equal(mdWithSmartypantsExpected, formatted.HTML)
@@ -189,6 +196,11 @@ func (suite *MarkdownTestSuite) TestParseLink() {
suite.Equal(mdWithLinkExpected, formatted.HTML)
}
+func (suite *MarkdownTestSuite) TestParseLinkBasic() {
+ formatted := suite.FromMarkdownBasic(mdWithLink)
+ suite.Equal(mdWithLinkBasicExpected, formatted.HTML)
+}
+
func (suite *MarkdownTestSuite) TestParseObjectInCodeBlock() {
formatted := suite.FromMarkdown(mdObjectInCodeBlock)
suite.Equal(mdObjectInCodeBlockExpected, formatted.HTML)
--
cgit v1.2.3