This project provides a serverless function that converts HTML to React JSX. It's designed to run on Vercel's serverless platform and can be easily deployed and integrated into your workflow.
- Converts basic HTML to JSX syntax
- Handles self-closing tags (e.g.,
<img>,<br>) - Converts
classattributes toclassName - Converts
forattributes tohtmlFor - Transforms inline styles to React style objects
- Wraps the converted HTML in a functional React component
-
Clone this repository:
git clone https://github.com/teebarg/html-converter cd html-converter -
Install the Vercel CLI if you haven't already:
npm install -g vercel -
Deploy to Vercel:
vercel
api/hello.py: The main Python function that handles the HTML to JSX conversionvercel.json: Configuration file for Vercel deploymentREADME.md: This file
npm i -g vercel
vercel devYour Python API is now available at http://localhost:3000/api.
To use the converter, send a POST request to your deployed Vercel function URL with the HTML content in the request body. The function will return a JavaScript file containing a React component.
Example using curl:
curl -X POST -H "Content-Type: text/plain" -d '<div class="hello" style="color: red;">Hello, World!<img src="example.jpg" alt="Example"></div>' https://your-vercel-url.vercel.app/api/convertThis is a basic converter and may not handle all complex HTML structures or React-specific features. It's designed for simple conversions and may need to be extended for more complex use cases.
Contributions are welcome! Please feel free to submit a Pull Request.