Skip to content

Self-closing HTML tags are not always working #270

@rolandleth

Description

@rolandleth

Hey!

The issue reproduces with almost any self-closing tag like input or area, but br seems to have no issues.

If I try to parse just this

<img src="/images/someImage.jpg" />

I get an error thrown:

Invariant Violation: img is a void element tag and must neither have children nor use dangerouslySetInnerHTML.

Something more complex, like a blog post that contains several img tags gets me:

screenshot 2019-01-31 at 13 43 31

Weirdly enough, a blog post that contains a single img properly works ...

This is an example that is giving me troubles: https://gist.github.com/rolandleth/b182260ba423c3e65923fe382e000c9e

I tried lurking for a few hours, but I don't have the experience to actually debug it. I thought I found some solutions, but nothing properly worked. For example React does this check: !(props.children == null && props.dangerouslySetInnerHTML == null), but the passed in children is an empty array for the img tag; but not always 😑. It's clear I have no real idea what I'm doing.

Would you have time to test the library with the example I provided?

I'm using

<ReactMarkdown
    source={this.state.post.body}
    escapeHtml={false}
/>

but I also tried custom parsers, like in the docs, with astPlugins={[parseHtml]}. Although it might just be that I didn't know how to configure them 😞

Let me know if and how I can help.

Thanks and have a great day! 🌞

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions