This project provides a class-based system for rendering HTML programmatically using Python.
It supports element nesting, attributes, self-closing tags, and inline vs. block-level elements.
- HTML tag rendering with indentation
- Element content and attribute handling
- Support for self-closing tags (e.g.,
br,hr,meta) - Specialized subclasses for common HTML tags (
Html,Body,P,Title, etc.) - Link and header tag rendering
- Readable, testable architecture with class-based design
To render an HTML structure, create instances of HTML elements and nest them using .append().
Example:
from html_render import Html, Body, P
page = Html()
body = Body()
body.append(P("Hello, world!"))
page.append(body)
with open("output.html", "w") as f:
page.render(f)Run the included tests with:
pytest test_html_render.pyThis project is licensed under the MIT License.