Skip to main content

Light html generator

Project description

Upload Python Package

Abstract

Light html generator

Install

pip3 install htmlight

or

poetry add git+https://github.com/GrafLearnt/HTMLight.git

or

pip3 install git+https://github.com/GrafLearnt/HTMLight.git

Disclaimer

Despite htmlight is able to generate full html page, it is designed to generate small fragments of code like:

from htmlight import h
from flask_babel import lazy_gettext
from flask_login import current_user


TEMPLATE = h.div(h.hr(), h.span("{hello} {username}"), h.hr())


def get_html():
    return TEMPLATE.format(hello=lazy_gettext("Hello"), username=current_user.name)

or

from htmlight import h
from flask_babel import lazy_gettext
from flask_login import current_user


def get_html():
    return h.div(h.hr(), h.span(lazy_gettext("Hello"), " ", current_user.name), h.hr()))

Usage

Code

from htmlight import h


landing_page = h.html(
    h.head(
        h.title("Welcome to Our Website"),
        h.link(attributes={"rel": "stylesheet", "href": "styles.css"}),
    ),
    h.body(
        h.header(
            h.h1(
                "Welcome to Our Website",
                attributes={
                    "style": (
                        " color:"
                        " #333;"
                        " text-align:"
                        " center;"
                        " background-color:"
                        " #F0F0F0;"
                        " padding: 20px;"
                    )
                },
            ),
            h.p(
                "Explore our amazing content", attributes={"style": "font-size: 20px; color: #555;"}
            ),
        ),
        h.main(
            h.h2("Featured Articles", attributes={"style": "color: #444; text-align: center;"}),
            h.article(
                h.h3("Article 1", attributes={"style": "color: #0072d6;"}),
                h.p("This is the first article content", attributes={"style": "color: #666;"}),
            ),
            h.article(
                h.h3("Article 2", attributes={"style": "color: #00a86b;"}),
                h.p("This is the second article content", attributes={"style": "color: #666;"}),
            ),
        ),
        h.footer(
            h.p(
                "© 2023 Our Website",
                attributes={
                    "style": (
                        "text-align: center;"
                        " background-color: #333;"
                        " color: #fff;"
                        " padding: 10px;"
                        " flex-shrink: 0;"
                        " background-color: #333;"
                        " position: absolute;"
                        " left: 0;"
                        " bottom: 0;"
                        " width: 100%;"
                        " overflow: hidden;"
                    )
                },
            ),
        ),
    ),
    attributes={
        "style": "background-color: #f2f2f2; font-family: Arial, sans-serif;",
    },
)

with open("landing_page.html", "w") as f:
    f.write(landing_page)

Result page

Result

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

htmlight-0.1.1.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

htmlight-0.1.1-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file htmlight-0.1.1.tar.gz.

File metadata

  • Download URL: htmlight-0.1.1.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for htmlight-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bef7b8d2ef93abefce5af640b70ae32e701290082f4a6a78d00426a778c93bd7
MD5 9ca3deb5318e5ebd39a0addd9af85eba
BLAKE2b-256 e2e0a99173681fb3f7984b8c59369e6fe915974d522c5bc442735006d7435e63

See more details on using hashes here.

File details

Details for the file htmlight-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: htmlight-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for htmlight-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0fb90fcb737bb6cc588bf362d8d36e170c6cbac72508ab965fb864d8f71b2667
MD5 f44928fb6917f3bf0546f34f2b03c0c5
BLAKE2b-256 9d7b84367e91d363c43bca74bb34b72304001dc22dd7bd98eb0d1cff58feecc3

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