From 536d9e482d4ebc012855372b9fcfa4f022d1618a Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Fri, 29 Sep 2023 10:39:56 +0200 Subject: [chore/bugfix] Deinterface text.Formatter, allow underscores in hashtags (#2233) --- internal/text/markdown_test.go | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'internal/text/markdown_test.go') diff --git a/internal/text/markdown_test.go b/internal/text/markdown_test.go index cc466df6c..98ed3a96b 100644 --- a/internal/text/markdown_test.go +++ b/internal/text/markdown_test.go @@ -76,10 +76,16 @@ const ( mdWithLinkExpected = "
Check out this code, i heard it was written by a sloth https://github.com/superseriousbusiness/gotosocial
" mdObjectInCodeBlock = "@foss_satan@fossbros-anonymous.io this is how to mention a user\n```\n@the_mighty_zork hey bud! nice #ObjectOrientedProgramming software you've been writing lately! :rainbow:\n```\nhope that helps" mdObjectInCodeBlockExpected = "@foss_satan this is how to mention a user
@the_mighty_zork hey bud! nice #ObjectOrientedProgramming software you've been writing lately! :rainbow:\n
hope that helps
" - mdItalicHashtag = "_#hashtag_" - mdItalicHashtagExpected = "" - mdItalicHashtags = "_#hashtag #hashtag #hashtag_" - mdItalicHashtagsExpected = "" + // Hashtags can be italicized but only with *, not _. + mdItalicHashtag = "*#hashtag*" + mdItalicHashtagExpected = "" + mdItalicHashtags = "*#hashtag #hashtag #hashtag*" + mdItalicHashtagsExpected = "" + // Hashtags can end with or contain _ but not start with it. + mdUnderscorePrefixHashtag = "_#hashtag" + mdUnderscorePrefixHashtagExpected = "_#hashtag
" + mdUnderscoreSuffixHashtag = "#hashtag_" + mdUnderscoreSuffixHashtagExpected = "" // BEWARE: sneaky unicode business going on. // the first ö is one rune, the second ö is an o with a combining diacritic. mdUnnormalizedHashtag = "#hellöthere #hellöthere" @@ -194,6 +200,19 @@ func (suite *MarkdownTestSuite) TestParseItalicHashtags() { suite.Equal(mdItalicHashtagsExpected, formatted.HTML) } +func (suite *MarkdownTestSuite) TestParseHashtagUnderscorePrefix() { + formatted := suite.FromMarkdown(mdUnderscorePrefixHashtag) + suite.Equal(mdUnderscorePrefixHashtagExpected, formatted.HTML) + suite.Empty(formatted.Tags) +} + +func (suite *MarkdownTestSuite) TestParseHashtagUnderscoreSuffix() { + formatted := suite.FromMarkdown(mdUnderscoreSuffixHashtag) + suite.Equal(mdUnderscoreSuffixHashtagExpected, formatted.HTML) + suite.NotEmpty(formatted.Tags) + suite.Equal("hashtag_", formatted.Tags[0].Name) +} + func (suite *MarkdownTestSuite) TestParseUnnormalizedHashtag() { formatted := suite.FromMarkdown(mdUnnormalizedHashtag) suite.Equal(mdUnnormalizedHashtagExpected, formatted.HTML) -- cgit v1.2.3