Skip to main content

An intuitive, high performance HTML rendering framework

Project description

htmldoom

An intuitive, high performance HTML rendering framework

PyPI version PyPI version Build Status codecov Code style: black

Usage

A basic tag

>>> from htmldoom import render, elements as e
>>> 
>>> print(render(e.p(style="color='red'")("This is a paragraph")))
<p style="color:'red';">This is a paragraph</p>

A functional style foreach loop with a switch case

>>> from htmldoom import elements as e
>>> from htmldoom import functions as fn
>>> 
>>> tuple(fn.foreach(["good", "bad", "evil"])(
...     lambda x: fn.switch({
...         x == "good": lambda: e.span(style="color: green")(f"this is {x}"),
...         x == "bad": lambda: e.span(style="color: yellow")(f"this is {x}"),
...         x == "evil": lambda: e.span(style="color: red")(f"this is {x}"),
...         fn.Case.DEFAULT: lambda: fn.Error.throw(ValueError(x)),
...     })
... ))
(b'<span style="color: green">this is good</span>',
 b'<span style="color: yellow">this is bad</span>',
 b'<span style="color: red">this is evil</span>')

A fast dynamic elements rendering mechanism

Choose whichever syntax suits you:

Syntax 1

>>> @renders(
...     e.p()("{x}"),
...     e.p()("another {x}"),
... )
... def render_paras(data: dict) -> dict:
...     return {"x": data["x"]}
>>> 
>>> render_paras({"x": "awesome paragraph"})
<p>awesome paragraph</p><p>another awesome paragraph</p>

Syntax 2

>>> render_paras = renders(
...     e.p()("{x}"),
...     e.p()("another {x}"),
... )(lambda data: {"x": data["x"]})
>>> 
>>> render_paras({"x": "awesome paragraph"})
<p>awesome paragraph</p><p>another awesome paragraph</p>

Find more examples here

Q/A

What is the goal here?

The primary goal is to make writing HTML pages cleaner, easier, safer and intuitive using Python.

What about performance?

Although performance is not the primary goal here, it should not be a roadblock. htmldoom is copying the syntax and some of the rendering properties of elm, an existing fast and purely functional programming language that specializes in rendering HTML in virtual doms. Elm does all the optimisation internally, which I believe can be implemented in Python to a great extent.
Furthermore, if we follow the the DOM size recommendations, i.e.

  • less than 1500 nodes total.
  • maximum depth of 32 nodes.
  • no parent node with more than 60 child nodes.
htmldoom should perform really well.

Plugins and ecosystem

  • moodlmth: Convert raw HTML pages into python source code

Contributing

Check out the contributing guidelines.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

htmldoom-0.6.1.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

htmldoom-0.6.1-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file htmldoom-0.6.1.tar.gz.

File metadata

  • Download URL: htmldoom-0.6.1.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.5

File hashes

Hashes for htmldoom-0.6.1.tar.gz
Algorithm Hash digest
SHA256 a6d22f58e805b31e186a7811c3c20b8a2aed9878fda33ef566721f09b7d9b893
MD5 3293f49880340afc929daa53d65c4d62
BLAKE2b-256 80049070dc2f811a3cea914058bed5fafcabd28f120ee0a6e16eb709abf2d250

See more details on using hashes here.

File details

Details for the file htmldoom-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: htmldoom-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.5

File hashes

Hashes for htmldoom-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b8b6026edc048fec4b7c28068590c45d2f17e47bfc07cfb199ca921a10580b7a
MD5 45f640a5266796d54e1c8527cb848a50
BLAKE2b-256 fecabd1aa1619d935d1cd97620efd471c544786e75671bbe73a0e54ec0abef6a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page