Skip to main content

A library for building HTML documents with a simple and easily learnable syntax

Project description

PyHTML Enhanced

A library for building HTML documents with a simple and easily learnable syntax, inspired by, and similar to the original PyHTML library, but with improved documentation and type safety.

Benefits over PyHTML

  • Inline documentation and type safety for all tags. Documentation for tags is pulled from MDN Web Docs.

  • A modern and readable codebase.

  • No dependencies.

Usage

import pyhtml as h

my_website = h.html(
    h.head(
        h.title("Hello, world!"),
        h.script(src="http://example.com/script.js"),
    ),
    h.body(
        h.h1("Hello, world!"),
        h.p("This is my amazing website rendered with PyHTML Enhanced!"),
    ),
)

# Converting it to a string is all you need to do to render it!
print(str(my_website))

This will produce the following HTML code:

<html>
  <head>
    <script src="http://example.com/script.js"></script>
    <title>
      Hello, world!
    </title>
  </head>
  <body>
    <h1>
      Hello, world!
    </h1>
    <p>
      This is my amazing website rendered with PyHTML Enhanced!
    </p>
  </body>
</html>

TODOs

There are a couple of things I haven't done yet

  • Make tags by themselves render, so str(br) renders to <br/>
  • Add default properties to tags
  • Make inline documentation include documentation of suggested properties
  • Update links within documentation to make them point to the right locations.

How it works

Since there are so many HTML tags, it would be extremely tedious to document them all manually. In the meta directory, you will find code that solves this problem with the following steps:

  1. Download the Markdown source for MDN's documentation of all HTML elements.

  2. Parse the markdown to gather all tag names and descriptions, discarding garbage data and obsolete tags.

  3. Use data from a YAML configuration file (meta/tags.yml) to gather information on suggested properties and base classes to use for each tag.

  4. Generate Python code to represent all of these tags.

Credits

Cenkalti/PyHTML

Cenk Altı's work was used as a source of inspiration and reference. Although all the code in pyhtml-enhanced was written by me, I want to thank them for the significant help their hard work provided while creating this project.

MDN Web Docs

Almost all of the documentation was gathered from the MDN Web Docs. It's super neat that all their documentation is open (licensed as CC-BY-SA-2.5 if you're interested).

License

All code in this project is licensed under the MIT License.

However, the documentation found in pyhtml/__tags/generated.py was copied from MDN Web Docs, and is licensed under CC-BY-SA-2.5. See LICENSE_DOCS.md for a copy of the license.

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

pyhtml_enhanced-0.1.0.tar.gz (25.5 kB view details)

Uploaded Source

Built Distribution

pyhtml_enhanced-0.1.0-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

Details for the file pyhtml_enhanced-0.1.0.tar.gz.

File metadata

  • Download URL: pyhtml_enhanced-0.1.0.tar.gz
  • Upload date:
  • Size: 25.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.5 Linux/5.15.0-1041-azure

File hashes

Hashes for pyhtml_enhanced-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f7d2d5e4b5dbd9a1eb9cdde52402a230783d9474598bbefcb6fa6de0a2539b33
MD5 bdde83445fd4fb2877d6e552529583e0
BLAKE2b-256 09ad3bd03fa277bbeac43ab928b24a04316c2c83bf3bef83209c7bfacef2c099

See more details on using hashes here.

File details

Details for the file pyhtml_enhanced-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyhtml_enhanced-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.5 Linux/5.15.0-1041-azure

File hashes

Hashes for pyhtml_enhanced-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5e7ed37cd754a95114712f60e9289bd12de68bc57dba28705a4a655644a14c5f
MD5 1483b01eb252f8dcc46e59b8f5bd5d0e
BLAKE2b-256 62d1f7df67be18145acda24678de58ee79255733d922b800fdc22a3ab64bee0e

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