react-markdown icon indicating copy to clipboard operation
react-markdown copied to clipboard

how to scale image

Open ldn0x7dc opened this issue 8 years ago • 6 comments

My page contains a large image which stretch beyond the width of this component. I want the image to contain.

ldn0x7dc avatar May 25 '18 07:05 ldn0x7dc

Use a custom renderer for the image type and specify a class name or inline styles:

function Image(props) {
  return <img {...props} style={{maxWidth: '100%'}} />
}

<Markdown
  source="![Espen](https://espen.codes/assets/img/avatar-colored.jpg)"
  renderers={{image: Image}}
/>

You'll have to figure out the right approach to styling it yourself, but this should give you all the flexibility you need.

rexxars avatar May 25 '18 09:05 rexxars

Thanks for the custom renderer code. Are there any plans to support scaling like mentioned at https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#images? I may have some time in the future to draft a PR.

redgeoff avatar Oct 09 '18 21:10 redgeoff

renderers is remove in latest version

dellwatson avatar Feb 11 '22 20:02 dellwatson

@dellwatson I think now you can use components instead of renderers to achieve a similar result as below.

<ReactMarkdown children={source}
  components={{img:({node,...props})=><img style={{maxWidth:'100%'}}{...props}/>}}
/>

RukshanJS avatar Feb 12 '22 18:02 RukshanJS

@dellwatson It works.

n8tbyte avatar Apr 24 '22 10:04 n8tbyte

@RukshanJS Any chance you could provide ts example how to use that img:XX value but from different file? I'm struggling to provide correct arguments to standalone component :/

Dariusz1989 avatar Jan 31 '23 00:01 Dariusz1989