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

'Implicit figures' does not fire inside footnotes without a block following the image (for final image blocks) #7006

Closed
gwern opened this issue Jan 5, 2021 · 1 comment

Comments

@gwern
Copy link
Contributor

gwern commented Jan 5, 2021

Implicit figures does not operate inside footnote blocks as expected. We've discovered a number of footnotes on gwern.net aren't getting <figure>-styled as expected & are screwed up because Pandoc renders them as <img> elements, despite being written the same way as any other figure-image is. The culprit seems to be that the footnotes include the image as the last block element, and this somehow does not trigger the implicit figure functionality.

An example: the basic image format works, and works inside a block footnote as long as there is any block element after the image (blockquotes, source code, text paragraphs, all seem fine). The exact same footnote, minus the trailing text, fails.

![Caption.](/image.jpg)

Test.[^footnote1][^footnote2]

[^footnote1]: Foo:

    ![Caption.](/image.jpg)

    Bar.

[^footnote2]: Foo:

    ![Caption.](/image.jpg)

renders as

<article>
  <figure>
  <img src="/image.jpg" alt="" /><figcaption>Caption.</figcaption>
  </figure>
  <p>Test.<a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a><a href="#fn2" class="footnote-ref" id="fnref2" role="doc-noteref"><sup>2</sup></a></p>
  <section class="footnotes" role="doc-endnotes">
  <hr />
  <ol>
  <li id="fn1" role="doc-endnote"><p>Foo:</p>
  <figure>
  <img src="/image.jpg" alt="" /><figcaption>Caption.</figcaption>
  </figure>
  <p>Bar.<a href="#fnref1" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
  <li id="fn2" role="doc-endnote"><p>Foo:</p>
  <p><img src="/image.jpg" title="fig:" alt="Caption." /><a href="#fnref2" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
  </ol>
  </section>
</article>

The first is correct and the second is wrong.

I don't see anything in the HTML <figure> standard discouraging use, and the mention of asides seems exactly like my usecase, and the Pandoc doc says only

An image with nonempty alt text, occurring by itself in a paragraph, will be rendered as a figure with a caption.

And my example clearly fulfills that description: it is inside a <p></p> paragraph, by itself, with no other elements. So this looks like a bug in the Pandoc logic where it makes some sort of assumption that 'by itself' means another block element follows the paragraph.

@gwern gwern changed the title 'Implicit figures' does not fire inside footnotes without a final block 'Implicit figures' does not fire inside footnotes without a block following the image (for final image blocks) Jan 5, 2021
@jgm
Copy link
Owner

jgm commented Jan 5, 2021

I see what is causing this:

blockListToNote opts ref blocks = do
  ...
  -- If last block is Para or Plain, include the backlink at the end of
  -- that block. Otherwise, insert a new Plain block with the backlink.

We include the backlink at the end of the block before processing it with blockToHtml. But that means that when it gets to blockToHtml, it's no longer an image alone in a Para, so implicit figure does not get triggered.

@jgm jgm closed this as completed in 15ba184 Jan 5, 2021
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