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

HTML fragments are being ignored

Open andrewkolesnikov opened this issue 9 years ago • 4 comments

The following test fails, probably because it's fed to innerHTML.

  it('should handle tr, td tags', function() {
    var converter = new HTMLtoJSX({ createClass: false });
    expect(converter.convert('<tr><td>foo</td></tr>').trim())
      .toBe('<tr><td>foo</td></tr>');
  });

Fails with: Expected '<div> foo </div>' to be '<tr><td>foo</td></tr>'.

Consequently, tons of HTML fragments won't be converted correctly, e.g. <table><tr><td>foo</td></tr></table> becomes <table><tbody><tr><td>foo</td></tr></tbody></table>

andrewkolesnikov avatar Aug 15 '15 00:08 andrewkolesnikov

Good catch! Indeed, table elements need special handling here.

For your second case, is that actually an issue? Tables should ideally always have at least one <tbody> in them.

Daniel15 avatar Aug 15 '15 00:08 Daniel15

Agreed. Injecting <tbody> shouldn't be an issue in most cases. Perhaps a note in the README to indicate elements aren't guaranteed to match 1:1?

andrewkolesnikov avatar Aug 15 '15 00:08 andrewkolesnikov

Daniel15, is this project ever going to be able to match HTML 1:1? Could you ever ensure a ~100% compatibility with HTML5? Does React/JSX have full coverage over everything you can do in normal HTML?

When I used this on a few sites, I would often get HTML syntax errors (akin to #9). Is that due to an incompatibility or just a buggy parser that could be fixed if enough time was put into it?

karlfloersch avatar Sep 16 '15 01:09 karlfloersch

@karlfloersch - What issues have you encountered? Concrete examples would be great, ideally one separate issue per issue to allow for better tracking :smile: JSX should allow most HTML tags except for deprecated tags, and hence the converter should also support them.

Daniel15 avatar Sep 16 '15 04:09 Daniel15