html-react-parser 1.4.2 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ const parse = require('html-react-parser');
|
|
|
25
25
|
parse('<p>Hello, World!</p>'); // React.createElement('p', {}, 'Hello, World!')
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
[
|
|
28
|
+
[Replit](https://replit.com/@remarkablemark/html-react-parser) | [JSFiddle](https://jsfiddle.net/remarkablemark/7v86d800/) | [CodeSandbox](https://codesandbox.io/s/940pov1l4w) | [TypeScript](https://codesandbox.io/s/html-react-parser-z0kp6) | [Examples](https://github.com/remarkablemark/html-react-parser/tree/master/examples)
|
|
29
29
|
|
|
30
30
|
<details>
|
|
31
31
|
<summary>Table of Contents</summary>
|
|
@@ -202,7 +202,7 @@ If you're having issues take a look at our [Create React App example](./examples
|
|
|
202
202
|
|
|
203
203
|
#### replace element and children
|
|
204
204
|
|
|
205
|
-
Replace the element and its children (see [demo](https://
|
|
205
|
+
Replace the element and its children (see [demo](https://replit.com/@remarkablemark/html-react-parser-replace-example)):
|
|
206
206
|
|
|
207
207
|
```jsx
|
|
208
208
|
import parse, { domToReact } from 'html-react-parser';
|
|
@@ -283,7 +283,7 @@ HTML output:
|
|
|
283
283
|
|
|
284
284
|
#### replace and remove element
|
|
285
285
|
|
|
286
|
-
[Exclude](https://
|
|
286
|
+
[Exclude](https://replit.com/@remarkablemark/html-react-parser-56) an element from rendering by replacing it with `<React.Fragment>`:
|
|
287
287
|
|
|
288
288
|
```jsx
|
|
289
289
|
parse('<p><br id="remove"></p>', {
|
|
@@ -415,7 +415,7 @@ If the parser throws an erorr, check if your arguments are valid. See ["Does inv
|
|
|
415
415
|
|
|
416
416
|
### Is SSR supported?
|
|
417
417
|
|
|
418
|
-
Yes, server-side rendering on Node.js is supported by this library. See [demo](https://
|
|
418
|
+
Yes, server-side rendering on Node.js is supported by this library. See [demo](https://replit.com/@remarkablemark/html-react-parser-SSR).
|
|
419
419
|
|
|
420
420
|
### Elements aren't nested correctly
|
|
421
421
|
|
|
@@ -450,7 +450,7 @@ parse('<CustomElement>', options); // React.createElement('CustomElement')
|
|
|
450
450
|
> Warning: <CustomElement> is using incorrect casing. Use PascalCase for React components, or lowercase for HTML elements.
|
|
451
451
|
> ```
|
|
452
452
|
|
|
453
|
-
See [#62](https://github.com/remarkablemark/html-react-parser/issues/62) and [example](https://
|
|
453
|
+
See [#62](https://github.com/remarkablemark/html-react-parser/issues/62) and [example](https://replit.com/@remarkablemark/html-react-parser-62).
|
|
454
454
|
|
|
455
455
|
### TS Error: Property 'attribs' does not exist on type 'DOMNode'
|
|
456
456
|
|
|
@@ -1316,11 +1316,19 @@
|
|
|
1316
1316
|
|
|
1317
1317
|
// convert HTML/SVG attribute to React prop
|
|
1318
1318
|
attributeNameLowerCased = attributeName.toLowerCase();
|
|
1319
|
-
propName =
|
|
1319
|
+
propName = getPropName(attributeNameLowerCased);
|
|
1320
1320
|
|
|
1321
1321
|
if (propName) {
|
|
1322
|
-
props[propName] = attributeValue;
|
|
1323
1322
|
propertyInfo = reactProperty.getPropertyInfo(propName);
|
|
1323
|
+
|
|
1324
|
+
// convert attribute to uncontrolled component prop (e.g., `value` to `defaultValue`)
|
|
1325
|
+
// https://reactjs.org/docs/uncontrolled-components.html
|
|
1326
|
+
if (propName === 'checked' || propName === 'value') {
|
|
1327
|
+
propName = getPropName('default' + attributeNameLowerCased);
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
props[propName] = attributeValue;
|
|
1331
|
+
|
|
1324
1332
|
switch (propertyInfo && propertyInfo.type) {
|
|
1325
1333
|
case reactProperty.BOOLEAN:
|
|
1326
1334
|
props[propName] = true;
|
|
@@ -1346,6 +1354,16 @@
|
|
|
1346
1354
|
return props;
|
|
1347
1355
|
};
|
|
1348
1356
|
|
|
1357
|
+
/**
|
|
1358
|
+
* Gets prop name from lowercased attribute name.
|
|
1359
|
+
*
|
|
1360
|
+
* @param {string} attributeName - Lowercased attribute name.
|
|
1361
|
+
* @return {string}
|
|
1362
|
+
*/
|
|
1363
|
+
function getPropName(attributeName) {
|
|
1364
|
+
return reactProperty.possibleStandardNames[attributeName];
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1349
1367
|
var React = require$$0__default["default"];
|
|
1350
1368
|
var attributesToProps$1 = attributesToProps$2;
|
|
1351
1369
|
var utilities$1 = utilities$3;
|