Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Interpret absolute image links relative to g:mkdp_images_path #651

Open
helins opened this issue Mar 13, 2024 · 5 comments
Open

Comments

@helins
Copy link

helins commented Mar 13, 2024

Some common workflows interpret absolute links relative to a well-known directory rather than the actual root of the filesystem, akin to how a web server interpret absolute links relative to the domain. I don't think there is currently a way for this plugin to behave like that regarding images.

I would suggest an additional boolean option for interpreting absolute image links relative to the existing g:mkdp_images_path (if provided). For instance, if g:mkdp_images_path is set to /foo/bar, then an image like ![](/baz.png) would resolve to /foo/bar/baz.png.

This should be an easy add-on and would turn this plugin from "great" to "excellent" :)

PaulBreugnot pushed a commit to PaulBreugnot/markdown-preview.nvim that referenced this issue May 15, 2024
As suggested in iamcco#651, `g:mkdp_images_path_as_root` can now be set to 1
to resolve absolute image paths against `g:mkdp_images_path`.

Example:
```
![Custom image](/path/to/image.png)
```
with `let g:mkdp_images_path = /home/user/.markdown_images`.

If `g:mkdp_images_path_as_root = 0` (default), then the image path is
interpreted as an absolute linux path, starting at the root of the
system.

If `g:mkdp_images_path_as_root = 1`, the path is interpreted as
`/home/user/.markdown_images/path/to/image.png`.

This is notably useful to reproduce the behavior of markdown hosting
websites, such as Github wikis, where absolute image paths are resolved
against https://github.com/username/repository/wiki/.
PaulBreugnot pushed a commit to PaulBreugnot/markdown-preview.nvim that referenced this issue May 15, 2024
As suggested in iamcco#651, `g:mkdp_images_path_as_root` can now be set to 1
to resolve absolute image paths against `g:mkdp_images_path`.

Example:
```
![Custom image](/path/to/image.png)
```
with `let g:mkdp_images_path = /home/user/.markdown_images`.

If `g:mkdp_images_path_as_root = 0` (default), then the image path is
interpreted as an absolute linux path, starting at the root of the
system.

If `g:mkdp_images_path_as_root = 1`, the path is interpreted as
`/home/user/.markdown_images/path/to/image.png`.

This is notably useful to reproduce the behavior of markdown hosting
websites, such as Github wikis, where absolute image paths are resolved
against https://github.com/username/repository/wiki/.
@pk0dev
Copy link

pk0dev commented Jul 31, 2024

I'm new mkdp user, could anyone please help me understand on how to use images in the markdown preview. Do I need to update something in my vim configs?

@Tweekism
Copy link

Not for the preview to work, as long as you have the correct syntax and path the image it should display.

![Some description](./path/to/image.png)

image

@pk0dev
Copy link

pk0dev commented Aug 2, 2024

thank you @Tweekism and also I was having issue loading the images. I noticed that the image name contained spaces and so I remove the spaces and it worked.

@Tweekism
Copy link

Tweekism commented Aug 2, 2024

Oh ok, well I haven't tested this, but if your images have spaces in them, replacing spaces in your link it %20 should also work.

@pk0dev
Copy link

pk0dev commented Aug 2, 2024

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants