mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-21 16:55:38 +03:00
[bugfix] Markdown format fixes (#718)
* just sanitize markdown, don't minify or escape * tidy tests, add one for inline code * add another test, it works!
This commit is contained in:
parent
c3b6a5b0f9
commit
59be7466f3
2 changed files with 23 additions and 20 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 = "<h1>Title</h1><p>Here’s a simple text in markdown.</p><p>Here’s a <a href=\"https://example.org\" rel=\"nofollow noreferrer noopener\" target=\"_blank\">link</a>.</p>"
|
||||
|
||||
withCodeBlockExpected = "<h1>Title</h1><p>Below is some JSON.</p><pre><code class=\"language-json\">{\n \"key\": \"value\",\n \"another_key\": [\n \"value1\",\n \"value2\"\n ]\n}\n</code></pre><p>that was some JSON :)</p>"
|
||||
|
||||
withHashtag = "# Title\n\nhere's a simple status that uses hashtag #Hashtag!"
|
||||
withHashtagExpected = "<h1>Title</h1><p>here’s a simple status that uses hashtag <a href=\"http://localhost:8080/tags/Hashtag\" class=\"mention hashtag\" rel=\"tag nofollow noreferrer noopener\" target=\"_blank\">#<span>Hashtag</span></a>!</p>"
|
||||
)
|
||||
|
||||
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 = "<h1>Title</h1>\n\n<p>Here’s a simple text in markdown.</p>\n\n<p>Here’s a <a href=\"https://example.org\" rel=\"nofollow noreferrer noopener\" target=\"_blank\">link</a>.</p>\n"
|
||||
withCodeBlockExpected = "<h1>Title</h1>\n\n<p>Below is some JSON.</p>\n\n<pre><code class=\"language-json\">{\n "key": "value",\n "another_key": [\n "value1",\n "value2"\n ]\n}\n</code></pre>\n\n<p>that was some JSON :)</p>\n"
|
||||
withInlineCode = "`Nobody tells you about the <code><del>SECRET CODE</del></code>, do they?`"
|
||||
withInlineCodeExpected = "<p><code>Nobody tells you about the <code><del>SECRET CODE</del></code>, do they?</code></p>\n"
|
||||
withInlineCode2 = "`Nobody tells you about the </code><del>SECRET CODE</del><code>, do they?`"
|
||||
withInlineCode2Expected = "<p><code>Nobody tells you about the </code><del>SECRET CODE</del><code>, do they?</code></p>\n"
|
||||
withHashtag = "# Title\n\nhere's a simple status that uses hashtag #Hashtag!"
|
||||
withHashtagExpected = "<h1>Title</h1>\n\n<p>here’s a simple status that uses hashtag <a href=\"http://localhost:8080/tags/Hashtag\" class=\"mention hashtag\" rel=\"tag nofollow noreferrer noopener\" target=\"_blank\">#<span>Hashtag</span></a>!</p>\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"],
|
||||
|
|
Loading…
Reference in a new issue