Skip to main content

Light html generator

Project description

Upload Python Package PyPI version Python Versions HTMLight

Abstract

Light html generator

Install

pip3 install htmlight

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(rel="stylesheet", href="styles.css"),
    ),
    h.body(
        h.header(
            h.h1(
                "Welcome to Our Website",
                style=(
                    " color:"
                    " #333;"
                    " text-align:"
                    " center;"
                    " background-color:"
                    " #F0F0F0;"
                    " padding: 20px;"
                ),
            ),
            h.p(
                "Explore our amazing content",
                style="font-size: 20px; color: #555;",
            ),
        ),
        h.main(
            h.h2("Featured Articles", style="color: #444; text-align: center;"),
            h.article(
                h.h3("Article 1", style="color: #0072d6;"),
                h.p("This is the first article content", style="color: #666;"),
            ),
            h.article(
                h.h3("Article 2", style="color: #00a86b;"),
                h.p("This is the second article content", style="color: #666;"),
            ),
        ),
        h.footer(
            h.p(
                "© 2023 Our Website",
                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;"
                ),
            ),
        ),
    ),
    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.2.0.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: htmlight-0.2.0.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for htmlight-0.2.0.tar.gz
Algorithm Hash digest
SHA256 51e1c5f862c4ecb3a57247ad2df2d6015be652f2c2ec612821c5afa385aa6a6b
MD5 148d4a6a5376abf6aad6d1d63da90f73
BLAKE2b-256 1afa200198be8445fbe54c5687fa8815252366b905d8a97e55b454067dbfbfc7

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for htmlight-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f6b32c277beda0a39104533a1ff3c78800fae5f9b11a3ad2563dc88905e528a
MD5 4903f031baca8ff136e794c5c25e8058
BLAKE2b-256 9e7eab92f39eda84fb3357278e14cb72c1f4f5fbb50f6a09fa9cf1cb30cfa16f

See more details on using hashes here.

Supported by

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