File tree Expand file tree Collapse file tree 1 file changed +21
-3
lines changed
Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -176,13 +176,31 @@ const options = {
176176console .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+
179199Output:
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
You can’t perform that action at this time.
0 commit comments