footnotes icon indicating copy to clipboard operation
footnotes copied to clipboard

Links within footnotes break the footnote

Open amphibian opened this issue 8 months ago • 9 comments

Describe the bug

When adding links to footnote text, either before or after creating the footnote (turning it into a <sup> element), the links is wrapped in its own <sup>, and any text before and after is wrapped in their own <sup> elements.

Steps to reproduce

  1. Add a link to part of a string which you want to turn into a footnote.
  2. Turn that text into a footnote.

Craft CMS version

5.7.1.1

Plugin version

5.1.0

Multi-site?

No

Additional context

No response

amphibian avatar May 21 '25 15:05 amphibian

I'll see what can be done about this, but I believe it's largely due to how CKEditor handles the sup element and other tags like an anchor tag. Secondly, it's also a little tricky in that footnotes are themselves considered to be links.

We're probably going to have to revise how the footnotes are handled anyway to address this. Rather than relying on using a <sup> element, it'll probably end up being similar to a link node where you can add whatever content you like.

engram-design avatar May 21 '25 22:05 engram-design

Thanks for the explanation Josh, sounds tricky. It's too bad CKE handles things so differently, as I was using links inside footnotes without issues in the Redactor version.

amphibian avatar May 22 '25 12:05 amphibian

Just discovered on a current project that any inline markup breaks the footnote in the same manner (e.g. bold, italics, etc). Given that things like publication titles are frequently inside footnote/endnote content, and those are routinely italicized, this issue is wreaking more havoc on me than I thought!

amphibian avatar May 27 '25 16:05 amphibian

Yeah, I'll need to figure this one out sooner rather than later, and rethink my approach. Will keep you posted (just not going to be a quick fix!)

engram-design avatar May 27 '25 21:05 engram-design

Ran into this too. For now, I chose the nuclear option – a regex that unwraps the <sup class="footnote"> elements:

$html = preg_replace_callback(
    '#<(\w+)[^>]*>\s*(<sup\s+class="footnote">.*?</sup>)\s*</\1>#i',
    function ($matches) {
        return $matches[2];
    },
    $html
);

mmikkel avatar Jun 27 '25 20:06 mmikkel

Hi, was there any update on this? Have also just run into the same issue

d-karstens avatar Jul 31 '25 06:07 d-karstens

Haven't had the chance to look at this, but it's essentially a brand-new implementation I need to look at.

engram-design avatar Jul 31 '25 14:07 engram-design

For others following, the route I've decided on for now is to instruct my clients to use markdown for formatting within each footnote, and then I apply the markdown filter to the footnotes in-template.

amphibian avatar Jul 31 '25 14:07 amphibian

Just noting that we recently discovered this is impacting a client site as well. Looking forward to a resolution.

AdamChlan avatar Aug 04 '25 14:08 AdamChlan