prejsx

Crates.ioprejsx
lib.rsprejsx
version0.1.0
created_at2025-10-12 09:49:15.125446+00
updated_at2025-10-12 09:49:15.125446+00
descriptionA JSX-to-HTML transpiler written in Rust using pest and meval.
homepage
repositoryhttps://github.com/Pjdur/prejsx
max_upload_size
id1879115
size16,603
Pjdur (Pjdur)

documentation

README

prejsx

prejsx is a lightweight JSX-to-HTML transpiler written in Rust. It parses JSX-like syntax and outputs valid HTML, including support for embedded expressions and inline styles — all without relying on JavaScript or a browser.


✨ Features

  • ✅ Parses JSX-like syntax using pest
  • ✅ Evaluates embedded math expressions like {1 + 2}
  • ✅ Converts className to class for HTML compatibility
  • ✅ Translates inline style objects (e.g. style={{color: "red"}}) to CSS
  • ✅ Supports nested elements and self-closing tags
  • ✅ Built for speed and simplicity — no external runtime required

📦 Installation

Add this to your Cargo.toml:

[dependencies]
prejsx = "0.1"

🚀 Example

use prejsx::render;

fn main() {
    let input = r#"<h1 className="title" style={{color: "blue"}}>Hello {2 * 2}!</h1>"#;
    let html = render(input);
    println!("{}", html);
}

Output:

<h1 class="title" style="color: blue;">Hello 4!</h1>

🧠 How It Works

  • The parser is powered by pest and defined in jsx.pest.
  • Expressions like {3 + 3} are evaluated using prejsx_math, a zero-dependency math parser.
  • Style objects are converted to CSS using kebab-case transformation.

🧪 Testing

Run the test suite:

cargo test

Example tests include:

  • Expression evaluation
  • Style conversion
  • Class name normalization
  • Nested JSX rendering

📁 Workspace Integration

prejsx is part of a Cargo workspace:

prejsx-workspace/
├── prejsx/         # JSX-to-HTML transpiler
├── prejsx_math/    # Math expression parser

You can use prejsx_math independently if you need a lightweight math evaluator.


📜 License

Licensed under either of:

  • MIT License
  • Apache License 2.0

💬 Feedback & Contributions

Feel free to open issues or PRs. Whether you're using prejsx in a static site generator, a templating engine, or just for fun — we'd love to hear from you!

Commit count: 0

cargo fmt