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

No figure caption with hugo-md #11478

Open
dmenne opened this issue Nov 19, 2024 · 2 comments
Open

No figure caption with hugo-md #11478

dmenne opened this issue Nov 19, 2024 · 2 comments
Assignees
Labels
bug Something isn't working crossref hugo
Milestone

Comments

@dmenne
Copy link

dmenne commented Nov 19, 2024

Bug description

Format hugo-md does not create captions, only alt-text

Steps to reproduce

---
title: Hugo Captions
format: 
  html:
    fig-height: 3
  hugo-md:
    fig-height: 2.5
---


```{r}
#| label: fig-hugo
#| echo: FALSE
#| fig-cap: "This should be a numbered caption"
plot(rnorm(100))
```

With format: html, there is a numbered caption.

```
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-hugo-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="hugo_caption_files/figure-html/fig-hugo-1.png" class="img-fluid figure-img" width="672">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-hugo-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: This should be a numbered caption
</figcaption>
</figure>
```

With format: hugo-md, there is no caption, only an alt-text.

```
<img
src="hugo_caption.markdown_strict_files/figure-markdown_strict/fig-hugo-1.png"
id="fig-hugo" alt="Figure 1: This should be a numbered caption" />`
```

Expected behavior

Hugo needs figure captions

Actual behavior

No figure captions

Your environment

No response

Quarto check output

Quarto 1.6.36

@dmenne dmenne added the bug Something isn't working label Nov 19, 2024
@dmenne
Copy link
Author

dmenne commented Nov 19, 2024

It would be possible to delegate this to a Hugo-hook (https://sebastiandedeyne.com/captioned-images-with-markdown-render-hooks-in-hugo/), but why bother because html does a nice job.

@cderv
Copy link
Collaborator

cderv commented Nov 19, 2024

I think this is something we may not be handling well for cross reference figure.

This is the markdown produced by knitr as intermediate for Quarto + Pandoc

![This should be a numbered caption](test.markdown_strict_files/figure-markdown_strict/hugo-1.png){#fig-hugo width=768}

If fig- label is not used then a caption is produced.

![This should be a numbered caption](test.markdown_strict_files/figure-markdown_strict/hugo-1.png){width=768}

leads to

<figure>
<img src="test.markdown_strict_files/figure-markdown_strict/hugo-1.png" width="768" alt="This should be a numbered caption" />
<figcaption aria-hidden="true">This should be a numbered caption</figcaption>
</figure>

So our processing is making the caption undealt with. Here is another reprex of what I think the problem is with cross ref figure for hugo-md

---
title: Hugo Captions
format: hugo-md
keep-md: true
---

::: {#fig-hugo}

![]({{< placeholder >}})

Caption
:::

This leads to only fig-alt.

<img
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAADNklEQVR4nO2WLVYrQRBGKwuADcAGYAGAwuFQ4MAEBwYcDgUKBwoHBhwoXFxUsoG4uGQBSRaQ13dyKpDAE5jJJ757zuT09E81p25XD41+vz8NI4OFiGEhYliIGBYihoWIYSFiWIgYFiKGhYhhIWJYiBgWIoaFiGEhYliIGBYihoWIYSFiWIgYFiKGhYhhIWJYiBgWIoaFiGEhYliIGBYihoWIYSFiWIgYFiKGhYhhIWJYiBgWIoaFiGEhYliIGBYihoWIsVIhvV4vtre3S+uLwWBQfiM2NzfL7xfdbjd2d3dL6+8Qc319vXoS+uC3fba2thbm1slKhJCMi4uLSkjZv/TMuL29jeFwWFoRBwcHcXx8XM29vr6uZJCsp6enPyXr9PQ0Op1OvL6+xt7eXumJeH9/j1arVVoRGxsbcXNzE+PxOM7Pz+f73N/f/5BVBysRkpycnMTb21tpRZUQ3j8/P8tbxP7+frTb7Xh4eKgSgxwSybyzs7MyY7bm4+Mjms1mwMvLSxwdHf0QRtzLy8u5kIwNh4eH1d+AIOIRmzYPUupGRginmCRwWoExEkJ1ZDKZ8/j4OF8DVBVja2trlRzWLEOsjEFV3t3dzWMQH4nsTVUyB1iTc+pESghXxdXVVXmbjZFEBOQ1tZxM4FQzl/GctwzjxCLZ7EPMjEEFck3Rl3OAyslqrRMpId9POGO0OcGZKOaQuFyTcPdPJpPqO/EbxMoY+U3KGKxtliuPw4AY5iCZ/pxTJzJCSALvnEranFDu+efn5+qdyuE05/ckyXEeksm1swxxUwgQm32ppmxzZVGBXJm0kU+7blYihI8z1UAC+LeXO5wkZz+nmATSR6I5rY1GI6bT6cK1xBjJ/i6Rdo5nPPZB5M7OTpVk+qk0+nJvoHKotNFotLBPnaxEiPk/FiKGhYhhIWJYiBgWIoaFiGEhYliIGBYihoWIYSFiWIgYFiKGhYhhIWJYiBgWIoaFiGEhYliIGBYihoWIYSFiWIgYFiKGhYhhIWJYiBgWIoaFiGEhYliIGBYihoWIYSFiWIgYFiKGhYhhIWJYiBgWIoaFiGEhYliIGBYihoWIYSFiWIgYFiLGPxfY2Bvll5LhAAAAAElFTkSuQmCC"
id="fig-hugo" alt="Figure 1: Caption" />

It is using alt and not caption. Hugo would support another syntax with HTML 5 and figcaption.

I believe this ends up like this because we do process Hugo markdown floatRefTarget specifically as Img

local el = quarto.utils.match("Plain/[1]/Image")(float.content)
if el then
local text = pandoc.write(pandoc.Pandoc({
pandoc.Image(
pandoc.utils.stringify(quarto.utils.as_inlines(float.caption_long)),
el.src,
"",
pandoc.Attr(float.identifier, {}, {}))}), "html")
-- we use "html" here because otherwise
-- Pandoc appears to not want to emit the right thing
-- when the output is inside a table
-- Pandoc is also emitting bizarre (but ultimately harmless) newline entities inside tables
-- if we add the newline here, but if we don't add newlines,
-- then images by themselves don't have line breaks after them
local result = pandoc.RawInline("html", text .. "\n")
return result
end

and not Figure with pandoc.Figure() so no Caption added by Pandoc.

Here is waht Pandoc does

  1. First is a figure, and HTML for figure is produced
  2. Second is a image, and only HTML for image is produced
❯ quarto pandoc --to gfm
![Some Text](fig-1.png){#fig-hugo}

![Some Text 2](fig-2.png){#fig-hugo2}\
^Z
<figure id="fig-hugo">
<img src="fig-1.png" alt="Some Text" />
<figcaption aria-hidden="true">Some Text</figcaption>
</figure>

<img src="fig-2.png" id="fig-hugo2" alt="Some Text 2" />

This is recent parsing change in Pandoc 3 I believe

❯ quarto pandoc --to native
![Some Text](fig-1.png){#fig-hugo}

![Some Text 2](fig-2.png){#fig-hugo2}\
^Z
[ Figure
    ( "fig-hugo" , [] , [] )
    (Caption
       Nothing [ Plain [ Str "Some" , Space , Str "Text" ] ])
    [ Plain
        [ Image
            ( "" , [] , [] )
            [ Str "Some" , Space , Str "Text" ]
            ( "fig-1.png" , "" )
        ]
    ]
, Para
    [ Image
        ( "fig-hugo2" , [] , [] )
        [ Str "Some" , Space , Str "Text" , Space , Str "2" ]
        ( "fig-2.png" , "" )
    , LineBreak
    ]
]

So we could probably adapt Quarto output for Hugo, as floatreftarget should probably output as a figure with caption.

@cderv cderv added this to the v1.7 milestone Nov 19, 2024
@cscheid cscheid self-assigned this Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working crossref hugo
Projects
None yet
Development

No branches or pull requests

3 participants