Skip to content

Commit 76f8b0c

Browse files
author
huangteng02
committed
feat: update readme
1 parent 00fbef2 commit 76f8b0c

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

README.md

+21-3
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,31 @@ const options = {
176176
console.log(renderToStaticMarkup(parse(html, options)));
177177
```
178178

179+
Use the exported attributesToProps method to convert DOM attributes to React Props:
180+
181+
```jsx
182+
import React from 'react';
183+
import parse, { attributesToProps } from 'html-react-parser';
184+
185+
const html = `
186+
<hr class="prettify" style="background:#fff;text-align:center" />
187+
`;
188+
189+
const options = {
190+
replace: node => {
191+
if (node.attribs && node.name === 'hr') {
192+
const props = attributesToProps(node.attribs);
193+
return <hr {...props} />;
194+
}
195+
}
196+
};
197+
```
198+
179199
Output:
180200

181201
```html
182202
<h1 style="font-size:42px">
183-
<span style="color:hotpink">
184-
keep me and make me pretty!
185-
</span>
203+
<span style="color:hotpink"> keep me and make me pretty! </span>
186204
</h1>
187205
```
188206

0 commit comments

Comments
 (0)