summaryrefslogtreecommitdiff
path: root/internal/text/markdown_test.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-07-19 10:41:16 +0200
committerLibravatar GitHub <noreply@github.com>2022-07-19 10:41:16 +0200
commit59be7466f365266bb643e2f5b6b9ce2c4701b945 (patch)
treeba15b2019a0bb9c5fda7fcb275a0473d773e4a99 /internal/text/markdown_test.go
parent[feature] Implement `cache-control` and etags for static assets (#711) (diff)
downloadgotosocial-59be7466f365266bb643e2f5b6b9ce2c4701b945.tar.xz
[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!
Diffstat (limited to 'internal/text/markdown_test.go')
-rw-r--r--internal/text/markdown_test.go41
1 files changed, 22 insertions, 19 deletions
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 = "<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 &#34;key&#34;: &#34;value&#34;,\n &#34;another_key&#34;: [\n &#34;value1&#34;,\n &#34;value2&#34;\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 &lt;code&gt;&lt;del&gt;SECRET CODE&lt;/del&gt;&lt;/code&gt;, 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 &lt;/code&gt;&lt;del&gt;SECRET CODE&lt;/del&gt;&lt;code&gt;, 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"],