This project provides a Python-based tool for parsing precompiled shadcn HTML into ShadCN components using Beautiful Soup. It simplifies the process of transforming raw HTML into reusable and styled components.
- Clone the repository.
- Install the required dependencies:
pip install -r requirements.txt
Here’s how you can use the converter:
from registry import COMPONENTS
from converter import JSXConverter
# Initialize the converter with the component registry
converter = JSXConverter(COMPONENTS)
# Input your HTML
html_input = '<button class="inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 hover:bg-accent hover:text-accent-foreground h-10 px-4 py-2 custom-class">Login</button>'
# Convert the HTML to ShadCN components
jsx_output = converter.convert(html_input)
print(jsx_output)
# Output:
# <Button variant="ghost" size="default" className="custom-class">Login</Button>
.
├── components.py # Defines the Component interface
├── converter.py # Contains the main conversion and parsing logic
├── registry.py # Defines the COMPONENTS registry
this project uses tailwind-merge
This project is licensed under the MIT License.