html-to-react

Crates.iohtml-to-react
lib.rshtml-to-react
version0.5.2
sourcesrc
created_at2022-07-12 21:43:10.45308
updated_at2022-07-13 19:07:13.042671
descriptionconvert a html string to react
homepage
repository
max_upload_size
id624725
size25,506
Jeff Mendez (j-mendez)

documentation

https://docs.rs/html-to-react

README

html-to-react

Fast html to react jsx converter

Getting Started

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>
    //     )
    // }
}

About

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.

License

MIT

Commit count: 0

cargo fmt