From d22b0160a6ca4a5226c30cff95a44e7cd66b5c8f Mon Sep 17 00:00:00 2001 From: Norwin Date: Mon, 21 Nov 2022 14:23:56 +0100 Subject: [PATCH 1/3] [enhancement] markdown: disable SmartyPantsFractions fixes #1028 --- internal/text/markdown.go | 4 +++- internal/text/markdown_test.go | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/text/markdown.go b/internal/text/markdown.go index b512e3b0f8..3d7b516b75 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 SmartypantsFractions disabled + // ref: https://github.com/superseriousbusiness/gotosocial/issues/1028 + Flags: blackfriday.UseXHTML | blackfriday.Smartypants | blackfriday.SmartypantsDashes | blackfriday.SmartypantsLatexDashes, }), } diff --git a/internal/text/markdown_test.go b/internal/text/markdown_test.go index 31ef69eea7..d9af44b823 100644 --- a/internal/text/markdown_test.go +++ b/internal/text/markdown_test.go @@ -69,6 +69,8 @@ const ( mdHashtagAndCodeBlockExpected = "

#Hashtag

#Hashtag\n
" mdMentionAndCodeBlock = "@the_mighty_zork\n\n```\n@the_mighty_zork\n```" mdMentionAndCodeBlockExpected = "

@the_mighty_zork

@the_mighty_zork\n
" + mdWithSmartypants = "\"you have to quargle the bleepflorp\" they said with 1/3 of nominal speed" + mdWithSmartypantsExpected = "

“you have to quargle the bleepflorp” they said with 1/3 of nominal speed

" ) 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)) } From 963c77914c7a2f46d3b22948367c0d59d834ad9c Mon Sep 17 00:00:00 2001 From: Norwin Date: Mon, 21 Nov 2022 14:36:40 +0100 Subject: [PATCH 2/3] some fractions are still converted to unicode to fix that, we might need to disable smartypants indeed in its entirety --- internal/text/markdown_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/text/markdown_test.go b/internal/text/markdown_test.go index d9af44b823..1b4a8d5110 100644 --- a/internal/text/markdown_test.go +++ b/internal/text/markdown_test.go @@ -69,8 +69,8 @@ const ( mdHashtagAndCodeBlockExpected = "

#Hashtag

#Hashtag\n
" mdMentionAndCodeBlock = "@the_mighty_zork\n\n```\n@the_mighty_zork\n```" mdMentionAndCodeBlockExpected = "

@the_mighty_zork

@the_mighty_zork\n
" - mdWithSmartypants = "\"you have to quargle the bleepflorp\" they said with 1/3 of nominal speed" - mdWithSmartypantsExpected = "

“you have to quargle the bleepflorp” they said with 1/3 of nominal speed

" + 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 { From e3c90ab7b48a6d2d3f1614bea2a657decc96bc0a Mon Sep 17 00:00:00 2001 From: Norwin Date: Mon, 21 Nov 2022 14:37:21 +0100 Subject: [PATCH 3/3] disable smartypants completely for lack of a better simple solution --- internal/text/markdown.go | 4 ++-- internal/text/markdown_test.go | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/text/markdown.go b/internal/text/markdown.go index 3d7b516b75..837f213e16 100644 --- a/internal/text/markdown.go +++ b/internal/text/markdown.go @@ -71,9 +71,9 @@ func (f *formatter) FromMarkdown(ctx context.Context, markdownText string, menti mentions: mentions, tags: tags, HTMLRenderer: *blackfriday.NewHTMLRenderer(blackfriday.HTMLRendererParameters{ - // same as blackfriday.CommonHTMLFlags, but with SmartypantsFractions disabled + // same as blackfriday.CommonHTMLFlags, but with Smartypants disabled // ref: https://github.com/superseriousbusiness/gotosocial/issues/1028 - Flags: blackfriday.UseXHTML | blackfriday.Smartypants | blackfriday.SmartypantsDashes | blackfriday.SmartypantsLatexDashes, + Flags: blackfriday.UseXHTML, }), } diff --git a/internal/text/markdown_test.go b/internal/text/markdown_test.go index 1b4a8d5110..6b7c1032fd 100644 --- a/internal/text/markdown_test.go +++ b/internal/text/markdown_test.go @@ -45,18 +45,18 @@ that was some JSON :) const ( simpleMarkdown = "# Title\n\nHere's a simple text in markdown.\n\nHere's a [link](https://example.org)." - simpleMarkdownExpected = "

Title

Here’s a simple text in markdown.

Here’s a link.

" + simpleMarkdownExpected = "

Title

Here's a simple text in markdown.

Here's a link.

" withCodeBlockExpected = "

Title

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 the SECRET CODE, do they?`" withInlineCodeExpected = "

Nobody tells you about the <code><del>SECRET CODE</del></code>, do they?

" withInlineCode2 = "`Nobody tells you about the SECRET CODE, 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: \"The" - mdWithHTMLExpected = "

Title

Here’s a simple text in markdown.

Here’s a link.

Here’s an image: \"The

" + mdWithHTMLExpected = "

Title

Here's a simple text in markdown.

Here's a link.

Here's an image: \"The

" 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 = "

#welcome #Hashtag

" mdCodeBlockWithNewlines = "some code coming up\n\n```\n\n\n\n```\nthat was some code" @@ -64,13 +64,13 @@ const ( 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

#Hashtag\n
" mdMentionAndCodeBlock = "@the_mighty_zork\n\n```\n@the_mighty_zork\n```" mdMentionAndCodeBlockExpected = "

@the_mighty_zork

@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

" + 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 {