File tree 1 file changed +21
-3
lines changed
1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -176,13 +176,31 @@ const options = {
176
176
console .log (renderToStaticMarkup (parse (html, options)));
177
177
```
178
178
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
+
179
199
Output:
180
200
181
201
``` html
182
202
<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 >
186
204
</h1 >
187
205
```
188
206
You can’t perform that action at this time.
0 commit comments