common/uilib.py
changeset 2399 68799e25f893
parent 2375 628000fcf7dc
child 2458 4d114865098f
equal deleted inserted replaced
2391:59a2def75e93 2399:68799e25f893
   207 
   207 
   208 
   208 
   209 
   209 
   210 # HTML generation helper functions ############################################
   210 # HTML generation helper functions ############################################
   211 
   211 
       
   212 HTML4_EMPTY_TAGS = frozenset(('base', 'meta', 'link', 'hr', 'br', 'param',
       
   213                               'img', 'area', 'input', 'col'))
       
   214 
   212 def simple_sgml_tag(tag, content=None, escapecontent=True, **attrs):
   215 def simple_sgml_tag(tag, content=None, escapecontent=True, **attrs):
   213     """generation of a simple sgml tag (eg without children tags) easier
   216     """generation of a simple sgml tag (eg without children tags) easier
   214 
   217 
   215     content and attributes will be escaped
   218     content and attri butes will be escaped
   216     """
   219     """
   217     value = u'<%s' % tag
   220     value = u'<%s' % tag
   218     if attrs:
   221     if attrs:
   219         try:
   222         try:
   220             attrs['class'] = attrs.pop('klass')
   223             attrs['class'] = attrs.pop('klass')
   226     if content:
   229     if content:
   227         if escapecontent:
   230         if escapecontent:
   228             content = xml_escape(unicode(content))
   231             content = xml_escape(unicode(content))
   229         value += u'>%s</%s>' % (content, tag)
   232         value += u'>%s</%s>' % (content, tag)
   230     else:
   233     else:
   231         value += u'></%s>' % tag
   234         if tag in HTML4_EMPTY_TAGS:
       
   235             value += u' />'
       
   236         else:
       
   237             value += u'></%s>' % tag
   232     return value
   238     return value
   233 
   239 
   234 def tooltipize(text, tooltip, url=None):
   240 def tooltipize(text, tooltip, url=None):
   235     """make an HTML tooltip"""
   241     """make an HTML tooltip"""
   236     url = url or '#'
   242     url = url or '#'