MediaLinks Extension doesn't work on relative links #606

Open
opened 2026-01-29 14:40:54 +00:00 by claunia · 4 comments
Owner

Originally created by @RickStrahl on GitHub (Jun 13, 2023).

It appears that the .UseMediaLinks() extension does not detect media when the URL is not an http link, but rather a relative path.

The following demonstrates:

image

Note that the only media link created correctly is the one that has the full HTTP link while the relative link/no path ones render as images which is not correct.

Here's a Gist with the above code:
https://gist.github.com/RickStrahl/36035c87787fc24e37861059e40a6f8b

Originally created by @RickStrahl on GitHub (Jun 13, 2023). It appears that the `.UseMediaLinks()` extension does not detect media when the URL is not an http link, but rather a relative path. The following demonstrates: ![image](https://github.com/xoofx/markdig/assets/1374013/d14e2695-94f8-423f-a343-638dc2afd31d) Note that the only media link created correctly is the one that has the full HTTP link while the relative link/no path ones render as images which is not correct. Here's a Gist with the above code: https://gist.github.com/RickStrahl/36035c87787fc24e37861059e40a6f8b
claunia added the questionPR Welcome! labels 2026-01-29 14:40:54 +00:00
Author
Owner

@RickStrahl commented on GitHub (Jun 13, 2023):

For reference here's a screen shot of Markdown Monster rendering the above links as well as a relative image and an explicit HTML video tag:

image

For the markdown media links only the online https:// links work.

However the manual video link work fine with a relative path for image rendered out of the current path (cut off bottom image is a video player instance).

@RickStrahl commented on GitHub (Jun 13, 2023): For reference here's a screen shot of Markdown Monster rendering the above links as well as a relative image and an explicit HTML video tag: ![image](https://github.com/xoofx/markdig/assets/1374013/4ede3f7b-93be-4021-a55c-52d1658059ea) For the markdown media links only the online `https://` links work. However the manual video link work fine with a relative path for image rendered out of the current path (cut off bottom image is a video player instance).
Author
Owner

@xoofx commented on GitHub (Jul 8, 2023):

Medialinks extension only supports absolute URL. It could support relative with an option to allow them.
I don't have time to implement such feature but PR welcome if someone is looking for this.

@xoofx commented on GitHub (Jul 8, 2023): Medialinks extension only supports [absolute URL](https://github.com/xoofx/markdig/blob/b7cb169fd3a924e1e0d4e2e487a22c51caaedd10/src/Markdig/Extensions/MediaLinks/MediaLinkExtension.cs#L54-L67). It could support relative with an option to allow them. I don't have time to implement such feature but PR welcome if someone is looking for this.
Author
Owner

@RickStrahl commented on GitHub (Jul 8, 2023):

Do you think relative paths need an option? Seems like this should just work otherwise it's confusing why some media links work and some do not.

Looks like the only other parser that actually supports media link parsing (on Babelmark) is PanDoc. PanDoc turns relative paths into respective <video> and <audio> links along with fully qualified Urls.

If I find some time I'll take a look.

@RickStrahl commented on GitHub (Jul 8, 2023): Do you think relative paths need an option? Seems like this should just work otherwise it's confusing why some media links work and some do not. Looks like the only other parser that actually supports media link parsing (on Babelmark) is PanDoc. PanDoc turns relative paths into respective `<video>` and `<audio>` links along with fully qualified Urls. If I find some time I'll take a look.
Author
Owner

@xoofx commented on GitHub (Jul 8, 2023):

Do you think relative paths need an option? Seems like this should just work otherwise it's confusing why some media links work and some do not.

Problem is more backward compatibility that could start to break existing code that were relying on this behavior.

@xoofx commented on GitHub (Jul 8, 2023): > Do you think relative paths need an option? Seems like this should just work otherwise it's confusing why some media links work and some do not. Problem is more backward compatibility that could start to break existing code that were relying on this behavior.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#606