roman01la / html-to-react-components

Converts HTML pages into React components
https://roman01la.github.io/html-to-react-components/
MIT License
2.13k stars 136 forks source link

First property of inline style missing trailing comma #9

Closed jesstelford closed 8 years ago

jesstelford commented 8 years ago

On commit 775e9b12064e0dcae0f1eef9d5fa21c0ff461700

This minimal test case:

console.log(require('html-to-react-components')(
  '<div data-component="Component" style="padding:0; display:inline"></div>'
).Component);

Produces this output:

import React from 'react';

const Component = React.createClass({
  render() {
    return <div style={{
        padding: 0
        display: 'inline'
      }} />;
  }
});

Notice the padding: 0 line is missing a trailing comma.

When more than two inline style elements exist, commas are correctly inserted for properties other than the first. For example:

console.log(require('html-to-react-components')(
  '<div data-component="Component" style="padding:0; display:inline; margin: 10; border: none"></div>'
).Component);

Produces

import React from 'react';

const Component = React.createClass({
  render() {
    return <div style={{
        padding: 0
        display: 'inline',
        margin: 10,
        border: 'none'
      }} />;
  }
});
jesstelford commented 8 years ago

Note that I tried the same case in htmltojsx, and it gives the correct output:

var HTMLtoJSX = require('htmltojsx');
var converter = new HTMLtoJSX({
  createClass: false
});
console.log(converter.convert('<div data-component="Component" style="padding:0; display:inline; margin: 10; border: none"></div>'));

Produces

<div data-component="Component" style={{padding: 0, display: 'inline', margin: 10, border: 'none'}} />

Does this imply an issue with the output formatter?

roman01la commented 8 years ago

Interesting. I'm going to check this. Thanks!

roman01la commented 8 years ago

fixed in 1ecc6998

jesstelford commented 8 years ago

:+1: Thanks!