summaryrefslogtreecommitdiff
path: root/internal/text/markdown.go
diff options
context:
space:
mode:
authorLibravatar tobi <tobi.smethurst@protonmail.com>2025-06-30 12:56:50 +0200
committerLibravatar kim <gruf@noreply.codeberg.org>2025-06-30 12:56:50 +0200
commit5fbaf5b7bec6f59bb868dd8b76a90c1bbd2986b5 (patch)
tree5003d30e1152d491840ef0a3ef7c2e2b69257742 /internal/text/markdown.go
parent[bugfix] fix issues with postgres array serialization (#4295) (diff)
downloadgotosocial-5fbaf5b7bec6f59bb868dd8b76a90c1bbd2986b5.tar.xz
[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 <tobi.smethurst@protonmail.com> Co-committed-by: tobi <tobi.smethurst@protonmail.com>
Diffstat (limited to 'internal/text/markdown.go')
-rw-r--r--internal/text/markdown.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/internal/text/markdown.go b/internal/text/markdown.go
index e4b633e75..8486d6935 100644
--- a/internal/text/markdown.go
+++ b/internal/text/markdown.go
@@ -24,6 +24,7 @@ import (
"strings"
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
+ "code.superseriousbusiness.org/gotosocial/internal/id"
"code.superseriousbusiness.org/gotosocial/internal/log"
"code.superseriousbusiness.org/gotosocial/internal/regexes"
"codeberg.org/gruf/go-byteutil"
@@ -118,6 +119,18 @@ func (f *Formatter) fromMarkdown(
}
}
+ // Inject a footnote ID prefix to avoid
+ // footnote ID clashes. StatusID isn't
+ // always set (eg., when parsing instance
+ // description markdown), so take a random
+ // ULID if it's not.
+ var footnoteIDPrefix string
+ if statusID != "" {
+ footnoteIDPrefix = statusID + "-"
+ } else {
+ footnoteIDPrefix = id.NewULID() + "-"
+ }
+
// Instantiate goldmark parser for
// markdown, using custom renderer
// to add hashtag/mention links.
@@ -141,7 +154,9 @@ func (f *Formatter) fromMarkdown(
extension.NewLinkify(
extension.WithLinkifyURLRegexp(regexes.URLLike),
),
- extension.Footnote,
+ extension.NewFootnote(
+ extension.WithFootnoteIDPrefix(footnoteIDPrefix),
+ ),
extension.Strikethrough,
),
)