{ "info": { "author": "Sebastian Rittau", "author_email": "srittau@rittau.biz", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Internet :: WWW/HTTP :: WSGI", "Topic :: Text Processing :: Markup :: HTML" ], "description": "Python HTML 5 Generator\n=======================\n\n.. image:: https://img.shields.io/pypi/l/htmlgen.svg\n :target: https://pypi.python.org/pypi/htmlgen/\n.. image:: https://img.shields.io/github/release/srittau/python-htmlgen/all.svg\n :target: https://github.com/srittau/python-htmlgen/releases/\n.. image:: https://img.shields.io/pypi/v/htmlgen.svg\n :target: https://pypi.python.org/pypi/htmlgen/\n.. image:: https://travis-ci.org/srittau/python-htmlgen.svg?branch=master\n :target: https://travis-ci.org/srittau/python-htmlgen\n\nLibrary to generate HTML from classes.\n\nBasic usage:\n\n>>> from htmlgen import Division, Span\n>>> Division(\"This is \", Span(\"important!\"), \"!\")\n\nA more verbose example:\n\n>>> span = Span(\"important\")\n>>> span.add_css_classes(\"important\")\n>>> div = Division()\n>>> div.id = \"my-block\"\n>>> div.append(\"This is \")\n>>> div.append(span)\n>>> div.append(\"!\")\n\nA tree constructed like this can be converted to a string:\n\n>>> str(div)\n'
This is {}!
\".format(span)\n'This is important!
'\n\nAlternatively, all elements can be used as iterators, for example to return\nthem from a WSGI callback:\n\n>>> def application(env, start_response):\n... start_response(\"200 OK\", [(\"Content-Type\", \"text/html\")])\n... return div\n\nThere are two different ways to render children of HTML elements. The tree\nconstruction approach shown above is mainly suitable for elements with few\nchildren. The disadvantage of this approach is that the whole tree must be\nconstructed in memory. An alternative way, best suited for custom sub-classes\nof elements, is to override the generate_children method of the Element class:\n\n>>> class MyBlock(Division):\n... def __init__(self):\n... super(MyBlock, self).__init__()\n... self.id = \"my-block\"\n... def generate_children(self):\n... yield \"This is \"\n... span = Span(\"important\")\n... span.add_css_classes(\"important\")\n... yield span\n... yield \"!\"\n>>> str(MyBlock())\n'