mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 20:22:26 -05:00
[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>
This commit is contained in:
parent
39b11dbfb6
commit
5fbaf5b7be
3 changed files with 38 additions and 5 deletions
|
|
@ -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,
|
||||
),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue