A demo of generating HTML with just htm.py and the Python 3 standard library. This idea could, maybe, be combined with this gist.
h.py is the main "library" that implements html
for generating the DOM and render
for rendering it.
example.py uses h.py and illustrates some general patterns, such as:
- functional components (see
functional_component
) - generator components (see
generator_component
) - boolean props (see
editable
in the output) - components only getting the props they're asking for (via
relaxed_call
in h.py) - fragments and nested child lists (via
flatten
in h.py) - conditional rendering (
True
/False
/None
get ignored - seefooter_message
)
To run, first install htm.py with pip3 install htm
and then run the command python3 example.py
.
Note that this is just a PoC. For example tags and prop names are not validated properly to not contain spaces etc.