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

Markdown images are not turned into webpack requires #25

Open
jasononeil opened this issue Dec 22, 2017 · 1 comment
Open

Markdown images are not turned into webpack requires #25

jasononeil opened this issue Dec 22, 2017 · 1 comment

Comments

@jasononeil
Copy link
Contributor

Using JSX <img src={}> tags allows you to import images using require statements and have them correctly handled by webpack, but using the markdown ![alt]({{src}}) syntax does not generate a require statement, so the assets aren't processed by webpack.

It would be good to support {{importedVariable}} interpolation in the markdown syntax too.

It would be even nicer (in my opinion at least) if images were automatically transformed into webpack requires.

Markdown to reproduce:

---
imports:
  myImg: ./img/img.png
---

- Image 1: ![img](./img/img.png)
- Image 2: ![img]({{myImg}})
- Image 3: <img src="./img/img.png" />
- Image 4: <img src={myImg} />
- Image 5: ![img]({{require('./img/img.png')}})
- Image 6: <img src={require('./img/img.png')} />

Actual output

import myImg from './img/img.png';
// ....snip....
      <li>Image 1: <img src="./img/img.png" alt="img" /></li>
      <li>Image 2: <img src="{myImg}" alt="img" /></li>
      <li>Image 3: <img src="./img/img.png" /></li>
      <li>Image 4: <img src={myImg} /></li>
      <li>Image 5: <img src="{require('./img/img.png')}" alt="img" /></li>
      <li>Image 6: <img src={require('./img/img.png')} /></li>
// ....snip....

Expected output

import myImg from './img/img.png';
// ....
      <li>Image 1: <img src="./img/img.png" alt="img" /></li>
      <li>Image 2: <img src={myImg} alt="img" /></li>
      <li>Image 3: <img src="./img/img.png" /></li>
      <li>Image 4: <img src={myImg} /></li>
      <li>Image 5: <img src={require('./img/img.png')} alt="img" /></li>
      <li>Image 6: <img src={require('./img/img.png')} /></li>
// ....

Thanks for the very cool webpack loader! I'd be open to creating a pull request if you can confirm which of the images in the example should be transformed into require statements

@ticky
Copy link
Owner

ticky commented Jan 4, 2018

Ah, that’s an unfortunate gotcha, and I know why it’s happening - the interpolation is being set aside to be re-inserted, but what it’s replaced with gets quoted by the markdown processor.

I believe this is fixable, but for now, I’d just stick to using an <img> tag directly.

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

2 participants