Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vchan/hyperscript
HyperText with Python
https://github.com/vchan/hyperscript
Last synced: 4 months ago
JSON representation
HyperText with Python
- Host: GitHub
- URL: https://github.com/vchan/hyperscript
- Owner: vchan
- License: mit
- Created: 2022-09-19T17:35:21.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-22T23:55:35.000Z (about 1 year ago)
- Last Synced: 2024-04-24T15:24:00.872Z (10 months ago)
- Language: Python
- Size: 19.5 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-python-html - vchan/hyperscript
- awesome-python-html - vchan/hyperscript
README
# Hyperscript
Hyperscript is a lightweight library that allows you to write HTML with Python. It is heavily inspired by [HyperScript](https://github.com/hyperhype/hyperscript).## Example usage
```
>>> print(h("p", "Hello world!"))Hello world!
```
Class and id selectors
```
>>> print(h("p.class1#id", "Hello world!"))Hello world!
```
Style
```
>>> print(h("p", "Hello world!", {"style": {"color": "red"}}))Hello world!
```
Nesting elements
```
>>> print(h("div", h("p", "Hello world!")))Hello world!
```
Attributes
```
>>> print(h("a", {"href": "https://www.example.com"}, "link"))
link
```
Boolean attributes
```
>>> print(h("input", {"type": "checkbox", "checked": True})) # Behavior is the same if "checked" is None>>> print(h("input", {"type": "checkbox", "checked": ""}))
>>> print(h("input", {"type": "checkbox", "checked": False}))
```