Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/keller-mark/with-html

(Ab)use python context managers to construct HTML
https://github.com/keller-mark/with-html

Last synced: 12 days ago
JSON representation

(Ab)use python context managers to construct HTML

Awesome Lists containing this project

README

        

# with-html

(Ab)use python context managers to construct HTML. Render the resulting tree using [anywidget](https://anywidget.dev).

:warning: This is an experiment

## Usage

```python
from with_html import create_root, RootWidget

h = create_root()

def my_button(h):
h.button("submit")

with h.div():
h.h1("Test")
h.img(src="https://example.com/my_image.jpg", width=200, height=200)
h.p("my paragraph")
h(my_button)
h.p("another paragraph")
with h.table(style=dict(border="1px solid red")):
with h.tr():
h.th("Column 1")
h.th("Column 2")
with h.tr():
h.td("Value 1")
h.td("Value 2")

w = RootWidget(h.root)
w
```

## Development

```sh
conda create -n with-html python=3.12
conda activate with-html
pip install -e ".[dev]"
```

```sh
jupyter lab
```