Python in, HTML out.
Project description
htmlclasses
Python in, HTML out.
There are templating engines making it possible to write code in HTML template files. However, I would very much prefer to be able to write Python that gets converted to HTML rather than write Python-like mini language engulfed in HTML.
Version
0.3.2
Goals
Generating valid HTML from pure Python code.
Non-goals
Features geared toward JavaScript.
- I find using 2 intertwined languages too cumbersome.
- JavaScript is heavily overused and misused. I don't want to add to the problem.
Installation
pip install htmlclasses
Developing
This project is managed with poetry: https://github.com/python-poetry/poetry
git clone git@github.com:uigctaw/htmlclasses.git
poetry install
Running tests
./check_all.sh
Examples
To convert Python to HTML run:
from htmlclasses import to_string
to_string(html, indent=' ')
Hello World
from htmlclasses import E
class html(E):
class head:
pass
class body:
class p:
TEXT = 'Hello, world!'
<!DOCTYPE html>
<html>
<head/>
<body>
<p>
Hello, world!
</p>
</body>
</html>
Repeated Elements
from htmlclasses import E
class html(E):
class head(E): # Must sublcass if repeating tags
class meta:
name = 'description'
content = 'Framework usage examples'
class meta: # type: ignore[no-redef] # noqa: F811
name = 'keywords'
content = 'Python, HTML'
class body:
class p:
TEXT = 'Hello, world!'
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Framework usage examples"/>
<meta name="keywords" content="Python, HTML"/>
</head>
<body>
<p>
Hello, world!
</p>
</body>
</html>
Work in progress
SVG utilities for creating plots.
Alternatives
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
Built Distribution
File details
Details for the file htmlclasses-0.3.2.tar.gz
.
File metadata
- Download URL: htmlclasses-0.3.2.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.8.10 Linux/5.11.0-34-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bd08f4ba4dcf6260c6d47eab38e1188937ece0ec4dab1e990155c0c209ccea4 |
|
MD5 | b9f774034ff54502f65338c95987f438 |
|
BLAKE2b-256 | d04a9b7e007f32b23dd4cbfeaa71c95fe20144e52aaec8665384bfeac5c957fb |
File details
Details for the file htmlclasses-0.3.2-py3-none-any.whl
.
File metadata
- Download URL: htmlclasses-0.3.2-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.8.10 Linux/5.11.0-34-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df0b95a5fa038a1ee49b7a8259b62c1c78ea689b7a15fba58f4534631c0cf197 |
|
MD5 | 40f20671748d5aa14bf4a588c851ed21 |
|
BLAKE2b-256 | ed504325f1638e1c4fa88200f36a89415bb4c5e9a1e274416df465fff7d2df5f |