Skip to content

Conversation

peterbozso
Copy link
Contributor

Right now the library creates a <figure> element even when an image doesn't have caption.

For example this:

Following image is without caption:

![Alt text](https://example.com/image.jpg)

So this won't be a figure.

Will be turned into this:

<p>Following image is without caption:</p>
<figure><img src="https://example.com/image.jpg" alt="Alt text"></figure>
<p>So this won't be a figure.</p>

This is a problem in real life for websites like the "About" page of my blog:

  1. HTML
  2. Markdown

As can be seen here, the image link is to my profile picture, standing on it's own, which I definitely don't want to turn into a <figure>.

This PR fixes this by not adding a <figure> element when there's no text right after the imagine in Markdown. Please refer to the newly addedd test to see it in action.

@peterbozso
Copy link
Contributor Author

Also (not to bloat the PR description): thank you @yilei for this nice library! It helps a lot.

@yilei
Copy link
Contributor

yilei commented May 11, 2025

Thanks for the PR, I'm glad you find this extension useful!

I used standalone images without captions on my site, i.e. relying on the current behavior.

Instead of changing the default, could you please make this an option to opt-in? The WithImageLink() function is a prior art.

Thanks!

@peterbozso
Copy link
Contributor Author

Thanks for the feedback @yilei - it's done!

@yilei yilei self-requested a review May 14, 2025 03:15
@yilei
Copy link
Contributor

yilei commented May 14, 2025

Thanks for making the changes! I made a small tweak to the if statement. Merging.

@yilei yilei merged commit 2316551 into mangoumbrella:main May 14, 2025
3 checks passed
@yilei
Copy link
Contributor

yilei commented May 14, 2025

@peterbozso
Copy link
Contributor Author

Cool, thanks! :)

@peterbozso peterbozso deleted the no-caption branch July 13, 2025 05:48
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

Successfully merging this pull request may close these issues.

2 participants