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

Figure captions: HTML (and markdown) not getting rendered #535

Closed
kaushalmodi opened this issue Jan 18, 2022 · 4 comments
Closed

Figure captions: HTML (and markdown) not getting rendered #535

kaushalmodi opened this issue Jan 18, 2022 · 4 comments
Labels
not a bug This is the expected behavior, not a bug

Comments

@kaushalmodi
Copy link
Owner

I don't know if this is the right place to mention this, but using latest ox-hugo with figure captions, HTML markup in the captions are rendered encoded, e.g.:

<figcaption>
          <p>&lt;span class=&#34;figure-number&#34;&gt;Figure 1: &lt;/span&gt;Mom and Dad (1971)</p>
</figcaption>

This is from the following Org content:

#+caption: Mom and Dad (1971)
[[/img/2022/20220118-MomDadDressup.jpg]]

The Markdown renders as:

{{< figure src="/img/2022/20220118-MomDadDressup.jpg" caption="<span class=\"figure-number\">Figure 1: </span>Mom and Dad (1971)" >}}

I'm running latest doom emacs with unpinned ox-hugo and Hugo v0.92.0+extended. Let me know if there's a better place for this or if I'm missing something. Thanks.

Originally posted by @jackbaty in #321 (comment)

@kaushalmodi
Copy link
Owner Author

@jackbaty I will need more details.

The test page is exporting alright:

Looking at the HTML source of that test page, the HTML inside the captions looks good:

    <p>Some text before image.</p>
<figure><img src="https://ox-hugo.scripter.co/test/images/org-mode-unicorn-logo.png"
         alt="Figure 1: A unicorn! &amp;ldquo;Something in double quotes&amp;rdquo;"/><figcaption>
            <p><span class="figure-number">Figure 1: </span>A unicorn! &ldquo;Something in double quotes&rdquo;</p>
        </figcaption>
</figure>

<p>Some more text, after image.</p>
<figure><img src="https://ox-hugo.scripter.co/test/images/org-mode-unicorn-logo.png"
         alt="Figure 2: The same figure again, testing a link too!"/><figcaption>
            <p><span class="figure-number">Figure 2: </span>The <em>same</em> figure <strong>again</strong>, testing <a href="https://ox-hugo.scripter.co">a link</a> too!</p>
        </figcaption>
</figure>

The test site is using Hugo v0.92.0 (regular version, not extended).


Do you happen to have a custom figure shortcode in your theme that's overriding the default figure shortcode?

@kaushalmodi kaushalmodi added the cannot reproduce issue The issue reported by the OP cannot be reproduce in tests label Jan 18, 2022
@kaushalmodi
Copy link
Owner Author

kaushalmodi commented Jan 18, 2022

@jackbaty

Do you happen to have a custom figure shortcode in your theme that's overriding the default figure shortcode?

Looks like it.


Replace this line:

https://github.com/jackbaty/daily-jane/blob/73d9c6d964003f50e9c38fb010bbb9372309c204/layouts/shortcodes/figure.html#L24

with

{{ .Get "caption" | markdownify }}

.. and the same for "attr":

{{ .Get "attr" | markdownify }}

@kaushalmodi
Copy link
Owner Author

Coincidentally, I was involved this fixing the default figure shortcode in Hugo to allow rendering of HTML in "caption" and "attr" more than (gasp!) 3 years back! -> gohugoio/hugo#5276

So I kind of guessed quickly what was going on with this issue 😄 .

@kaushalmodi kaushalmodi changed the title Figure captions are exported with angle brackets encoded as HTML entities Figure captions: HTML (and markdown) not getting rendered Jan 18, 2022
@kaushalmodi kaushalmodi added not a bug This is the expected behavior, not a bug and removed cannot reproduce issue The issue reported by the OP cannot be reproduce in tests labels Jan 18, 2022
@jackbaty
Copy link

Oh my, I'd forgotten I was using a custom shortcode. Sorry for the noise. You're right, calling markdownify on those elements takes care of the problem. Thank you much!

jackbaty added a commit to jackbaty/daily-jane that referenced this issue Jan 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not a bug This is the expected behavior, not a bug
Projects
None yet
Development

No branches or pull requests

2 participants