From 5fbaf5b7bec6f59bb868dd8b76a90c1bbd2986b5 Mon Sep 17 00:00:00 2001 From: tobi Date: Mon, 30 Jun 2025 12:56:50 +0200 Subject: [feature] Allow anchor href to work for footnotes, use ID prefix to avoid clashes (#4298) Updates markdown parser + sanitizer to allow footnote anchors to work properly, with appropriate roles. Footnote anchor IDs and backrefs use the status ID as a prefix to avoid clashes, so that footnotes don't break when multiple footnoted statuses are rendered on the same page (eg., in a thread or on the account's home page). closes https://codeberg.org/superseriousbusiness/gotosocial/issues/4296 Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4298 Co-authored-by: tobi Co-committed-by: tobi --- internal/text/markdown_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'internal/text/markdown_test.go') diff --git a/internal/text/markdown_test.go b/internal/text/markdown_test.go index 347ca2928..14578398d 100644 --- a/internal/text/markdown_test.go +++ b/internal/text/markdown_test.go @@ -61,7 +61,9 @@ const ( mdCodeBlockWithNewlines = "some code coming up\n\n```\n\n\n\n```\nthat was some code" mdCodeBlockWithNewlinesExpected = "

some code coming up

\n\n\n

that was some code

" mdWithFootnote = "fox mulder,fbi.[^1]\n\n[^1]: federated bureau of investigation" - mdWithFootnoteExpected = "

fox mulder,fbi.1


  1. federated bureau of investigation ↩︎

" + mdWithFootnoteExpected = "

fox mulder,fbi.1


  1. federated bureau of investigation ↩︎

" + mdWithAttemptedRelative = "hello this is a cheeky relative link: click it!" + mdWithAttemptedRelativeExpected = "

hello this is a cheeky relative link: click it!

" 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

" mdHashtagAndCodeBlock = "#Hashtag\n\n```\n#Hashtag\n```" @@ -156,6 +158,11 @@ func (suite *MarkdownTestSuite) TestParseWithFootnote() { suite.Equal(mdWithFootnoteExpected, formatted.HTML) } +func (suite *MarkdownTestSuite) TestParseWithAttemptedRelative() { + formatted := suite.FromMarkdown(mdWithAttemptedRelative) + suite.Equal(mdWithAttemptedRelativeExpected, formatted.HTML) +} + func (suite *MarkdownTestSuite) TestParseWithBlockquote() { formatted := suite.FromMarkdown(mdWithBlockQuote) suite.Equal(mdWithBlockQuoteExpected, formatted.HTML) -- cgit v1.2.3