Skip to content

URLs relative to the markdown file #246

Answered by pngwn
mattjennings asked this question in Q&A
Discussion options

You must be logged in to vote

Technically possible in a plugin but relatively complex.

The simplest way I could think to do it is to transform:

Hello, this is an image

![my image](./my-image.png)

Into:

<script>
  import MyImage from './my-image.png';
</script>

<img src="{MyImage}" title="my image" />

Then, assuming your bundler is set up to handle images, it will take care of copying across the necessary files. You can then continue using image paths relative to your files as you do with javascript etc.

The other alternative is to resolve the files manually and copy them across to the static folder, but at this point you are pretending to be a bundler. Vite will handle this for us and getting images into your JS too…

Replies: 2 comments 9 replies

Comment options

You must be logged in to vote
1 reply
@mattjennings
Comment options

Comment options

You must be logged in to vote
8 replies
@mattjennings
Comment options

@michaeloliverx
Comment options

@eur2
Comment options

@KoljaL
Comment options

@eur2
Comment options

Answer selected by mattjennings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants