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

Self-closing tags and custom components #79

Open
ischenkodv opened this issue Aug 31, 2016 · 6 comments
Open

Self-closing tags and custom components #79

ischenkodv opened this issue Aug 31, 2016 · 6 comments

Comments

@ischenkodv
Copy link

I'm trying to convert HTML with my custom component named "Data". It looks like this:

<div>
  <br/>
  <Data name="foo"/>
  <p>After</p>
</div>

As I result I get the following JSX in which the paragraph becomes the child of a Data tag and the tag itself is lowercased:

var MyTemplate = React.createClass({
  render: function() {
    return (

      <div>
        <br />
        <data name="foo">
          <p>After</p>
        </data></div>
    );
  }
});

Is this an expected behaviour?

@Daniel15
Copy link
Member

Daniel15 commented Sep 4, 2016

This library is really designed to only handle HTML - Data is not a regular HTML tag 😛

@KyleAMathews
Copy link
Contributor

I need this supported too — couldn't we just leave the casing of tags alone?

@NathanLawrence
Copy link
Contributor

Yeah...I'm a little confused about what's going on here. If you have actual React components you're mixing with React Magic, there's a reason this isn't supported -- you'll potentially be creating colossal memory leaks and violating just about every React best practice.

It seems like the way to handle this would be to avoid using React Magic and instead work on reconstructing all the major page elements in React with properly nested components. I know that sounds like a lot of extra effort, but I think you'll regret anything less in the long run.

@NathanLawrence
Copy link
Contributor

@KyleAMathews is this a Gatsby issue? If so, I'm definitely starting to understand why you might need or want this, even if it is against best practices -- I'm not sure how to get around this yet, though. Looking through the parser, I'm nervous this may be more than just a casing issue by the time we get to the bottom of it.

@KyleAMathews
Copy link
Contributor

I just want the HTML to jsx piece not the magic bit. I am interested in it for gatsby. Working on making it so you can add jsx to markdown. Would to compile to HTML from markdown then to jsx and need the jsx to survive through that. Could also write a markdown to jsx convertor which might be easier actually.

@Daniel15
Copy link
Member

Daniel15 commented Dec 19, 2016

couldn't we just leave the casing of tags alone?

It's using the browser's HTML parser, which tends to convert tags to lowercase (as regular HTML tags are not case sensitive). This library was designed only for use as a HTML to JSX converter, not a HTML+JSX to JSX converter, and thus it does not support the use case of a chunk of HTML that has existing JSX elements in it.

The Node.js build uses jsdom instead, but it works similarly. This library is really built for use in a browser though.

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

4 participants