-
-
Notifications
You must be signed in to change notification settings - Fork 126
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
Fix component style attribute parser #45
Conversation
Thanks for opening the pull request and bringing the bug to my attention @ianvieira My question for you is do you think Also, since |
@remarkablemark After using the new solution with the css-to-react-native, I've found some issues, so I tried another approach, that is more successful. Now I'm using AST to deconstruct the style string and then creating a new object with the values and property name in camel case. This new approach works faster as before and without the problem of using a isomorphic designed module. What do you think about the new solution? |
@ianvieira Nice! I like the AST approach because it'll support the general use cases. The solution looks great but I found something unfortunate about The alternative I have a library I have a few more requests (if you would be so kind):
I want to thank you once more for looking into this and submitting the pull request. I really appreciate your time and effort. If you feel like you're swamped or have no time, I can always take over and lend a helping hand. |
Of course, I can address these issues, in fact this will change will help me too, my application bundle is with 900kb and I'm trying to make it smaller. I'll do a new commit with the changes and also check if your library handles my biggest problem, the background with a base64 image, which was not being interpreted rightly. |
…to an style object
…mel case and assert the string is a string
… remove double quote from tests
@remarkablemark I believe now it's how you expected. I tried to address all your requests and also added an base64 image for test, this way we're able to test this edge case and also the url. |
@ianvieira Thanks for addressing the requests so quickly. I made a few comments and then let's get this thing merged in. Oh and before I forget, were you able to verify if the style prefix for |
lib/attributes-to-props.js
Outdated
@@ -5,6 +5,7 @@ | |||
*/ | |||
var utilities = require('./utilities'); | |||
var propertyConfig = require('./property-config'); | |||
var parser = require('style-to-object'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind renaming parser
to styleToObject
just for keeping it explicit here?
lib/attributes-to-props.js
Outdated
for (var i = 0, declarationsLen = declarations.length; i < declarationsLen; i++) { | ||
properties = declarations[i].trim().split(':'); | ||
parser(style, function(propName, propValue) { | ||
styleObj[utilities.camelCase(propName)] = propValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing about the style parser is that css comments is included in the iterator. Could we include an undefined
check here?
if (propName && propValue) {
styleObj[utilities.camelCase(propName)] = propValue;
}
lib/utilities.js
Outdated
@@ -6,24 +6,19 @@ | |||
* @param {String} string - The string. | |||
* @return {String} | |||
*/ | |||
|
|||
var _hyphenPattern = /-(.)/g; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind moving this line above the JSDoc? This is because we can find easier to read the comment when it's next to the function.
package.json
Outdated
@@ -30,7 +30,8 @@ | |||
], | |||
"dependencies": { | |||
"html-dom-parser": "0.1.2", | |||
"react-dom-core": "0.0.2" | |||
"react-dom-core": "0.0.2", | |||
"style-to-object": "^0.2.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove the ^
? I'm following save-exact
since I don't have a package-lock.json
or yarn.lock
checked in.
I’ll do the requested changes between today and tomorrow and yes I checked
the browser prefix and it’s working as expected, I also added this case to
the tests.
…On Sun, 26 Nov 2017 at 18:19 Mark ***@***.***> wrote:
@ianvieira <https://github.com/ianvieira> Thanks for addressing the
requests so quickly. I made a few comments and then let's get this thing
merged in.
Oh and before I forget, were you able to verify if the style prefix for
-ms works as expected?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#45 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA-c8Ff8E6CdPtANvfONusH1bzB4F6S-ks5s6ceWgaJpZM4QFSJc>
.
|
@remarkablemark I finished all the requested changes |
@ianvieira Awesome work! Also if you're looking to visualize your webpack bundle stats, check out Webpack Visualizer. |
@remarkablemark Thank you! Great tip! I have another question, when this new version will be available at NPM? Currently I'm using my repo as source and I want to change to the package again |
@ianvieira I'll try to release either tonight or tomorrow morning. |
@ianvieira I have released # npm
npm install html-react-parser@latest --save
# yarn
yarn upgrade html-react-parser --latest |
Fix component style attribute parser
When we have a style attribute on the original HTML, the parsing was not correct, specially with background-image with an external URL, this was not loading because of a split by ':' what breaks the URL. I added an library that generates a more complete style tag using css-to-react-native.