diff --git a/internal/text/markdown.go b/internal/text/markdown.go index be094afd2..01238954f 100644 --- a/internal/text/markdown.go +++ b/internal/text/markdown.go @@ -37,5 +37,5 @@ func (f *formatter) FromMarkdown(ctx context.Context, md string, mentions []*gts // format mentions nicely content = f.ReplaceMentions(ctx, content, mentions) - return postformat(content) + return SanitizeHTML(content) } diff --git a/internal/text/markdown_test.go b/internal/text/markdown_test.go index e086f14f7..111cfe473 100644 --- a/internal/text/markdown_test.go +++ b/internal/text/markdown_test.go @@ -20,30 +20,13 @@ package text_test import ( "context" - "fmt" "testing" "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) -const ( - simpleMarkdown = `# Title - -Here's a simple text in markdown. - -Here'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}\n
that was some JSON :)
" - - withHashtag = "# Title\n\nhere's a simple status that uses hashtag #Hashtag!" - withHashtagExpected = "here’s a simple status that uses hashtag #Hashtag!
" -) - -var ( - withCodeBlock = `# Title +var withCodeBlock = `# Title Below is some JSON. @@ -59,6 +42,17 @@ Below is some JSON. 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.
\n\nHere’s a link.
\n" + withCodeBlockExpected = "Below is some JSON.
\n\n{\n "key": "value",\n "another_key": [\n "value1",\n "value2"\n ]\n}\n
\n\nthat was some JSON :)
\n" + 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?
\n"
+ withHashtag = "# Title\n\nhere's a simple status that uses hashtag #Hashtag!"
+ withHashtagExpected = "Title
\n\nhere’s a simple status that uses hashtag #Hashtag!
\n"
)
type MarkdownTestSuite struct {
@@ -71,11 +65,20 @@ func (suite *MarkdownTestSuite) TestParseSimple() {
}
func (suite *MarkdownTestSuite) TestParseWithCodeBlock() {
- fmt.Println(withCodeBlock)
s := suite.formatter.FromMarkdown(context.Background(), withCodeBlock, nil, nil)
suite.Equal(withCodeBlockExpected, s)
}
+func (suite *MarkdownTestSuite) TestParseWithInlineCode() {
+ s := suite.formatter.FromMarkdown(context.Background(), withInlineCode, nil, nil)
+ suite.Equal(withInlineCodeExpected, s)
+}
+
+func (suite *MarkdownTestSuite) TestParseWithInlineCode2() {
+ s := suite.formatter.FromMarkdown(context.Background(), withInlineCode2, nil, nil)
+ suite.Equal(withInlineCode2Expected, s)
+}
+
func (suite *MarkdownTestSuite) TestParseWithHashtag() {
foundTags := []*gtsmodel.Tag{
suite.testTags["Hashtag"],