class HTMLBuilder:
Helper object for HTML generation.
Per default there are two instances of that class. The html
one, and
the xhtml
one for those two dialects. The class uses keyword parameters
and positional parameters to generate small snippets of HTML.
Keyword parameters are converted to XML/SGML attributes, positional arguments are used as children. Because Python accepts positional arguments before keyword arguments it's a good idea to use a list with the star-syntax for some children:
>>> html.p(class_='foo', *[html.a('foo', href='foo.html'), ' ', ... html.a('bar', href='bar.html')]) '<p class="foo"><a href="foo.html">foo</a> <a href="bar.html">bar</a></p>'
This class works around some browser limitations and can not be used for arbitrary SGML/XML generation. For that purpose lxml and similar libraries exist.
Calling the builder escapes the string passed:
>>> html.p(html("<foo>")) '<p><foo></p>'
Method | __call__ |
Undocumented |
Method | __getattr__ |
Undocumented |
Method | __init__ |
Undocumented |
Method | __repr__ |
Undocumented |
Class Variable | _boolean_attributes |
Undocumented |
Class Variable | _c_like_cdata |
Undocumented |
Class Variable | _empty_elements |
Undocumented |
Class Variable | _entities |
Undocumented |
Class Variable | _entity_re |
Undocumented |
Class Variable | _plaintext_elements |
Undocumented |
Instance Variable | _dialect |
Undocumented |