OpenQuizz
Une application de gestion des contenus pédagogiques
HTMLBuilder Class Reference
Inheritance diagram for HTMLBuilder:
Collaboration diagram for HTMLBuilder:

Public Member Functions

def __init__ (self, dialect)
 
def __call__ (self, s)
 
def __getattr__ (self, tag)
 
def __repr__ (self)
 

Detailed Description

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')])
u'<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>"))
u'<p>&lt;foo&gt;</p>'

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  dialect 
)

Member Function Documentation

◆ __call__()

def __call__ (   self,
  s 
)

◆ __getattr__()

def __getattr__ (   self,
  tag 
)

◆ __repr__()

def __repr__ (   self)

The documentation for this class was generated from the following file: