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

Images are wrapped in a p tag #93

Closed
iremlopsum opened this issue Nov 2, 2017 · 10 comments
Closed

Images are wrapped in a p tag #93

iremlopsum opened this issue Nov 2, 2017 · 10 comments

Comments

@iremlopsum
Copy link

All of the images are wrapped in a p tag, which makes styling images hard. If I set a max-width of a paragraph 600px, but I want the image to be 700px and responsive at that, this becomes awful.

I have to custom render paragraphs, add a class to them, style them based on that. I feel like it would be easier not to wrap images in paragraphs.

Any reason why this is done like this?

@rexxars
Copy link
Collaborator

rexxars commented Nov 13, 2017

Only because the current parser emits a paragraph. In v3 you have the option to manipulate the AST before rendering, which should make unwrapping images pretty simple. I'll get back to you with an example once v3 is released.

@iremlopsum
Copy link
Author

I found a work around. I'm just checking whether it contains an image and return only the image.

@kaifaust
Copy link

kaifaust commented Jan 8, 2018

Can we get an example of how to do this in v3?

@mkum9469
Copy link

@rexxars How can we achieve this is v3? How can we make it not wrap the output in a paragraph? :)

@wallawe
Copy link

wallawe commented Jun 22, 2018

@iremlopsum mind providing an example of how you did this?

@iremlopsum
Copy link
Author

@wallawe something like this should work.

renderParagraph(props) {
  const { children } = props;

  if (children && children[0]
    && children.length === 1
    && children[0].props
    && children[0].props.src) { // rendering media without p wrapper

    return children;
  }

  return <p>{children}</p>;
}
renderPost() {
  return (
    <ReactMarkdown
      source={source}
      renderers={{
        paragraph: this.renderParagraph,
      }}
    />
  );
}

@wallawe
Copy link

wallawe commented Jun 22, 2018

you're the man, thank you

@tairosonloa
Copy link

tairosonloa commented Jul 14, 2021

This syntax is not valid for current version (6.0.2). What should we do now?

Edit: Could achieve it using a plugin: https://www.npmjs.com/package/remark-unwrap-images

@JonathanScialpi

This comment was marked as resolved.

@Schachte

This comment was marked as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

8 participants