Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/niklasf/python-tinyhtml
A tiny library to safely render compact HTML5 from Python expressions.
https://github.com/niklasf/python-tinyhtml
functional-programming html html5 python python3 vdom
Last synced: 3 months ago
JSON representation
A tiny library to safely render compact HTML5 from Python expressions.
- Host: GitHub
- URL: https://github.com/niklasf/python-tinyhtml
- Owner: niklasf
- License: apache-2.0
- Created: 2020-10-19T17:55:11.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-12-24T11:18:03.000Z (about 1 year ago)
- Last Synced: 2024-05-01T18:58:02.063Z (9 months ago)
- Topics: functional-programming, html, html5, python, python3, vdom
- Language: Python
- Homepage: https://pypi.org/project/tinyhtml/
- Size: 64.5 KB
- Stars: 14
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE-APACHE
Awesome Lists containing this project
- awesome-python-html - niklasf/python-tinyhtml
- awesome-python-html - niklasf/python-tinyhtml
README
tinyhtml
========A tiny library to safely render compact HTML5 from Python expressions.
.. image:: https://github.com/niklasf/python-tinyhtml/workflows/Test/badge.svg
:target: https://github.com/niklasf/python-tinyhtml/actions
:alt: Test status.. image:: https://badge.fury.io/py/tinyhtml.svg
:target: https://pypi.python.org/pypi/tinyhtml
:alt: PyPI packageIntroduction
------------This is the entire API. The following documentation is longer than the
implementation... code:: python
>>> from tinyhtml import html, h, frag, raw
The most important function is ``h()``. Below you see how to render attributes,
normal elements, and void/self-closing elements... code:: python
>>> html(lang="en")(
... h("head")(
... h("meta", charset="utf-8"),
... ),
... ).render()
''Use ``frag()`` to pass around groups of elements.
.. code:: python
>>> frag(
... h("h1")("Lorem ipsum ..."),
... h("p")("... dolor sit amet."),
... )
raw('Lorem ipsum ...
... dolor sit amet.
')Of course all content and attributes are properly escaped. Use ``raw()`` as an
escape hatch to render unescaped HTML... code:: python
>>> print(h("a", title="&<>\"'")("&<>\"'").render())
&<>"'>>> print(raw("