How to get ALT text of image? #197

Closed
opened 2026-01-29 14:30:09 +00:00 by claunia · 1 comment
Owner

Originally created by @ckome on GitHub (Mar 4, 2018).

hi all~

I'v use this code get images node list
var links = md.Descendants<ParagraphBlock>().SelectMany(x => x.Inline.Descendants<LinkInline>()).ToList(); foreach (var node in links) { if (node.IsImage) { Debug.WriteLine(node.Url); } }

and how to get the alt text?

Originally created by @ckome on GitHub (Mar 4, 2018). hi all~ I'v use this code get images node list ` var links = md.Descendants<ParagraphBlock>().SelectMany(x => x.Inline.Descendants<LinkInline>()).ToList(); foreach (var node in links) { if (node.IsImage) { Debug.WriteLine(node.Url); } } ` and how to get the alt text?
claunia added the question label 2026-01-29 14:30:09 +00:00
Author
Owner

@xoofx commented on GitHub (Apr 4, 2018):

Unfortunately, there is no easy way to get the real alt text, as it is actually given by the potential multiple children rendered without the HTML tags.

7620b2b760/src/Markdig/Renderers/Html/Inlines/LinkInlineRenderer.cs (L30-L40)

You can come with a hack to fetch this by using similar code (or if you expect a single LiteralInline as a child)

@xoofx commented on GitHub (Apr 4, 2018): Unfortunately, there is no easy way to get the real alt text, as it is actually given by the potential multiple children rendered without the HTML tags. https://github.com/lunet-io/markdig/blob/7620b2b76030e2092b172808a64c4ae6f787384b/src/Markdig/Renderers/Html/Inlines/LinkInlineRenderer.cs#L30-L40 You can come with a hack to fetch this by using similar code (or if you expect a single `LiteralInline` as a child)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#197