-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
attributesToProps converts case to lower case #263
Comments
Thanks for the question @h0jeZvgoxFepBQ2C, On the browser, the attributes technically don't care about case-sensitivity. Is there a particular reason why you need case-sensitive attributes? There are htmlparser2 options, but they only work on Node.js (server-side) and do not work in the browser (client-side). |
Thanks for the follow up @remarkablemark Actually we would like to pass react specific arguments to our html, so we can use these attributes directly.. F.e. imagine a div should be replaced with a countdown element with the argument <div role="countdown" endsAt="2021-10-10 01:01:01+0200"/> should be converted to <Countdown endsAt="2021-10-10 01:01:01+0200"/> So if the arguments are always downcased, I cannot use them for the react components? |
@remarkablemark Any thoughts on this? Your library would offer much more possibilities if it doesn't convert all keys to downcase. And as you said, browsers don't care about case sensitivity, so it wouldn't make a difference? Right now there is only this downside, that we can't use it to pass props directly to other React components? |
@h0jeZvgoxFepBQ2C If you're using the library only on the server-side (Node.js), then you can override the htmlparser2 options. You can find a list of the parser options here. |
I know, but we are clientside rendering |
Adding my vote to this. If possible it would be nice with an option to enable the client side version to work the same as the server side version. Some use cases, like mine, don't need to care about e.g. XSS issues. |
@remarkablemark would you accept a PR for this, to make the option also available for the client side? |
@h0jeZvgoxFepBQ2C I feel the approach will add more complexity to If you really want to achieve this, one approach is to override Webpack to ensure |
I second this issue, case conversion is a pain as you can't export a string as React components - I thought this would be a key use case but maybe not. |
@remarkablemark You can use |
@Yankovsky Thanks for the suggestion. I'm just concerned that this may not be backwards compatible and could cause a breaking change for existing users. Currently, |
Yeah, I checked the code already. It won't be as easy as just changing the mime type to |
I definitely agree with this. I had issues when I was trying to parse an html string from a source string in a json file and it kept transforming my props incorrectly into lowercase. Most props use camel case so I am not sure why this wasn't anticipated. At the time, I thought well no problem I'll pass options from the documentation into it, and that doesn't work because html2parser is server side only and my application is static. Unfortunately, these limitations render this package useless for many common use cases. I realize the devs of this package aren't at fault here because there are reasons for these limitations. But sadly, I will have to find something else or come up with something hacky. |
It seems that the
attributesToProps
method is converting all keys to lowercase (see https://github.com/remarkablemark/html-react-parser/blob/master/lib/attributes-to-props.js#L37 ).Why is this happening?
We would like to pass case-sensitive attributes to our dynamic html content and with the current implementation it doesn't work, since all attributes are converted to lower case?
The text was updated successfully, but these errors were encountered: