Markdown image inside HTML figure element not transformed #167

Closed
opened 2026-01-29 14:29:20 +00:00 by claunia · 2 comments
Owner

Originally created by @follesoe on GitHub (Dec 3, 2017).

I'm migrating to markdig from https://github.com/hey-red/Markdown, and have run into an issue. Much of my content comes from a headless CMS, where the images are inserted using the editor, and then wrapped manually in a <figure> element. I see that markdig has a markdown figure-extension, but since I have so much existing content in this format, and the hey-red/Markdown lib (v.2.2.0) supports this syntax, I'm reporting this in case it is a bug.

string fig = "<figure>![Alt Text](https://site.com/image.jpg)</figure>";
string noFig = "![Alt Text](https://site.com/image.jpg)";

var outputFig = Markdown.ToHtml(fig);
var outputNoFig = Markdown.ToHtml(noFig);

Console.WriteLine(outputFig);
Console.WriteLine(outputNoFig);

Outputs the following:

<figure>![Alt Text](https://site.com/image.jpg)</figure>
<p><img src="https://site.com/image.jpg" alt="Alt Text" /></p>

Is this expected behavior or a bug?

Originally created by @follesoe on GitHub (Dec 3, 2017). I'm migrating to markdig from https://github.com/hey-red/Markdown, and have run into an issue. Much of my content comes from a headless CMS, where the images are inserted using the editor, and then wrapped manually in a `<figure>` element. I see that markdig has a markdown figure-extension, but since I have so much existing content in this format, and the hey-red/Markdown lib (v.2.2.0) supports this syntax, I'm reporting this in case it is a bug. ```csharp string fig = "<figure>![Alt Text](https://site.com/image.jpg)</figure>"; string noFig = "![Alt Text](https://site.com/image.jpg)"; var outputFig = Markdown.ToHtml(fig); var outputNoFig = Markdown.ToHtml(noFig); Console.WriteLine(outputFig); Console.WriteLine(outputNoFig); ``` Outputs the following: ``` <figure>![Alt Text](https://site.com/image.jpg)</figure> <p><img src="https://site.com/image.jpg" alt="Alt Text" /></p> ``` Is this expected behavior or a bug?
claunia added the question label 2026-01-29 14:29:20 +00:00
Author
Owner

@xoofx commented on GitHub (Dec 3, 2017):

Yes, it is expected, as per the CommonMark specs. As you can verify on babelmark

This is because if the line starts by a HTML element, everything inside the HTML element will be output as-is. This is considered as a HTML block in the CommonMark specs.

This is different if you have the following markdown on babelmark

This is a test <figure>![Alt Text](https://site.com/image.jpg)</figure>
<p>This is a test</p>
<figure><img src="https://site.com/image.jpg" alt="Alt Text"></figure>

Now the HTML is not a HTML block, but considered as HTML raw inline. So only the HTML tags are left as-is but their content are still considered as markdown content.

@xoofx commented on GitHub (Dec 3, 2017): Yes, it is expected, as per the [CommonMark specs](http://spec.commonmark.org/). As you can verify on [babelmark](https://babelmark.github.io/?text=%3Cfigure%3E!%5BAlt+Text%5D(https%3A%2F%2Fsite.com%2Fimage.jpg)%3C%2Ffigure%3E) This is because if the line starts by a HTML element, everything inside the HTML element will be output as-is. This is considered as a [HTML block](http://spec.commonmark.org/) in the CommonMark specs. This is different if you have the following markdown on [babelmark](https://babelmark.github.io/?text=This+is+a+test+%3Cfigure%3E!%5BAlt+Text%5D(https%3A%2F%2Fsite.com%2Fimage.jpg)%3C%2Ffigure%3E) ```md This is a test <figure>![Alt Text](https://site.com/image.jpg)</figure> ``` ```html <p>This is a test</p> <figure><img src="https://site.com/image.jpg" alt="Alt Text"></figure> ``` Now the HTML is not a HTML block, but considered as [HTML raw inline](http://spec.commonmark.org/0.28/#raw-html). So only the HTML tags are left as-is but their content are still considered as markdown content.
Author
Owner

@follesoe commented on GitHub (Dec 3, 2017):

I'll stick with Markdown 2.2.0 until I get my content updated (v 2.2.1 has the behavior you describe, so I guess I'm taking advantage of a bug in 2.2.0).

Thanks for the incredible swift reply to my question! And awesome to see a feature rich actively maintained new Markdown library for .NET!

@follesoe commented on GitHub (Dec 3, 2017): I'll stick with Markdown 2.2.0 until I get my content updated (v 2.2.1 has the behavior you describe, so I guess I'm taking advantage of a bug in 2.2.0). Thanks for the incredible swift reply to my question! And awesome to see a feature rich actively maintained new Markdown library for .NET!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#167