Skip to content

Commit

Permalink
feat: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
huangteng02 committed Sep 11, 2020
1 parent 00fbef2 commit 76f8b0c
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,31 @@ const options = {
console.log(renderToStaticMarkup(parse(html, options)));
```

Use the exported attributesToProps method to convert DOM attributes to React Props:

```jsx
import React from 'react';
import parse, { attributesToProps } from 'html-react-parser';

const html = `
<hr class="prettify" style="background:#fff;text-align:center" />
`;

const options = {
replace: node => {
if (node.attribs && node.name === 'hr') {
const props = attributesToProps(node.attribs);
return <hr {...props} />;
}
}
};
```

Output:

```html
<h1 style="font-size:42px">
<span style="color:hotpink">
keep me and make me pretty!
</span>
<span style="color:hotpink"> keep me and make me pretty! </span>
</h1>
```

Expand Down

0 comments on commit 76f8b0c

Please sign in to comment.