mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-10-31 22:40:01 +00: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
|
// format mentions nicely
|
||||||
content = f.ReplaceMentions(ctx, content, mentions)
|
content = f.ReplaceMentions(ctx, content, mentions)
|
||||||
|
|
||||||
return postformat(content)
|
return SanitizeHTML(content)
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,30 +20,13 @@
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
var withCodeBlock = `# Title
|
||||||
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
|
|
||||||
|
|
||||||
Below is some JSON.
|
Below is some JSON.
|
||||||
|
|
||||||
|
@ -59,6 +42,17 @@
|
||||||
|
|
||||||
that was 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 {
|
type MarkdownTestSuite struct {
|
||||||
|
@ -71,11 +65,20 @@ func (suite *MarkdownTestSuite) TestParseSimple() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *MarkdownTestSuite) TestParseWithCodeBlock() {
|
func (suite *MarkdownTestSuite) TestParseWithCodeBlock() {
|
||||||
fmt.Println(withCodeBlock)
|
|
||||||
s := suite.formatter.FromMarkdown(context.Background(), withCodeBlock, nil, nil)
|
s := suite.formatter.FromMarkdown(context.Background(), withCodeBlock, nil, nil)
|
||||||
suite.Equal(withCodeBlockExpected, s)
|
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() {
|
func (suite *MarkdownTestSuite) TestParseWithHashtag() {
|
||||||
foundTags := []*gtsmodel.Tag{
|
foundTags := []*gtsmodel.Tag{
|
||||||
suite.testTags["Hashtag"],
|
suite.testTags["Hashtag"],
|
||||||
|
|
Loading…
Reference in a new issue