gjtorikian / commonmarker

Ruby wrapper for the comrak (CommonMark parser) Rust crate
MIT License
416 stars 80 forks source link

Does this work for relative path? #195

Closed yc1838 closed 1 year ago

yc1838 commented 1 year ago

When rendering a Readme.md file that contains a relative path to an image, will this rendering tool help to retrieve that image and put it back inside the current html item? I am developing an app that can be used to browse repos we get from Github, but I realize somehow only images with absolute paths work for the currently package I used.

gjtorikian commented 1 year ago

Well, if the README.md has a path like this:

This is a link to an image in a folder: ![alt text of image](images/foo.png)

Then this tool will turn that to:

This is a link to an image in a folder: <img src="images/foo.png" alt="alt text of image" />

as per the Commonmark spec, no more and no less.

So depending on the file, as long as it's placed relative to that image, it'll be there.

If you need to manipulate the HTML during or after the fact of parsing, you can use https://github.com/gjtorikian/html-pipeline to turn the image into a Base64 or whatever.