class documentation

class HTMLBuilder:

View In Hierarchy

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>&lt;foo&gt;</p>'
Deprecated since version 2.0: Will be removed in Werkzeug 2.1.
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
def __call__(self, s):

Undocumented

def __getattr__(self, tag):

Undocumented

def __init__(self, dialect):

Undocumented

def __repr__(self):

Undocumented

Returns
strUndocumented
_boolean_attributes: set[str] =

Undocumented

_c_like_cdata: set[str] =

Undocumented

_empty_elements: set[str] =

Undocumented

_entities =

Undocumented

_entity_re =

Undocumented

_plaintext_elements: set[str] =

Undocumented

_dialect =

Undocumented