Crates.io | html-to-react |
lib.rs | html-to-react |
version | 0.5.2 |
source | src |
created_at | 2022-07-12 21:43:10.45308 |
updated_at | 2022-07-13 19:07:13.042671 |
description | convert a html string to react |
homepage | |
repository | |
max_upload_size | |
id | 624725 |
size | 25,506 |
Fast html to react jsx converter
This project convers html into valid react jsx markup.
This helps when using find and replace tools when you scrape content getting raw html and need a way to convert it back to the form it would be in a valid React codebase.
[dependencies]
html_to_react = "0.5.1"
extern crate html_to_react;
use html_to_react::convert_props_react;
fn main(){
let html = r#"<div class="something" for="mystuff" tabindex="2" style="color: white; background-color: black">"#;
let react_html = convert_props_react(html.to_string());
println!("{}", react_html);
// <div className="something" htmlFor="mystuff" tabIndex="2" style={{color: "white", backgroundColor: "black"}}>
}
extern crate html_to_react;
use html_to_react::convert_to_react;
/// convert html to react component
fn main(){
let html = r#"<div class="something" for="mystuff" tabindex="2" style="color: white; background-color: black">"#;
let react_component = convert_to_react(html.to_string(), "Something");
println!("{}", react_component);
// import React from "react"
//
// function Something() {
// return (
// <div className="something" htmlFor="mystuff" tabIndex="2" style={{color: "white", backgroundColor: "black"}}>
// <div className="child" htmlFor="mychildstuff" tabIndex="2" style={{color: "white", backgroundColor: "black"}}>
// child
// </div>
// </div>
// )
// }
}
This project uses BTrees and parses the html with the order sorted before lookup for speed.
You can combine this project with html-parser to convert elements into React ready components.
An example of this being used with ripgrep to perform search and replace from scraped content to find exactly where in the codebase it would be, the react way.