""" # BEGIN TAG_DEMO >>> tag('br') # <1> '
' >>> tag('p', 'hello') # <2> '

hello

' >>> print(tag('p', 'hello', 'world'))

hello

world

>>> tag('p', 'hello', id=33) # <3> '

hello

' >>> print(tag('p', 'hello', 'world', cls='sidebar')) # <4> >>> tag(content='testing', name="img") # <5> '' >>> my_tag = {'name': 'img', 'title': 'Sunset Boulevard', ... 'src': 'sunset.jpg', 'cls': 'framed'} >>> tag(**my_tag) # <6> '' # END TAG_DEMO """ # BEGIN TAG_FUNC def tag(name, *content, cls=None, **attrs): """Generate one or more HTML tags""" if cls is not None: attrs['class'] = cls if attrs: attr_str = ''.join(' %s="%s"' % (attr, value) for attr, value in sorted(attrs.items())) else: attr_str = '' if content: return '\n'.join('<%s%s>%s' % (name, attr_str, c, name) for c in content) else: return '<%s%s />' % (name, attr_str) # END TAG_FUNC