diff --git a/internal/text/markdown.go b/internal/text/markdown.go index b512e3b0f..837f213e1 100644 --- a/internal/text/markdown.go +++ b/internal/text/markdown.go @@ -71,7 +71,9 @@ func (f *formatter) FromMarkdown(ctx context.Context, markdownText string, menti mentions: mentions, tags: tags, HTMLRenderer: *blackfriday.NewHTMLRenderer(blackfriday.HTMLRendererParameters{ - Flags: blackfriday.CommonHTMLFlags, + // same as blackfriday.CommonHTMLFlags, but with Smartypants disabled + // ref: https://github.com/superseriousbusiness/gotosocial/issues/1028 + Flags: blackfriday.UseXHTML, }), } diff --git a/internal/text/markdown_test.go b/internal/text/markdown_test.go index 31ef69eea..6b7c1032f 100644 --- a/internal/text/markdown_test.go +++ b/internal/text/markdown_test.go @@ -45,18 +45,18 @@ 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.
" + 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 :)
" 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!
"
+ withHashtagExpected = "Title
here's a simple status that uses hashtag #Hashtag!
"
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:
"
+ 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:
"
+ 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"
@@ -64,11 +64,13 @@
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
"
+ 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
"
)
type MarkdownTestSuite struct {
@@ -151,6 +153,13 @@ func (suite *MarkdownTestSuite) TestParseMentionWithCodeBlock() {
suite.Equal(mdMentionAndCodeBlockExpected, s)
}
+func (suite *MarkdownTestSuite) TestParseSmartypants() {
+ s := suite.formatter.FromMarkdown(context.Background(), mdWithSmartypants, []*gtsmodel.Mention{
+ suite.testMentions["local_user_2_mention_zork"],
+ }, nil, nil)
+ suite.Equal(mdWithSmartypantsExpected, s)
+}
+
func TestMarkdownTestSuite(t *testing.T) {
suite.Run(t, new(MarkdownTestSuite))
}