# htr Rust library usage `htr` transforms HTML into React JSX markup, which helps when converting scraped raw HTML back into the form it would have in a valid React codebase. ## Add dependency ```toml [dependencies] htr = "0.5.26" ``` ## Transform props only Convert HTML attributes/styles to their React equivalents, keeping the markup: ```rust extern crate htr; use htr::convert_props_react; fn main(){ let html = r#"
"#; let react_html = convert_props_react(html.to_string()); println!("{}", react_html); //
} ``` ## Convert HTML to a full React component `convert_to_react` takes the HTML string and a component name and returns a complete React component: ```rust extern crate htr; use htr::convert_to_react; /// convert html to react component fn main(){ let html = r#"
child
"#; let react_component = convert_to_react(&html.to_string(), "Something"); println!("{}", react_component); // import React from "react" // // function Something() { // return ( // <> // //
//
// child //
//
// // // ) // } } ``` ## Input / output format - **Input**: raw HTML as a `String` (props conversion) or `&String` plus a component name (full component conversion). - **Output**: React JSX — converted attributes (`class` → `className`, `for` → `htmlFor`, `tabindex` → `tabIndex`), inline `style` strings as style objects, and, for component conversion, a complete component wrapped with `import React from "react"` and a fragment root.