Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Footnotes in links are broken #249

Closed
wooorm opened this issue Dec 6, 2021 · 2 comments
Closed

Footnotes in links are broken #249

wooorm opened this issue Dec 6, 2021 · 2 comments

Comments

@wooorm
Copy link

wooorm commented Dec 6, 2021

[a [^b] c](https://example.com)

[^b]: asd

Renders (formatted w/ whitespace):

<p dir="auto">
  <a href="https://example.com">
    a
    <sup></sup>
  </a>
  <a
    href="#user-content-fn-b"
    id="user-content-fnref-b"
    data-footnote-ref=""
    aria-describedby="footnote-label"
  >1</a>
  c
</p>

Rendered here:

a 1 c


Expected. Either (when not using HTML parsing to sanitize):

<p>
  <a href="https://example.com">
    a
    <sup>
      <a
        href="#user-content-fn-b"
        id="user-content-fnref-b"
        data-footnote-ref=""
        aria-describedby="footnote-label"
      >1</a>
    </sup>
    c
  </a>
</p>

Or (when not generating footnotes in certain disallowed tags):

<p>
  <a href="https://example.com">
    a [^b] c
  </a>
</p>

Footnotes

  1. asd

@phillmv
Copy link
Member

phillmv commented Jan 4, 2022

You can't have nested anchor tags, so this one is on your browser.1

Footnotes

  1. if you examine the output in cmark-gfm, you'll find the library does in fact nest the links 😉.

@phillmv phillmv closed this as completed Jan 4, 2022
@wooorm
Copy link
Author

wooorm commented Aug 23, 2022

Yes, it is invalid.

CommonMark/GFM enforces logic to prevent it: it doesn’t allow what could be a link, when occurring around a link.
This is not the case for images, because images are fine in link.
Given that footnotes calls are similar to link labels, and implemented in the same code, why not implement the existing logic for links, too?

cmark-gfm/src/inlines.c

Lines 1242 to 1257 in ef1cfcb

// Now, if we have a link, we also want to deactivate earlier link
// delimiters. (This code can be removed if we decide to allow links
// inside links.)
if (!is_image) {
opener = subj->last_bracket;
while (opener != NULL) {
if (!opener->image) {
if (!opener->active) {
break;
} else {
opener->active = false;
}
}
opener = opener->previous;
}
}

if (!opener->active) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants