Adding custom link to img path #586
-
I am getting the readme.MD of different public GitHub repos and I want to display them on my website. I do a fetch for the content(rest API GitHub), I decode the content of the readme.MD and then I want to display it in HTML using remark module. All is well and good with one exception. Is it possible to render images that do not have the whole link inside the readme.MD but just the path to the image location in the git repository? For example, it fairs well if it is "https://img.com/..." but not so well when "/images/image1.png". Can I somehow tell remark to put a "https://github.com/user/repo" in front of the path? Because right now I get a broken image, remark tries to complete the link by adding it to my website domain. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Welcome to the remark community @avpopa! 👋 |
Beta Was this translation helpful? Give feedback.
Welcome to the remark community @avpopa! 👋
This is possible though creating a remark plugin, https://unifiedjs.com/learn/ has good guides on plugins and working with an AST.
For your particular example, a plugin could look something like https://astexplorer.net/#/gist/5abca7e669e2be5f625da8e8ad6caec4/0ca13e906f82a565a38e2c2a76c3c4da867395d6