mdx-util icon indicating copy to clipboard operation
mdx-util copied to clipboard

relative image path ?

Open belgattitude opened this issue 6 years ago • 3 comments

Sorry I was not able to handle by myself...

Have a markdown containing an image tag:

![My image](./images/gravity-book-fr.jpg "My image")

I was assuming, the mdx-loader would resolve the picture from the markdown document file, and then let webpack do the regular job (take the picture, move it to the static dist, hash...) .

But it looks it's not the case... Is it something I can achieve (I mean with regular markdown, without import './img.jpg')

Have you any thoughts ? Thanks

belgattitude avatar Dec 21 '18 14:12 belgattitude

I'd really like to have support for this, but don't have time to implement it right now.

Would you be interested in doing this as a PR?

jamesknelson avatar Dec 23 '18 04:12 jamesknelson

Same time situation for me, but I would love too... Let's see.

belgattitude avatar Dec 23 '18 14:12 belgattitude

As a workaround, I am using the components prop to modify an img tag with a relative src to an absolute path:

imageFactory = ({ src, ...props }) => {
  const imgSrc = src.startsWith('http')
    ? src
    : <construct-absolute-url>

  return <img {...props} src={imgSrc} />;
};

// ...

<Document components={{ img: this.imageFactory }}

helfi92 avatar Dec 30 '18 18:12 helfi92