Mdx: inline image tags not rendered

Created on 14 Aug 2018  路  7Comments  路  Source: mdx-js/mdx

images inside of markdown text is rendered as text instead of as an image.

The terrain <img src="/img/terrains/grass.jpg" width="24" style={{margin: "0 !important", display: "inline-block !important"}} alt="css grid item" /> items we'll use are stacked to the left of the shuttle to show their order in the DOM.

should be rendered as:
image

but instead is just text:
image

馃悰 typbug

Most helpful comment

Seems like something that should work 馃

All 7 comments

As a workaround for anyone else who needs this: just use a span instead of an img and then style that span with a background image.

Closing this issue since there's a workaround.

Seems like something that should work 馃

Yeah, inline JSX doesn't seem to work. The original example doesn't work because style={{ }} is not valid HTML (it's JSX), so remark interprets the whole element as a string. Using a string instead of an object for style will work:

style="margin: 0 !important; display: inline-block !important"

I would also like the JSX form to work, though.

This is also not being parsed properly. There's a workaround where you can import the image at the top of the file and add that, but it's not ideal.

<a href={require('./async-cheatsheet.png')}>
<img alt="Asynchronous JavaScript Cheatsheet" src={require('./async-cheatsheet.png')} />
</a>

Any idea how I'd go about fixing this? I'm moving all my markdown from MDXC to MDX, and this is the one thing that seems not to work.

I'm not sure what causes this, but a workaround might be to create a custom component that's simply an alias for the <a> element:

// Link.js
export default 'a'
import Link from './Link'

<Link href={require('./async-cheatsheet.png')}>
<img alt="Asynchronous JavaScript Cheatsheet" src={require('./async-cheatsheet.png')} />
</Link>

The parser treats <a> elements differently (for example <div> works) probably because links are special in Markdown, so it can't parse syntax which isn't valid HTML.

Neat, that works. Thanks!

The image tag isn't working because of the curly braces. This will be fixed when remark-mdx is finalized and then used in core. You can follow along with #196 to track progress. Thanks for opening up an issue!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ludwigfrank picture ludwigfrank  路  3Comments

riceboyler picture riceboyler  路  3Comments

lex111 picture lex111  路  4Comments

johno picture johno  路  3Comments

silvenon picture silvenon  路  4Comments