diff --git a/lib/utils.js b/lib/utils.js index 9d0d7e8..d0d238a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -20,7 +20,14 @@ function createStyleJsonFromString(styleString) { } if (key != null && value != null && key.length > 0 && value.length > 0) { - jsonStyles[camelCase(key)] = value; + key = key.trim(); + + // Don't camelCase CSS custom properties + if (key.indexOf('--') !== 0) { + key = camelCase(key); + } + + jsonStyles[key] = value; } } return jsonStyles; diff --git a/test/html-to-react-tests.js b/test/html-to-react-tests.js index 51c36d4..50c42ea 100644 --- a/test/html-to-react-tests.js +++ b/test/html-to-react-tests.js @@ -61,6 +61,15 @@ describe('Html2React', () => { assert.equal(reactHtml, htmlExpected); }); + it('should return a valid HTML string with custom properties in inline styles', () => { + const htmlInput = '
'; + + const reactComponent = parser.parse(htmlInput); + const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); + + assert.equal(reactHtml, htmlInput); + }); + it('should return a valid HTML string with data attributes', () => { const htmlInput = '
';